org.redkale.net.sncp

## 类 Sncp

- java.lang.Object
- - org.redkale.net.sncp.Sncp

-     public abstract class Sncp
      extends java.lang.Object

  Service Node Communicate Protocol 生成Service的本地模式或远程模式Service-Class的工具类

  详情见: http://www.redkale.org

- - ### 方法概要

    所有方法 静态方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `static <T extends Service> T` | `createLocalService(java.lang.String name, java.util.function.Consumer<java.lang.Runnable> executor, java.lang.Class<T> serviceClass, java.net.InetSocketAddress clientAddress, Transport sameGroupTransport, java.util.Collection<Transport> diffGroupTransports)` 创建本地模式Service实例
    `protected static <T extends Service> java.lang.Class<? extends T>` | `createLocalServiceClass(java.lang.String name, java.lang.Class<T> serviceClass)` public class TestService implements Service{ public String findSomeThing(){ return "hello"; } @MultiRun(selfrun = false) public void createSomeThing(TestBean bean){ //do something } @MultiRun public String updateSomeThing(String id){ return "hello" + id; } } @Resource(name = "") @SncpDyn(remote = false) @ResourceType({TestService.class}) public final class _DynLocalTestService extends TestService{ @Resource private BsonConvert _convert; private Transport _sameGroupTransport; private Transport[] _diffGroupTransports; private SncpClient _client; private String _selfstring; @Override public String toString() { return _selfstring == null ?
    `static <T extends Service> T` | `createRemoteService(java.lang.String name, java.util.function.Consumer<java.lang.Runnable> executor, java.lang.Class<T> serviceClass, java.net.InetSocketAddress clientAddress, Transport transport)` @Resource(name = "") @SncpDyn(remote = true) @ResourceType({TestService.class}) public final class _DynRemoteTestService extends TestService{ @Resource private BsonConvert _convert; private Transport _transport; private SncpClient _client; private String _selfstring; @Override public String toString() { return _selfstring == null ?
    `static DLong` | `hash(java.lang.Class clazz)`
    `static DLong` | `hash(java.lang.reflect.Method method)`
    `static DLong` | `hash(java.lang.String name)` 对类名或者name字符串进行hash。
    `static DLong` | `hashClass(java.lang.String clazzName)`
    `static boolean` | `isRemote(Service service)`
    `static long` | `nodeid(java.net.InetSocketAddress ip)`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 方法详细资料

    - #### nodeid

          public static long nodeid(java.net.InetSocketAddress ip)

    - #### hash

          public static DLong hash(java.lang.Class clazz)

    - #### hashClass

          public static DLong hashClass(java.lang.String clazzName)

    - #### hash

          public static DLong hash(java.lang.reflect.Method method)

    - #### hash

          public static DLong hash(java.lang.String name)

      对类名或者name字符串进行hash。
      参数:
        `name` - String
      返回:
        hash值

    - #### isRemote

          public static boolean isRemote(Service service)

    - #### createLocalServiceClass

          protected static <T extends Service> java.lang.Class<? extends T> createLocalServiceClass(java.lang.String name,
                                                                                                    java.lang.Class<T> serviceClass)

      >      public class TestService implements Service{

      >           public String findSomeThing(){
      >               return "hello";
      >           }

      >           @MultiRun(selfrun = false)
      >           public void createSomeThing(TestBean bean){
      >               //do something
      >           }

      >           @MultiRun
      >           public String updateSomeThing(String id){
      >               return "hello" + id;
      >           }
      >      }

      >      @Resource(name = "")
      >      @SncpDyn(remote = false)
      >      @ResourceType({TestService.class})
      >      public final class _DynLocalTestService extends TestService{

      >           @Resource
      >           private BsonConvert _convert;

      >           private Transport _sameGroupTransport;

      >           private Transport[] _diffGroupTransports;

      >           private SncpClient _client;

      >           private String _selfstring;

      >           @Override
      >           public String toString() {
      >               return _selfstring == null ? super.toString() : _selfstring;
      >           }

      >           @Override
      >           public void createSomeThing(TestBean bean){
      >               this._createSomeThing(false, true, true, bean);
      >           }

      >           @SncpDyn(remote = false, index = 0)
      >           public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
      >               if(selfrunnable) super.createSomeThing(bean);
      >               if (_client== null) return;
      >               if (samerunnable) _client.remoteSameGroup(_convert, _sameGroupTransport, 0, true, false, false, bean);
      >               if (diffrunnable) _client.remoteDiffGroup(_convert, _diffGroupTransports, 0, true, true, false, bean);
      >           }

      >           @Override
      >           public String updateSomeThing(String id){
      >               return this._updateSomeThing(true, true, true, id);
      >           }

      >           @SncpDyn(remote = false, index = 1)
      >           public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
      >               String rs = super.updateSomeThing(id);
      >               if (_client== null) return;
      >               if (samerunnable) _client.remoteSameGroup(_convert, _sameGroupTransport, 1, true, false, false, id);
      >               if (diffrunnable) _client.remoteDiffGroup(_convert, _diffGroupTransports, 1, true, true, false, id);
      >               return rs;
      >           }
      >      }

      创建Service的本地模式Class
      类型参数:
        `T` - Service子类
      参数:
        `name` - 资源名
        `serviceClass` - Service类
      返回:
        Service实例

    - #### createLocalService

          public static <T extends Service> T createLocalService(java.lang.String name,
                                                                 java.util.function.Consumer<java.lang.Runnable> executor,
                                                                 java.lang.Class<T> serviceClass,
                                                                 java.net.InetSocketAddress clientAddress,
                                                                 Transport sameGroupTransport,
                                                                 java.util.Collection<Transport> diffGroupTransports)

      创建本地模式Service实例
      类型参数:
        `T` - Service泛型
      参数:
        `name` - 资源名
        `executor` - 线程池
        `serviceClass` - Service类
        `clientAddress` - 本地IP地址
        `sameGroupTransport` - 同组的通信组件
        `diffGroupTransports` - 异组的通信组件列表
      返回:
        Service的本地模式实例

    - #### createRemoteService

          public static <T extends Service> T createRemoteService(java.lang.String name,
                                                                  java.util.function.Consumer<java.lang.Runnable> executor,
                                                                  java.lang.Class<T> serviceClass,
                                                                  java.net.InetSocketAddress clientAddress,
                                                                  Transport transport)

      >      @Resource(name = "")
      >      @SncpDyn(remote = true)
      >      @ResourceType({TestService.class})
      >      public final class _DynRemoteTestService extends TestService{

      >           @Resource
      >           private BsonConvert _convert;

      >           private Transport _transport;

      >           private SncpClient _client;

      >           private String _selfstring;

      >           @Override
      >           public String toString() {
      >               return _selfstring == null ? super.toString() : _selfstring;
      >           }

      >           @SncpDyn(remote = false, index = 0)
      >           public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
      >               _client.remote(_convert, _transport, 0, selfrunnable, samerunnable, diffrunnable, bean);
      >           }

      >           @SncpDyn(remote = false, index = 1)
      >           public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
      >               return _client.remote(_convert, _transport, 1, selfrunnable, samerunnable, diffrunnable, id);
      >           }

      >           @Override
      >           public void createSomeThing(TestBean bean){
      >               _client.remote(_convert, _transport, 2, bean);
      >           }

      >           @Override
      >           public String findSomeThing(){
      >               return _client.remote(_convert, _transport, 3);
      >           }

      >           @Override
      >           public String updateSomeThing(String id){
      >               return  _client.remote(_convert, _transport, 4, id);
      >           }
      >      }

      创建远程模式的Service实例
      类型参数:
        `T` - Service泛型
      参数:
        `name` - 资源名
        `executor` - 线程池
        `serviceClass` - Service类
        `clientAddress` - 本地IP地址
        `transport` - 通信组件
      返回:
        Service的远程模式实例