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 void
addConnectHandler(MsgHandler handler)
Add a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is calledvoid
addDisconnectHandler(MsgHandler handler)
Add a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is calledvoid
addEstablishHandler(MsgHandler handler)
Add a establish handler, when the SDK establishes a connection with the node, call the handlervoid
addMessageHandler(MsgType type, MsgHandler handler)
Add a message handler to handle specific type messages.void
asyncSendToPeer(Message out, java.lang.String peerIpPort, ResponseCallback callback, Options options)
Asynchronous interface, send message to peervoid
asyncSendToPeerByRule(Message out, PeerSelectRule rule, ResponseCallback callback, Options options)
Asynchronous interface, send message to peer select by client`s rulevoid
asyncSendToRandom(Message out, ResponseCallback callback, Options options)
Asynchronous interface, send to an random peervoid
broadcast(Message out)
Broadcast to all peer, only sendvoid
broadcastToGroup(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 informationNetwork
getNetwork()
void
sendHeartbeatMessage(io.netty.channel.ChannelHandlerContext ctx)
Response
sendToPeer(Message out, java.lang.String peerIpPort)
Synchronize interface, send a message to the given peer, and get the responseResponse
sendToPeerByRuleWithTimeOut(Message out, PeerSelectRule rule, Options options)
Synchronize interface with timeout, send message to peer select by client`s ruleResponse
sendToPeerWithTimeOut(Message out, java.lang.String peerIpPort, Options options)
Synchronize interface with timeout, send a message to the given peer, and get the responseResponse
sendToRandomWithTimeOut(Message out, Options options)
Synchronize interface with timeout, randomly select nodes to send messagesvoid
setGroupId2PeerIpPortList(java.util.Map<java.lang.String,java.util.List<java.lang.String>> groupId2PeerIpPortList)
void
setThreadPool(java.util.concurrent.ExecutorService threadPool)
void
start()
void
stop()
void
waitResponse(org.fisco.bcos.sdk.channel.ChannelImp.Callback callback, Options options)
-
Constructor Details
-
ChannelImp
- Throws:
ConfigException
-
-
Method Details
-
getNetwork
- Specified by:
getNetwork
in interfaceChannel
-
start
public void start() -
stop
public void stop() -
addConnectHandler
Description copied from interface:Channel
Add a connect handler, when one connect success, call handler.onConnect(ChannleHandlerContext ctx)is called- Specified by:
addConnectHandler
in interfaceChannel
- Parameters:
handler
- the connect handler
-
addEstablishHandler
Description copied from interface:Channel
Add a establish handler, when the SDK establishes a connection with the node, call the handler- Specified by:
addEstablishHandler
in interfaceChannel
- Parameters:
handler
- the establish handler
-
addMessageHandler
Description copied from interface:Channel
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.- Specified by:
addMessageHandler
in interfaceChannel
- Parameters:
type
- the type of messagehandler
- the message handler
-
addDisconnectHandler
Description copied from interface:Channel
Add a disconnect handler, when one connection disconnect, handler.onDisconnect(ChannleHandlerContext ctx) is called- Specified by:
addDisconnectHandler
in 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:Channel
Send a message to the given group, only send- Specified by:
broadcastToGroup
in interfaceChannel
- Parameters:
out
- Message to be sentgroupId
- ID of the group receiving the message packet
-
broadcast
Description copied from interface:Channel
Broadcast to all peer, only send -
sendToPeer
Description copied from interface:Channel
Synchronize interface, send a message to the given peer, and get the response- Specified by:
sendToPeer
in interfaceChannel
- Parameters:
out
- Message to be sentpeerIpPort
- Remote ip:port information- Returns:
- Remote reply
-
waitResponse
-
sendToPeerWithTimeOut
Description copied from interface:Channel
Synchronize interface with timeout, send a message to the given peer, and get the response- Specified by:
sendToPeerWithTimeOut
in interfaceChannel
- Parameters:
out
- Message to be sentpeerIpPort
- Remote ip:port informationoptions
- Include timeout- Returns:
- Remote reply
-
sendToRandomWithTimeOut
Description copied from interface:Channel
Synchronize interface with timeout, randomly select nodes to send messages- Specified by:
sendToRandomWithTimeOut
in interfaceChannel
- Parameters:
out
- Message to be sentoptions
- Include timeout- Returns:
- Remote reply
-
sendToPeerByRuleWithTimeOut
Description copied from interface:Channel
Synchronize interface with timeout, send message to peer select by client`s rule- Specified by:
sendToPeerByRuleWithTimeOut
in 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:Channel
Asynchronous interface, send message to peer- Specified by:
asyncSendToPeer
in interfaceChannel
- Parameters:
out
- Message to be sentpeerIpPort
- Remote ip:port informationcallback
- Response callbackoptions
- Include timeout
-
asyncSendToRandom
Description copied from interface:Channel
Asynchronous interface, send to an random peer- Specified by:
asyncSendToRandom
in 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:Channel
Asynchronous interface, send message to peer select by client`s rule- Specified by:
asyncSendToPeerByRule
in interfaceChannel
- Parameters:
out
- Message to be sentrule
- Rule set by clientcallback
- Response callbackoptions
- Include timeout
-
getConnectionInfo
Description copied from interface:Channel
Get connection information- Specified by:
getConnectionInfo
in interfaceChannel
- Returns:
- List of connection information
-
getAvailablePeer
public java.util.List<java.lang.String> getAvailablePeer()Description copied from interface:Channel
Get available peer information- Specified by:
getAvailablePeer
in 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:
setThreadPool
in interfaceChannel
-