public abstract class ConnectorBase extends Object implements Connector
Connector. It connects
a server to a network interface and a port. ConnectorBase contains two
separate threads for sending and receiving. The receiver thread constantly
calls #receiveNext() which is supposed to listen on a socket until a
datagram arrives and forward it to the RawDataChannel. The sender
thread constantly calls #sendNext() which is supposed to wait on the
outgoing queue for a RawData message to send. Both
#sendNext() and #receiveNext() are expected to be blocking.| Constructor and Description |
|---|
ConnectorBase(InetSocketAddress address)
Instantiates a new connector base.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Stops the connector and cleans up any leftovers.
|
InetSocketAddress |
getAddress()
Gets the address of the socket this connector is bound to.
|
InetSocketAddress |
getLocalAddr()
Gets the local address this connector is listening to.
|
abstract String |
getName()
Gets the name of the connector, e.g.
|
RawDataChannel |
getReceiver()
Gets the receiver.
|
protected int |
getReceiverThreadCount()
Gets the receiver thread count.
|
protected int |
getSenderThreadCount()
Gets the sender thread count.
|
boolean |
isRunning()
Checks the connector has started but not stopped yet.
|
protected abstract RawData |
receiveNext()
Receives data from the socket queue.
|
void |
send(RawData msg)
Sends a raw message to a client via the network.
|
protected abstract void |
sendNext(RawData raw)
Sends data over the socket.
|
void |
setRawDataReceiver(RawDataChannel receiver)
Sets the handler for incoming messages.
|
void |
setReceiver(RawDataChannel receiver)
Sets the receiver for incoming messages.
|
void |
start()
Starts the connector.
|
void |
stop()
Stops the connector.
|
public ConnectorBase(InetSocketAddress address)
address - the address to listen topublic InetSocketAddress getAddress()
ConnectorgetAddress in interface Connectorpublic abstract String getName()
protected abstract RawData receiveNext() throws Exception
Exception - any exceptions that should be properly loggedprotected abstract void sendNext(RawData raw) throws Exception
raw - the raw data with metadataException - any exception that should be properly loggedprotected int getReceiverThreadCount()
protected int getSenderThreadCount()
public void start()
throws IOException
Connectorstart in interface ConnectorIOException - Signals that an I/O exception has occurred.public void stop()
ConnectorConnector.start() method.public void destroy()
public void send(RawData msg)
Connectorpublic void setRawDataReceiver(RawDataChannel receiver)
ConnectorRawDataChannel.receiveData(RawData) method
will be called whenever a new message from a client has been received
via the network.setRawDataReceiver in interface Connectorreceiver - the message handlerpublic InetSocketAddress getLocalAddr()
public RawDataChannel getReceiver()
public void setReceiver(RawDataChannel receiver)
receiver - the new receiverpublic boolean isRunning()
Copyright © 2019 Eclipse Foundation. All rights reserved.