public abstract class BusConnectionBase extends Object implements BusConnection
BusConnection
interface.
Subclasses need to use this object for synchronization.
Subclasses need to call setSocket(Socket)
with a valid socket before
activate()
will be called. activate()
will automatically
call handshake()
.Activatable.State
Constructor and Description |
---|
BusConnectionBase() |
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates all resources that belong to a specific object.
|
void |
deactivate()
Deactivate all resources that are owned by a specific object in order to
correctly tear down.
|
SocketOptions |
getOptions()
Returns the current configuration of the connection.
|
protected ReadableByteChannel |
getReader()
Returns the reader for the internal socket.
|
Socket |
getSocket()
Returns the contained socket instance.
|
protected WritableByteChannel |
getWriter()
Returns the writer for the internal socket.
|
protected abstract void |
handshake()
Performs the handshake step of the protocol.
|
boolean |
isActive()
Tells whether this class is currently active or not.
|
boolean |
isActiveShutdown()
Indicates whether the connection is currently performing an active
shutdown as a consequence of calling
BusConnection.shutdown() . |
protected int |
readLength()
Extract length of next notification blob.
|
NotificationType.Notification |
readNotification()
Reads a notification from the connection.
|
void |
sendNotification(NotificationType.Notification notification)
Sends a notification over the connection.
|
protected void |
setOptions(SocketOptions options)
Sets the options for the socket to hold in this instance.
|
protected void |
setSocket(Socket socket)
Sets the internal socket instance.
|
void |
shutdown()
This method starts and orderly shutdown of the connection.
|
protected abstract void handshake() throws RSBException
RSBException
- error during handshakepublic Socket getSocket()
null
if not set yet.protected void setSocket(Socket socket)
socket
- new socket instanceprotected void setOptions(SocketOptions options)
options
- socket options to holdpublic SocketOptions getOptions()
BusConnection
getOptions
in interface BusConnection
protected ReadableByteChannel getReader()
null
if called before
activate()
protected WritableByteChannel getWriter()
null
if called before
activate()
public void activate() throws RSBException
Activatable
activate
in interface Activatable
RSBException
- generic error related to RSBpublic void shutdown() throws IOException
BusConnection
Activatable.deactivate()
for this procedure to succeed. Should
be callable multiple times without raising an error. Calls after the
first are usually ignored.shutdown
in interface BusConnection
IOException
- error indicating the shutdown due to socket writing problemspublic boolean isActiveShutdown()
BusConnection
BusConnection.shutdown()
.isActiveShutdown
in interface BusConnection
true
in case of active shutdown, else
false
public void deactivate() throws RSBException, InterruptedException
Activatable
deactivate
in interface Activatable
RSBException
- generic error related to RSBInterruptedException
- interrupted while waiting for proper deactivation. Object
might be in an undefined state nowpublic boolean isActive()
Activatable
isActive
in interface Activatable
true
if activeprotected int readLength() throws IOException
IOException
- error while reading from the socketpublic NotificationType.Notification readNotification() throws IOException
BusConnection
readNotification
in interface BusConnection
IOException
- communication errorpublic void sendNotification(NotificationType.Notification notification) throws IOException
BusConnection
sendNotification
in interface BusConnection
notification
- the notification to send. Must be complete so that it can be
serialized.IOException
- error sending the notificationCopyright © 2018 CoR-Lab. All rights reserved.