public abstract class AbstractSocketDriver extends AbstractDriver<byte[]>
AbstractDriver
that implements connect/disconnect/read/write management of a Socket
connection.builderFactory, diagnosticsContext, executor, log, nodeManager
Modifier | Constructor and Description |
---|---|
protected |
AbstractSocketDriver(DriverContext driverContext,
java.lang.String hostname,
int port,
int timeout) |
Modifier and Type | Method and Description |
---|---|
protected void |
connect()
A chance for implementations to do anything that is needed before moving into
DriverState.Connected . |
protected abstract Request<byte[]> |
createConnectRequest()
Called after the driver has successfully opened a TCP connection but before moving into
DriverState.Connected . |
protected void |
disconnect()
A chance for implementations to do anything that is needed before moving into
DriverState.Disconnected . |
java.lang.String |
getHostname() |
int |
getPort() |
int |
getSoTimeout() |
int |
getTimeout() |
protected void |
messageArrived(byte[] message)
Notify
AbstractDriver that a messaged arrived. |
protected abstract int |
messageLength(java.nio.ByteBuffer buffer)
Search the given ByteBuffer starting at its current position looking for a message and return the length in bytes
of the next message in the buffer.
|
void |
notifyConnectFailed(java.lang.Exception connectError)
Callback indicating that the result of
AbstractDriver.connect() was a failure. |
protected void |
reconnect() |
void |
setHostname(java.lang.String hostname) |
void |
setPort(int port) |
void |
setSoTimeout(int soTimeout) |
void |
setTimeout(int timeout) |
boolean |
writeToChannel(java.nio.ByteBuffer... bufs)
Writes the contents of the given ByteBuffers to the channel.
|
addDriverTag, browse, createBrowseRequest, createReadRequest, createSubscribeRequest, createWriteRequest, currentGuid, findTag, getConcurrentRequests, getDiagnostics, getDriverContext, getDriverMetrics, getDriverState, getDriverStatus, getDriverTagAddressPrefix, getLogger, getName, getRequestDiagnostics, getRequestKey, isBrowsingSupported, isOfflineBrowsingSupported, nextGuid, notifyConnectionLost, notifyConnectSucceeded, notifyDisconnectDone, optimizeRead, optimizeSubscribe, optimizeWrite, postRequest, readItems, removeDriverTag, reschedule, setConcurrentRequests, setState, shutdown, writeItems
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
buildNode, getDriverStatusJSLibName, getDriverStatusJSUrl
protected AbstractSocketDriver(DriverContext driverContext, java.lang.String hostname, int port, int timeout)
public java.lang.String getHostname()
public int getPort()
public int getTimeout()
public int getSoTimeout()
public void setHostname(java.lang.String hostname)
public void setPort(int port)
public void setTimeout(int timeout)
public void setSoTimeout(int soTimeout)
protected void connect()
AbstractDriver
DriverState.Connected
. When
done, AbstractDriver.notifyConnectSucceeded()
or AbstractDriver.notifyConnectFailed(Exception)
must be called.connect
in class AbstractDriver<byte[]>
public void notifyConnectFailed(java.lang.Exception connectError)
AbstractDriver
AbstractDriver.connect()
was a failure.
The contents of connectError
will be displayed to the user on the device status page of the Ignition
gateway.notifyConnectFailed
in class AbstractDriver<byte[]>
connectError
- A user-facing error message that will be displayed on the device status page of
the Ignition gateway.protected void disconnect()
AbstractDriver
DriverState.Disconnected
.
When done, AbstractDriver.notifyDisconnectDone()
must be called.disconnect
in class AbstractDriver<byte[]>
protected void reconnect()
protected void messageArrived(byte[] message)
AbstractDriver
that a messaged arrived. This cannot be called on the same
thread that Request.sendMessage()
was invoked on.messageArrived
in class AbstractDriver<byte[]>
message
- The message that has arrived.public boolean writeToChannel(java.nio.ByteBuffer... bufs)
bufs
- ByteBuffers to write.protected abstract Request<byte[]> createConnectRequest()
DriverState.Connected
.
Now is that chance for any requests needed to initialize communications with a device, such as negotiating PDU
size or session handles, to happen.
Return null if no connect Request
is necessary.
If a non-null value is returned, then it is the responsibility of the implementation to call
AbstractDriver.notifyConnectSucceeded()
or notifyConnectFailed(Exception)
when finished connecting.Request
or null if none is necessary.protected abstract int messageLength(java.nio.ByteBuffer buffer)
ByteBuffer.get()
and friends. Only the buffer's position should
ever be modified by this function; it should leave the mark and limit alone.buffer
- A ByteBuffer containing bytes that have come in off the wire.