NodeIDType
- This class has support for retransmissions with exponential
backoff. But you can't rely on this backoff for anything other
than ephemeral traffic bursts. If you are overloaded, you are
overloaded, so you must just reduce the load.public class JSONMessenger<NodeIDType> extends java.lang.Object implements SSLMessenger<NodeIDType,org.json.JSONObject>
Modifier and Type | Class and Description |
---|---|
static class |
JSONMessenger.JSONObjectByteableWrapper |
static class |
JSONMessenger.JSONObjectWrapper |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.ScheduledExecutorService |
execpool |
static java.lang.String |
SENT_TIME
The JSON key for the time when the message was sent.
|
Constructor and Description |
---|
JSONMessenger(InterfaceNIOTransport<NodeIDType,org.json.JSONObject> niot) |
JSONMessenger(InterfaceNIOTransport<NodeIDType,org.json.JSONObject> niot,
int numWorkers) |
Modifier and Type | Method and Description |
---|---|
void |
addPacketDemultiplexer(AbstractPacketDemultiplexer<?> pd) |
AddressMessenger<org.json.JSONObject> |
getClientMessenger() |
AddressMessenger<org.json.JSONObject> |
getClientMessenger(java.net.InetSocketAddress listenSockAddr) |
java.net.InetSocketAddress |
getListeningSocketAddress() |
NodeIDType |
getMyID() |
protected InterfaceNIOTransport<NodeIDType,org.json.JSONObject> |
getNIOTransport() |
NodeConfig<NodeIDType> |
getNodeConfig() |
AddressMessenger<org.json.JSONObject> |
getSSLClientMessenger() |
SSLDataProcessingWorker.SSL_MODES |
getSSLMode() |
boolean |
isDisconnected(NodeIDType node) |
boolean |
isStopped() |
void |
precedePacketDemultiplexer(AbstractPacketDemultiplexer<?> pd) |
void |
send(GenericMessagingTask<NodeIDType,?> mtask) |
protected void |
send(GenericMessagingTask<NodeIDType,?> mtask,
boolean useWorkers)
Send returns void because it is the "ultimate" send.
|
void |
sendClient(java.net.InetSocketAddress sockAddr,
java.lang.Object message) |
int |
sendClient(java.net.InetSocketAddress sockAddr,
java.lang.Object message,
java.net.InetSocketAddress listenSocketAddress)
A hack that relies on the fact that NIO treats JSONObject as no different
from any other object in that it invokes toString() and then getBytes(.)
to serialize and send it over the network.
|
int |
sendToAddress(java.net.InetSocketAddress isa,
byte[] msg) |
int |
sendToAddress(java.net.InetSocketAddress address,
org.json.JSONObject jsonData)
Sends jsonData to address.
|
int |
sendToID(NodeIDType id,
byte[] msg) |
int |
sendToID(NodeIDType id,
org.json.JSONObject jsonData)
Sends jsonData to node id.
|
void |
setClientMessenger(AddressMessenger<?> clientMessenger) |
void |
setSSLClientMessenger(AddressMessenger<?> sslClientMessenger) |
void |
stop()
Needs to be called to close NIO gracefully.
|
java.lang.String |
toString() |
public static final java.lang.String SENT_TIME
AbstractPacketDemultiplexer.handleMessage
protected final java.util.concurrent.ScheduledExecutorService execpool
public JSONMessenger(InterfaceNIOTransport<NodeIDType,org.json.JSONObject> niot)
niot
- public JSONMessenger(InterfaceNIOTransport<NodeIDType,org.json.JSONObject> niot, int numWorkers)
niot
- numWorkers
- public void send(GenericMessagingTask<NodeIDType,?> mtask) throws java.io.IOException, org.json.JSONException
send
in interface Messenger<NodeIDType,org.json.JSONObject>
java.io.IOException
org.json.JSONException
protected void send(GenericMessagingTask<NodeIDType,?> mtask, boolean useWorkers) throws java.io.IOException, org.json.JSONException
java.io.IOException
org.json.JSONException
public void stop()
InterfaceNIOTransport
stop
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
public java.lang.String toString()
toString
in class java.lang.Object
public int sendToID(NodeIDType id, org.json.JSONObject jsonData) throws java.io.IOException
sendToID
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
id
- jsonData
- java.io.IOException
public int sendToAddress(java.net.InetSocketAddress address, org.json.JSONObject jsonData) throws java.io.IOException
sendToAddress
in interface AddressMessenger<org.json.JSONObject>
sendToAddress
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
address
- jsonData
- sendToID(Object,
JSONObject)
.java.io.IOException
public NodeIDType getMyID()
getMyID
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
public void addPacketDemultiplexer(AbstractPacketDemultiplexer<?> pd)
addPacketDemultiplexer
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
pd
- The supplied packet demultiplexer is appended to end of the
existing list. Messages will be processed by the first
demultiplexer that has registered for processing the
corresponding packet type and only by the first demultiplexer.
Note that there is no way to remove demultiplexers. All the necessary packet demultiplexers must be determined at design time. It is strongly recommended that all demultiplexers process exclusive sets of packet types. Relying on the order of chained demultiplexers is a bad idea.
public void precedePacketDemultiplexer(AbstractPacketDemultiplexer<?> pd)
precedePacketDemultiplexer
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
pd
- The demultiplexer is placed at the head of the existing list.protected InterfaceNIOTransport<NodeIDType,org.json.JSONObject> getNIOTransport()
public AddressMessenger<org.json.JSONObject> getClientMessenger()
getClientMessenger
in interface SSLMessenger<NodeIDType,org.json.JSONObject>
public AddressMessenger<org.json.JSONObject> getSSLClientMessenger()
getSSLClientMessenger
in interface SSLMessenger<NodeIDType,org.json.JSONObject>
public void setClientMessenger(AddressMessenger<?> clientMessenger)
setClientMessenger
in interface SSLMessenger<NodeIDType,org.json.JSONObject>
public void setSSLClientMessenger(AddressMessenger<?> sslClientMessenger)
setSSLClientMessenger
in interface SSLMessenger<NodeIDType,org.json.JSONObject>
public int sendClient(java.net.InetSocketAddress sockAddr, java.lang.Object message, java.net.InetSocketAddress listenSocketAddress) throws org.json.JSONException, java.io.IOException
sockAddr
- message
- listenSocketAddress
- org.json.JSONException
java.io.IOException
public void sendClient(java.net.InetSocketAddress sockAddr, java.lang.Object message) throws org.json.JSONException, java.io.IOException
sockAddr
- message
- org.json.JSONException
java.io.IOException
public NodeConfig<NodeIDType> getNodeConfig()
getNodeConfig
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
public SSLDataProcessingWorker.SSL_MODES getSSLMode()
getSSLMode
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
public int sendToID(NodeIDType id, byte[] msg) throws java.io.IOException
sendToID
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
java.io.IOException
public int sendToAddress(java.net.InetSocketAddress isa, byte[] msg) throws java.io.IOException
sendToAddress
in interface AddressMessenger<org.json.JSONObject>
sendToAddress
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
java.io.IOException
public boolean isStopped()
isStopped
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
public boolean isDisconnected(NodeIDType node)
isDisconnected
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>
node
got disconnected.public AddressMessenger<org.json.JSONObject> getClientMessenger(java.net.InetSocketAddress listenSockAddr)
getClientMessenger
in interface SSLMessenger<NodeIDType,org.json.JSONObject>
public java.net.InetSocketAddress getListeningSocketAddress()
getListeningSocketAddress
in interface InterfaceNIOTransport<NodeIDType,org.json.JSONObject>