Package org.fisco.bcos.sdk.channel
Class ChannelImp
java.lang.Object
org.fisco.bcos.sdk.channel.ChannelImp
- All Implemented Interfaces:
Channel
public class ChannelImp extends java.lang.Object implements Channel
An implementation of channel.
-
Constructor Summary
Constructors Constructor Description ChannelImp(ConfigOption configOption) -
Method Summary
Modifier and Type Method Description voidaddConnectHandler(MsgHandler handler)Add a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is calledvoidaddDisconnectHandler(MsgHandler handler)Add a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is calledvoidaddEstablishHandler(MsgHandler handler)Add a establish handler, when the SDK establishes a connection with the node, call the handlervoidaddMessageHandler(MsgType type, MsgHandler handler)Add a message handler to handle specific type messages.voidasyncSendToPeer(Message out, java.lang.String peerIpPort, ResponseCallback callback, Options options)Asynchronous interface, send message to peervoidasyncSendToPeerByRule(Message out, PeerSelectRule rule, ResponseCallback callback, Options options)Asynchronous interface, send message to peer select by client`s rulevoidasyncSendToRandom(Message out, ResponseCallback callback, Options options)Asynchronous interface, send to an random peervoidbroadcast(Message out)Broadcast to all peer, only sendvoidbroadcastToGroup(Message out, java.lang.String groupId)Send a message to the given group, only sendjava.util.List<java.lang.String>getAvailablePeer()Get available peer informationjava.util.List<ConnectionInfo>getConnectionInfo()Get connection informationNetworkgetNetwork()voidsendHeartbeatMessage(io.netty.channel.ChannelHandlerContext ctx)ResponsesendToPeer(Message out, java.lang.String peerIpPort)Synchronize interface, send a message to the given peer, and get the responseResponsesendToPeerByRuleWithTimeOut(Message out, PeerSelectRule rule, Options options)Synchronize interface with timeout, send message to peer select by client`s ruleResponsesendToPeerWithTimeOut(Message out, java.lang.String peerIpPort, Options options)Synchronize interface with timeout, send a message to the given peer, and get the responseResponsesendToRandomWithTimeOut(Message out, Options options)Synchronize interface with timeout, randomly select nodes to send messagesvoidsetGroupId2PeerIpPortList(java.util.Map<java.lang.String,java.util.List<java.lang.String>> groupId2PeerIpPortList)voidsetThreadPool(java.util.concurrent.ExecutorService threadPool)voidstart()voidstop()voidwaitResponse(org.fisco.bcos.sdk.channel.ChannelImp.Callback callback, Options options)
-
Constructor Details
-
ChannelImp
- Throws:
ConfigException
-
-
Method Details
-
getNetwork
- Specified by:
getNetworkin interfaceChannel
-
start
public void start() -
stop
public void stop() -
addConnectHandler
Description copied from interface:ChannelAdd a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is called- Specified by:
addConnectHandlerin interfaceChannel- Parameters:
handler- the connect handler
-
addEstablishHandler
Description copied from interface:ChannelAdd a establish handler, when the SDK establishes a connection with the node, call the handler- Specified by:
addEstablishHandlerin interfaceChannel- Parameters:
handler- the establish handler
-
addMessageHandler
Description copied from interface:ChannelAdd a message handler to handle specific type messages. When one message comes the handler will be notified, handler.onMessage(ChannleHandlerContext ctx, Message msg) called.- Specified by:
addMessageHandlerin interfaceChannel- Parameters:
type- the type of messagehandler- the message handler
-
addDisconnectHandler
Description copied from interface:ChannelAdd a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is called- Specified by:
addDisconnectHandlerin interfaceChannel- Parameters:
handler- disconnect handler
-
setGroupId2PeerIpPortList
public void setGroupId2PeerIpPortList(java.util.Map<java.lang.String,java.util.List<java.lang.String>> groupId2PeerIpPortList) -
broadcastToGroup
Description copied from interface:ChannelSend a message to the given group, only send- Specified by:
broadcastToGroupin interfaceChannel- Parameters:
out- Message to be sentgroupId- ID of the group receiving the message packet
-
broadcast
Description copied from interface:ChannelBroadcast to all peer, only send -
sendToPeer
Description copied from interface:ChannelSynchronize interface, send a message to the given peer, and get the response- Specified by:
sendToPeerin interfaceChannel- Parameters:
out- Message to be sentpeerIpPort- Remote ip:port information- Returns:
- Remote reply
-
waitResponse
-
sendToPeerWithTimeOut
Description copied from interface:ChannelSynchronize interface with timeout, send a message to the given peer, and get the response- Specified by:
sendToPeerWithTimeOutin interfaceChannel- Parameters:
out- Message to be sentpeerIpPort- Remote ip:port informationoptions- Include timeout- Returns:
- Remote reply
-
sendToRandomWithTimeOut
Description copied from interface:ChannelSynchronize interface with timeout, randomly select nodes to send messages- Specified by:
sendToRandomWithTimeOutin interfaceChannel- Parameters:
out- Message to be sentoptions- Include timeout- Returns:
- Remote reply
-
sendToPeerByRuleWithTimeOut
Description copied from interface:ChannelSynchronize interface with timeout, send message to peer select by client`s rule- Specified by:
sendToPeerByRuleWithTimeOutin interfaceChannel- Parameters:
out- Message to be sentrule- Rule set by clientoptions- Include timeout- Returns:
- Remote reply
-
asyncSendToPeer
public void asyncSendToPeer(Message out, java.lang.String peerIpPort, ResponseCallback callback, Options options)Description copied from interface:ChannelAsynchronous interface, send message to peer- Specified by:
asyncSendToPeerin interfaceChannel- Parameters:
out- Message to be sentpeerIpPort- Remote ip:port informationcallback- Response callbackoptions- Include timeout
-
asyncSendToRandom
Description copied from interface:ChannelAsynchronous interface, send to an random peer- Specified by:
asyncSendToRandomin interfaceChannel- Parameters:
out- Message to be sentcallback- Response callbackoptions- Include timeout
-
asyncSendToPeerByRule
public void asyncSendToPeerByRule(Message out, PeerSelectRule rule, ResponseCallback callback, Options options)Description copied from interface:ChannelAsynchronous interface, send message to peer select by client`s rule- Specified by:
asyncSendToPeerByRulein interfaceChannel- Parameters:
out- Message to be sentrule- Rule set by clientcallback- Response callbackoptions- Include timeout
-
getConnectionInfo
Description copied from interface:ChannelGet connection information- Specified by:
getConnectionInfoin interfaceChannel- Returns:
- List of connection information
-
getAvailablePeer
public java.util.List<java.lang.String> getAvailablePeer()Description copied from interface:ChannelGet available peer information- Specified by:
getAvailablePeerin interfaceChannel- Returns:
- List of available peer
-
sendHeartbeatMessage
public void sendHeartbeatMessage(io.netty.channel.ChannelHandlerContext ctx) -
setThreadPool
public void setThreadPool(java.util.concurrent.ExecutorService threadPool)- Specified by:
setThreadPoolin interfaceChannel
-