public interface CommunicationController
Interface for a component that manages I/O activities. A communication
controller typically controls one or more
TimerProcessors calling one of their process methods at the right
A communication controller allows communication processors to register for
I/O events for channels and for timer events. The controller will call the
TimerProcessor.processTimer() method each time such an event occurs.
This way, one thread can handle I/O and timer events for multiple components.
A communication controller must be thread safe, meaning that a communication processor must be able to call the controller's methods at any time, not just from one of the methods called by the controller.
On the other hand, a communication controller may never call more than one
process method in parallel. This is important,
because processor's might not be thread-safe and their might be hidden
dependencies between processors registered with the same communication
|Modifier and Type||Method and Description|
Tells whether the current thread is the communication thread.
Registers a channel with the communication controller.
Registers for a timer event.
SelectionKey registerChannel(ChannelProcessor channelProcessor, SelectableChannel channel) throws ClosedChannelException
Registers a channel with the communication controller. This tells the
communication controller that the channel processor is interested in I/O
events for this channel. The channel processor can exactly define which
events it is interested in through the
SelectionKey returned by
When this communication controller detects that one of the I/O events the
channelProcessor has registered for has occurred, it calls
The selection key returned by this method may be a wrapper that only
provides a subset of the operations defined in the
interface. In particular, its
methods may throw an
UnsupportedOperationException. This should
not be a problem because a processor does not have good reasons to call
this method anyway.
A typical implementation of this method will call the
SelectableChannel.register(java.nio.channels.Selector, int, Object)
method and will throw any exception thrown by this method.
channelProcessor- the channel processor that registers the channel. Each channel may only be registered for a single channel processor.
channel- the channel that shall be registered. Each channel may only be registered for a single channel processor.
Selector. This selection key might not be the original selection key but a wrapper that does not implement the
ClosedChannelException- if the
channelchannel is closed.
IllegalBlockingModeException- if the
channelis in blocking mode.
IllegalSelectorException- if the
channelwas not created by the same provider as this communication controller's selector.
CancelledKeyException- if the
channelis currently registered with this communication controller's selector but the corresponding key has already been cancelled.
void registerTimer(TimerProcessor timerProcessor, long eventTime)
Registers for a timer event. When the time specified by
eventTime has come or passed, this communication controller
calls the processor's
Multiple timer registrations for the same
result in a single call to
processTimer() if the
eventTime of all of these registrations has passed.
The general contract is that a processor's
method may be called an indefinite amount of time after, but never before
eventTime has passed.
timerProcessor- the processor that is registering for a timer event.
eventTime- Java time-stamp (as returned by
System.currentTimeMillis()) that specifies the point in time when the timer event should occur. The processor's process method may be called later, but never before this time.
TimerProcessors. This method can be used by processors that are not thread safe to detect whether code is run in the correct thread.
trueif the current thread is the communication thread,
Copyright © 2014–2016 aquenos GmbH. All rights reserved.