Interface Channel

All Known Implementing Classes:
ChannelImp

public interface Channel
The channel module interface.
  • Method Details

    • build

      static Channel build​(ConfigOption configOption) throws ConfigException
      Init channel module
      Parameters:
      configOption - config file path.
      Returns:
      a channel instance
      Throws:
      ConfigException - the configuration exception
    • getNetwork

      Network getNetwork()
    • start

      void start()
    • stop

      void stop()
    • addMessageHandler

      void addMessageHandler​(MsgType type, MsgHandler handler)
      Add a message handler to handle specific type messages. When one message comes the handler will be notified, handler.onMessage(ChannleHandlerContext ctx, Message msg) called.
      Parameters:
      type - the type of message
      handler - the message handler
    • addConnectHandler

      void addConnectHandler​(MsgHandler handler)
      Add a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is called
      Parameters:
      handler - the connect handler
    • addEstablishHandler

      void addEstablishHandler​(MsgHandler handler)
      Add a establish handler, when the SDK establishes a connection with the node, call the handler
      Parameters:
      handler - the establish handler
    • addDisconnectHandler

      void addDisconnectHandler​(MsgHandler handler)
      Add a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is called
      Parameters:
      handler - disconnect handler
    • broadcastToGroup

      void broadcastToGroup​(Message out, java.lang.String groupId)
      Send a message to the given group, only send
      Parameters:
      out - Message to be sent
      groupId - ID of the group receiving the message packet
    • broadcast

      void broadcast​(Message out)
      Broadcast to all peer, only send
      Parameters:
      out - Message to be sent
    • sendToPeer

      Response sendToPeer​(Message out, java.lang.String peerIpPort)
      Synchronize interface, send a message to the given peer, and get the response
      Parameters:
      out - Message to be sent
      peerIpPort - Remote ip:port information
      Returns:
      Remote reply
    • sendToPeerWithTimeOut

      Response sendToPeerWithTimeOut​(Message out, java.lang.String peerIpPort, Options options)
      Synchronize interface with timeout, send a message to the given peer, and get the response
      Parameters:
      out - Message to be sent
      peerIpPort - Remote ip:port information
      options - Include timeout
      Returns:
      Remote reply
    • sendToRandomWithTimeOut

      Response sendToRandomWithTimeOut​(Message out, Options options)
      Synchronize interface with timeout, randomly select nodes to send messages
      Parameters:
      out - Message to be sent
      options - Include timeout
      Returns:
      Remote reply
    • sendToPeerByRuleWithTimeOut

      Response sendToPeerByRuleWithTimeOut​(Message out, PeerSelectRule rule, Options options)
      Synchronize interface with timeout, send message to peer select by client`s rule
      Parameters:
      out - Message to be sent
      rule - Rule set by client
      options - Include timeout
      Returns:
      Remote reply
    • asyncSendToPeer

      void asyncSendToPeer​(Message out, java.lang.String peerIpPort, ResponseCallback callback, Options options)
      Asynchronous interface, send message to peer
      Parameters:
      out - Message to be sent
      peerIpPort - Remote ip:port information
      callback - Response callback
      options - Include timeout
    • asyncSendToRandom

      void asyncSendToRandom​(Message out, ResponseCallback callback, Options options)
      Asynchronous interface, send to an random peer
      Parameters:
      out - Message to be sent
      callback - Response callback
      options - Include timeout
    • asyncSendToPeerByRule

      void asyncSendToPeerByRule​(Message out, PeerSelectRule rule, ResponseCallback callback, Options options)
      Asynchronous interface, send message to peer select by client`s rule
      Parameters:
      out - Message to be sent
      rule - Rule set by client
      callback - Response callback
      options - Include timeout
    • getConnectionInfo

      java.util.List<ConnectionInfo> getConnectionInfo()
      Get connection information
      Returns:
      List of connection information
    • getAvailablePeer

      java.util.List<java.lang.String> getAvailablePeer()
      Get available peer information
      Returns:
      List of available peer
    • setThreadPool

      void setThreadPool​(java.util.concurrent.ExecutorService threadPool)