Package org.fisco.bcos.sdk.channel
Interface Channel
- All Known Implementing Classes:
ChannelImp
public interface Channel
The channel module interface.
-
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 sendstatic Channelbuild(ConfigOption configOption)Init channel modulejava.util.List<java.lang.String>getAvailablePeer()Get available peer informationjava.util.List<ConnectionInfo>getConnectionInfo()Get connection informationNetworkgetNetwork()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 messagesvoidsetThreadPool(java.util.concurrent.ExecutorService threadPool)voidstart()voidstop()
-
Method Details
-
build
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
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 messagehandler- the message handler
-
addConnectHandler
Add a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is called- Parameters:
handler- the connect handler
-
addEstablishHandler
Add a establish handler, when the SDK establishes a connection with the node, call the handler- Parameters:
handler- the establish handler
-
addDisconnectHandler
Add a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is called- Parameters:
handler- disconnect handler
-
broadcastToGroup
Send a message to the given group, only send- Parameters:
out- Message to be sentgroupId- ID of the group receiving the message packet
-
broadcast
Broadcast to all peer, only send- Parameters:
out- Message to be sent
-
sendToPeer
Synchronize interface, send a message to the given peer, and get the response- Parameters:
out- Message to be sentpeerIpPort- Remote ip:port information- Returns:
- Remote reply
-
sendToPeerWithTimeOut
Synchronize interface with timeout, send a message to the given peer, and get the response- Parameters:
out- Message to be sentpeerIpPort- Remote ip:port informationoptions- Include timeout- Returns:
- Remote reply
-
sendToRandomWithTimeOut
Synchronize interface with timeout, randomly select nodes to send messages- Parameters:
out- Message to be sentoptions- Include timeout- Returns:
- Remote reply
-
sendToPeerByRuleWithTimeOut
Synchronize interface with timeout, send message to peer select by client`s rule- Parameters:
out- Message to be sentrule- Rule set by clientoptions- 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 sentpeerIpPort- Remote ip:port informationcallback- Response callbackoptions- Include timeout
-
asyncSendToRandom
Asynchronous interface, send to an random peer- Parameters:
out- Message to be sentcallback- Response callbackoptions- 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 sentrule- Rule set by clientcallback- Response callbackoptions- 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)
-