BusBase¶
-
public abstract class
BusBase
extends AbstractActivatable implements Bus¶ A utility base class for the implementation of the
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 calldeactivate()
when overriding this method to ensure that receiving threads are terminated properly.- Author
swrede, jwienke
Constructors¶
BusBase¶
-
protected
BusBase
(SocketOptions options)¶ Constructor.
- Parameters
options – socket options to use
Methods¶
addConnection¶
-
protected 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. 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.- Parameters
con – the connection to register
- Returns
receiver thread for the added connection. Should be started using
Thread.start()
at an appropriate time.
addNotificationReceiver¶
-
public void
addNotificationReceiver
(NotificationReceiver receiver)¶
getSocketOptions¶
-
public SocketOptions
getSocketOptions
()¶
handleGlobally¶
-
protected void
handleGlobally
(Notification notification, BusConnection ignoreConnection)¶ Dispatches the notification to registered connections.
- Parameters
notification – notification to dispatch
ignoreConnection – for dispatching, ignore this connection and do not pass the notification to this instance. Might be
null
if this filtering is not required.
- Throws
RSBException – error during dispatching
handleGlobally¶
-
protected void
handleGlobally
(Notification notification)¶ Dispatches the notification to registered connections.
- Parameters
notification – notification to dispatch
- Throws
RSBException – error during dispatching
handleIncoming¶
-
public abstract void
handleIncoming
(Notification notification, BusConnection sourceConnection)¶ Implement this method to specify the behavior in case of an incoming notification received from a connection. Implementations can use the utility methods
handleLocally(rsb.protocol.NotificationType.Notification)
andhandleGlobally(rsb.protocol.NotificationType.Notification)
to implement their processing logic.- Parameters
notification – the received connection
sourceConnection – the source
BusConnection
providing this Notification
- Throws
RSBException – processing error
handleIncoming¶
-
public void
handleIncoming
(Notification notification)¶ Implement this method to specify the behavior in case of an incoming notification received from a connection. Implementations can use the utility methods
handleLocally(rsb.protocol.NotificationType.Notification)
andhandleGlobally(rsb.protocol.NotificationType.Notification)
orhandleGlobally(rsb.protocol.NotificationType.Notification,BusConnection)
to implement their processing logic. This method assumes that the notification was not received from aBusConnection
and passesnull
tohandleIncoming(rsb.protocol.NotificationType.Notification,BusConnection)
.- Parameters
notification – the received connection
- Throws
RSBException – processing error
handleLocally¶
-
protected void
handleLocally
(Notification notification)¶ Dispatches the specified notifications to all registered
rsb.transport.socket.Bus.NotificationReceiver
s.- Parameters
notification – the notification to dispatch
- Throws
RSBException – exception during dispatching
numberOfConnections¶
-
public int
numberOfConnections
()¶ Indicates how many connections are currently registered.
- Returns
number of connections
removeConnection¶
-
protected ReceiveThread
removeConnection
(BusConnection con)¶ Removes a connection from the dispatching logic. The connection is neither closed automatically nor is the receiving thread terminated.
- Parameters
con – the connection to remove
- Returns
the ReceiveThread responsible for this connection or
null
if this connection was not part of the dispatching logic
removeNotificationReceiver¶
-
public void
removeNotificationReceiver
(NotificationReceiver receiver)¶