MESSAGE - the generic typepublic abstract class AbstractMultiConnectionSocket<MESSAGE> extends java.lang.Object implements MultiConnectionSocket
MultiConnectionSocket. This superclass
uses Disruptor to pull EEG device messages off a socket and pass them to an
Executor for processing.
Subclasses type the format of the raw data messages. Should multiple types
ie. double and byte arrays be received from the device then a serializable
wrapper can be created to contain the data.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMultiConnectionSocket(boolean broadcasting)
Instantiates a new abstract multi connection socket.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addConnectionEventListener(ConnectionEventListener listener)
Adds the connection event listener.
|
void |
bindBroadcaster()
Binds the broadcaster to the local host and the broadcaster port in
AbstractSocketConnector. |
boolean |
canBroadcast()
Returns true if this instance has been configured for broadcasting.
|
void |
clearConnectionEventListeners()
Clear connection event listeners.
|
protected abstract org.apache.mina.core.service.IoHandler |
getHandlerAdapter()
Gets the handler adapter.
|
int |
getNumChannels()
Returns the number of channels.
|
protected void |
initBroadCaster()
Initialization of the broadcaster, to send
AbstractMultiConnectionEvents to remote processes which have
registered for subscriptions. |
boolean |
isBound()
Returns true if the broadcaster is bound.
|
protected void |
notifyConnectionEventListeners(ConnectionEvent.State state)
Notify connection event listeners.
|
protected abstract void |
parseMessage(MESSAGE message)
Invoked via Disruptor's onEvent processing, implement to notify event
listeners and any multi connection subscribers.
|
protected void |
publishMessage(MESSAGE message)
EEG device messages are passed to this method which uses Disruptor to pass
the message asynchronously for processing by subclasses.
|
void |
removeConnectionEventListener(ConnectionEventListener listener)
Removes the connection event listener.
|
void |
setNumChannels(int numChannels)
Sets the num channels.
|
void |
start()
Connects to the socket.
|
protected abstract void |
startImpl()
Implement to create a connection to the EEG device.
|
void |
stop()
Closes the connection to the
AbstractMultiConnectionSocket socket. |
protected abstract void |
stopImpl()
Implement to close the connection to the EEG device.
|
void |
unbindBroadcaster()
Unbinds the broadcaster.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetChannel, getChannels, isConnectedprotected AbstractMultiConnectionSocket(boolean broadcasting)
throws java.io.IOException
broadcasting - the broadcastingjava.io.IOException - Signals that an I/O exception has occurred.public final void start()
throws MultiConnectionSocketException
MultiConnectionSocketstart in interface MultiConnectionSocketMultiConnectionSocketException - if already connected or an unexpected error occursprotected abstract void startImpl()
throws MultiConnectionSocketException
AbstractMultiConnectionSocket#publishMessage(String) method.MultiConnectionSocketException - the multi connection socket exceptionAbstractMultiConnectionSocket#publishMessage(String)public void stop()
MultiConnectionSocketAbstractMultiConnectionSocket socket.stop in interface MultiConnectionSocketprotected abstract void stopImpl()
public void addConnectionEventListener(ConnectionEventListener listener)
MultiConnectionSocketaddConnectionEventListener in interface MultiConnectionSocketlistener - the listenerpublic void removeConnectionEventListener(ConnectionEventListener listener)
MultiConnectionSocketremoveConnectionEventListener in interface MultiConnectionSocketlistener - the listenerpublic void clearConnectionEventListeners()
MultiConnectionSocketclearConnectionEventListeners in interface MultiConnectionSocketpublic void bindBroadcaster()
throws java.io.IOException
MultiConnectionSocketAbstractSocketConnector.bindBroadcaster in interface MultiConnectionSocketjava.io.IOException - Signals that an I/O exception has occurred.AbstractSocketConnectorpublic void unbindBroadcaster()
MultiConnectionSocketunbindBroadcaster in interface MultiConnectionSocketAbstractSocketConnectorpublic boolean canBroadcast()
MultiConnectionSocketcanBroadcast in interface MultiConnectionSocketpublic boolean isBound()
MultiConnectionSocketisBound in interface MultiConnectionSocketAbstractSocketConnectorprotected void notifyConnectionEventListeners(ConnectionEvent.State state)
state - the stateprotected void initBroadCaster()
throws java.io.IOException
AbstractMultiConnectionEvents to remote processes which have
registered for subscriptions. Invoke during object creation.java.io.IOException - Signals that an I/O exception has occurred.protected abstract org.apache.mina.core.service.IoHandler getHandlerAdapter()
protected void publishMessage(MESSAGE message)
message - the messageAbstractMultiConnectionSocket#parseMessage(String)protected abstract void parseMessage(MESSAGE message)
message - the messagepublic int getNumChannels()
MultiConnectionSocketgetNumChannels in interface MultiConnectionSocketpublic void setNumChannels(int numChannels)
numChannels - the new num channels