ESP OpenBCI - An EEG Signal Processing Library for OpenBCI Hardware

com.github.mrstampy.esp.multiconnectionsocket
Class AbstractMultiConnectionSocket<MESSAGE>

java.lang.Object
  extended by com.github.mrstampy.esp.multiconnectionsocket.AbstractMultiConnectionSocket<MESSAGE>
Type Parameters:
MESSAGE - the generic type
All Implemented Interfaces:
MultiConnectionSocket
Direct Known Subclasses:
MultiConnectOpenBCISocket

public abstract class AbstractMultiConnectionSocket<MESSAGE>
extends java.lang.Object
implements MultiConnectionSocket

Abstract implementation of a 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.

Author:
burton

Constructor Summary
protected AbstractMultiConnectionSocket(boolean broadcasting)
          Instantiates a new abstract multi connection socket.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.github.mrstampy.esp.multiconnectionsocket.MultiConnectionSocket
getChannel, getChannels, isConnected
 

Constructor Detail

AbstractMultiConnectionSocket

protected AbstractMultiConnectionSocket(boolean broadcasting)
                                 throws java.io.IOException
Instantiates a new abstract multi connection socket.

Parameters:
broadcasting - the broadcasting
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
Method Detail

start

public final void start()
                 throws MultiConnectionSocketException
Description copied from interface: MultiConnectionSocket
Connects to the socket.

Specified by:
start in interface MultiConnectionSocket
Throws:
MultiConnectionSocketException - if already connected or an unexpected error occurs

startImpl

protected abstract void startImpl()
                           throws MultiConnectionSocketException
Implement to create a connection to the EEG device. Messages retrieved from the device should be passed to the AbstractMultiConnectionSocket#publishMessage(String) method.

Throws:
MultiConnectionSocketException - the multi connection socket exception
See Also:
AbstractMultiConnectionSocket#publishMessage(String)

stop

public void stop()
Description copied from interface: MultiConnectionSocket
Closes the connection to the AbstractMultiConnectionSocket socket.

Specified by:
stop in interface MultiConnectionSocket

stopImpl

protected abstract void stopImpl()
Implement to close the connection to the EEG device.


addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener listener)
Description copied from interface: MultiConnectionSocket
Adds the connection event listener.

Specified by:
addConnectionEventListener in interface MultiConnectionSocket
Parameters:
listener - the listener

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener listener)
Description copied from interface: MultiConnectionSocket
Removes the connection event listener.

Specified by:
removeConnectionEventListener in interface MultiConnectionSocket
Parameters:
listener - the listener

clearConnectionEventListeners

public void clearConnectionEventListeners()
Description copied from interface: MultiConnectionSocket
Clear connection event listeners.

Specified by:
clearConnectionEventListeners in interface MultiConnectionSocket

bindBroadcaster

public void bindBroadcaster()
                     throws java.io.IOException
Description copied from interface: MultiConnectionSocket
Binds the broadcaster to the local host and the broadcaster port in AbstractSocketConnector.

Specified by:
bindBroadcaster in interface MultiConnectionSocket
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
See Also:
AbstractSocketConnector

unbindBroadcaster

public void unbindBroadcaster()
Description copied from interface: MultiConnectionSocket
Unbinds the broadcaster.

Specified by:
unbindBroadcaster in interface MultiConnectionSocket
See Also:
AbstractSocketConnector

canBroadcast

public boolean canBroadcast()
Description copied from interface: MultiConnectionSocket
Returns true if this instance has been configured for broadcasting.

Specified by:
canBroadcast in interface MultiConnectionSocket
Returns:
true, if successful

isBound

public boolean isBound()
Description copied from interface: MultiConnectionSocket
Returns true if the broadcaster is bound.

Specified by:
isBound in interface MultiConnectionSocket
Returns:
true, if is bound
See Also:
AbstractSocketConnector

notifyConnectionEventListeners

protected void notifyConnectionEventListeners(ConnectionEvent.State state)
Notify connection event listeners.

Parameters:
state - the state

initBroadCaster

protected void initBroadCaster()
                        throws java.io.IOException
Initialization of the broadcaster, to send AbstractMultiConnectionEvents to remote processes which have registered for subscriptions. Invoke during object creation.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getHandlerAdapter

protected abstract org.apache.mina.core.service.IoHandler getHandlerAdapter()
Gets the handler adapter.

Returns:
the handler adapter

publishMessage

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.

Parameters:
message - the message
See Also:
AbstractMultiConnectionSocket#parseMessage(String)

parseMessage

protected abstract void parseMessage(MESSAGE message)
Invoked via Disruptor's onEvent processing, implement to notify event listeners and any multi connection subscribers.

Parameters:
message - the message

getNumChannels

public int getNumChannels()
Description copied from interface: MultiConnectionSocket
Returns the number of channels.

Specified by:
getNumChannels in interface MultiConnectionSocket
Returns:
the num channels

setNumChannels

public void setNumChannels(int numChannels)
Sets the num channels.

Parameters:
numChannels - the new num channels

brought to you by Mr. Stampy