public abstract class BusBase extends AbstractActivatable implements Bus
Bus
interface.
This class offers methods for sending and receiving events to this bus as
well as registration of internal Connectors (inward) and Connections
(outward) which allow to send event notifications to external participants.
Subclasses of this class should use this instance to synchronize on.
Subclasses should call deactivate()
when overriding this method to
ensure that receiving threads are terminated properly.Modifier and Type | Class and Description |
---|---|
protected class |
BusBase.ReceiveThread
A thread that continuously reads from a
BusConnection and passes
the received NotificationType.Notification s to
handleIncoming(rsb.protocol.NotificationType.Notification)
. |
Bus.NotificationReceiver
Activatable.State
Modifier | Constructor and Description |
---|---|
protected |
BusBase(SocketOptions options)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected BusBase.ReceiveThread |
addConnection(BusConnection con)
Registers a connection for the dispatching logic in
handleGlobally(rsb.protocol.NotificationType.Notification) and
creates a new instance of a thread receiving notifications from this
connection. |
void |
addNotificationReceiver(Bus.NotificationReceiver receiver)
Registers a local observer for notifications.
|
void |
deactivate()
Deactivate all resources that are owned by a specific object in order to
correctly tear down.
|
SocketOptions |
getSocketOptions()
Returns the current socket configuration of the bus.
|
URI |
getTransportUri()
Return the URI describing the transport manifested by this bus.
|
protected void |
handleGlobally(NotificationType.Notification notification)
Dispatches the notification to registered connections.
|
protected void |
handleGlobally(NotificationType.Notification notification,
BusConnection ignoreConnection)
Dispatches the notification to registered connections.
|
void |
handleIncoming(NotificationType.Notification notification)
Implement this method to specify the behavior in case of an incoming
notification received from a connection.
|
abstract void |
handleIncoming(NotificationType.Notification notification,
BusConnection sourceConnection)
Implement this method to specify the behavior in case of an incoming
notification received from a connection.
|
protected void |
handleLocally(NotificationType.Notification notification)
Dispatches the specified notifications to all registered
Bus.NotificationReceiver s. |
void |
handleOutgoing(NotificationType.Notification notification)
Handles a notification to be sent over the bus.
|
int |
numberOfConnections()
Indicates how many connections are currently registered.
|
protected BusBase.ReceiveThread |
removeConnection(BusConnection con)
Removes a connection from the dispatching logic.
|
void |
removeNotificationReceiver(Bus.NotificationReceiver receiver)
Removes a local observer for notifications if registered before.
|
close
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
activate, isActive
protected BusBase(SocketOptions options)
options
- socket options to usepublic SocketOptions getSocketOptions()
Bus
getSocketOptions
in interface Bus
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 abstract void handleIncoming(NotificationType.Notification notification, BusConnection sourceConnection) throws RSBException
handleLocally(rsb.protocol.NotificationType.Notification)
and
handleGlobally(rsb.protocol.NotificationType.Notification)
to
implement their processing logic.notification
- the received connectionsourceConnection
- the source BusConnection
providing this NotificationRSBException
- processing errorpublic void handleIncoming(NotificationType.Notification notification) throws RSBException
handleLocally(rsb.protocol.NotificationType.Notification)
and
handleGlobally(rsb.protocol.NotificationType.Notification)
or
handleGlobally(rsb.protocol.NotificationType.Notification, BusConnection)
to implement their processing logic.
This method assumes that the notification was not received from a
BusConnection
and passes null
to
handleIncoming(rsb.protocol.NotificationType.Notification, BusConnection)
.notification
- the received connectionRSBException
- processing errorprotected void handleLocally(NotificationType.Notification notification) throws RSBException
Bus.NotificationReceiver
s.notification
- the notification to dispatchRSBException
- exception during dispatchingprotected void handleGlobally(NotificationType.Notification notification, BusConnection ignoreConnection) throws RSBException
notification
- notification to dispatchignoreConnection
- for dispatching, ignore this connection and do not pass the
notification to this instance. Might be null
if
this filtering is not required.RSBException
- error during dispatchingprotected void handleGlobally(NotificationType.Notification notification) throws RSBException
notification
- notification to dispatchRSBException
- error during dispatchingpublic void handleOutgoing(NotificationType.Notification notification) throws RSBException
Bus
Bus.NotificationReceiver
and to all registered BusConnection
s.handleOutgoing
in interface Bus
notification
- the notification to distributeRSBException
- error during dispatchingprotected BusBase.ReceiveThread addConnection(BusConnection con)
handleGlobally(rsb.protocol.NotificationType.Notification)
and
creates a new instance of a thread receiving notifications from this
connection. However, this thread is not started. It is the responsibility
of the client calling this method to start the thread at an appropriate
time. This manual handling is necessary as the procedure varies for bus
server and clients.con
- the connection to registerThread.start()
at an appropriate time.protected BusBase.ReceiveThread removeConnection(BusConnection con)
con
- the connection to removenull
if this connection was not part of the
dispatching logicpublic int numberOfConnections()
public void addNotificationReceiver(Bus.NotificationReceiver receiver)
Bus
addNotificationReceiver
in interface Bus
receiver
- the receiver to registerpublic void removeNotificationReceiver(Bus.NotificationReceiver receiver)
Bus
removeNotificationReceiver
in interface Bus
receiver
- the receiver to removepublic URI getTransportUri()
Bus
getTransportUri
in interface Bus
null
Copyright © 2018 CoR-Lab. All rights reserved.