com.kuka.comm
Class AbstractConnection

java.lang.Object
  extended by com.kuka.comm.AbstractConnection
All Implemented Interfaces:
Connection
Direct Known Subclasses:
NetConnection

public abstract class AbstractConnection
extends Object
implements Connection

An abstract implementation for the connection interface. To be derived by more specific connections.

Its generic type defines the in- and output type for en- and decoder. This generic type has to be replaced by a concrete type in the subclass.

Manages a map which contains message classes as keys and possible handler for these classes as values. Handlers are grouped into a collection.


Constructor Summary
AbstractConnection()
           
 
Method Summary
 void addConnectionListener(ConnectionListener listener)
          Adds a new ConnectionListener to the internal list notification subscribers.
<M> void
addMessageHandler(Class<M> messageClass, MessageHandler<M> handler)
          Generic method to append a MessageHandler for a message type to the internal list of message handlers.
 boolean awaitIsConnected(boolean expectedValue, long timeoutInMs)
          This method will block until {Connection.isConnected() returns the expected value or the timeout (in milliseconds) as been reached.
 void disconnect()
          Disconnects (or closes) the connection asynchronously.
protected  int dispatchMessages(List<Object> messages)
          Dispatches a list of message objects to another thread to reduce message handling time.
protected  void fireConnectionClosed()
          Callback called upon closing the connection.
protected  void fireConnectionFailed(Exception reason)
          Callback called upon failed connection establishment.
protected  void fireConnectionSuccessful()
          Callback called upon successful connection establishment.
protected  void fireConnectionTimedOut()
          Callback called upon failed connection establishment.
protected  void fireReceiveError(Exception reason)
          Callback called upon receive errors.
 ReconnectStrategy getAutoReconnectStrategy()
          Returns the currently set auto reconnection strategy.
 boolean isAbleToReceive()
          Returns true if the current state of the connection allows to receive messages.
 boolean isAbleToSend()
          Returns true if the current state of the connection allows to send messages.
 void removeConnectionListener(ConnectionListener listener)
          Removes a given listener from list of ConnectionListener.
<M> void
removeMessageHandler(Class<M> messageClass, MessageHandler<M> handler)
          Generic method to remove a message handler from internal list of message handlers.
 void setAutoReconnectStrategy(ReconnectStrategy strategy)
          Sets the auto reconnection strategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.kuka.comm.Connection
connect, getStatistics, hasDecoder, hasEncoder, isConnected, isConnectionless, send
 

Constructor Detail

AbstractConnection

public AbstractConnection()
Method Detail

awaitIsConnected

public final boolean awaitIsConnected(boolean expectedValue,
                                      long timeoutInMs)
Description copied from interface: Connection
This method will block until {Connection.isConnected() returns the expected value or the timeout (in milliseconds) as been reached.

Specified by:
awaitIsConnected in interface Connection
Parameters:
expectedValue - the expected value to wait for (true or false)
timeoutInMs - the maximum time (in milliseconds) to wait for the expected value
Returns:
True, if the connection is at the expected state within the timeout.

dispatchMessages

protected final int dispatchMessages(List<Object> messages)
Dispatches a list of message objects to another thread to reduce message handling time. The messages will be handled by the independent MessageDispatcher thread.

Parameters:
messages - List of Objects to be handled.
Returns:
the number of lost messages that could not be dispatched

disconnect

public void disconnect()
Description copied from interface: Connection
Disconnects (or closes) the connection asynchronously. The success of this method can be checked by calling Connection.isConnected(). A disconnected connection cannot be used for sending and will not receive any messages. A disconnected connection can be reconnected by calling Connection.connect().

Specified by:
disconnect in interface Connection

addMessageHandler

public final <M> void addMessageHandler(Class<M> messageClass,
                                        MessageHandler<M> handler)
Description copied from interface: Connection
Generic method to append a MessageHandler for a message type to the internal list of message handlers. Its type parameter M is used to store different message classes and associated handlers.

Specified by:
addMessageHandler in interface Connection
Type Parameters:
M - the type of the message
Parameters:
messageClass - Defines the type of message for this handler so that the connection is able to choose the right handler for an incoming message
handler - The message handler to handle an incoming message.

removeMessageHandler

public final <M> void removeMessageHandler(Class<M> messageClass,
                                           MessageHandler<M> handler)
Description copied from interface: Connection
Generic method to remove a message handler from internal list of message handlers. If a message handler doesn't exist this method does nothing.

Specified by:
removeMessageHandler in interface Connection
Type Parameters:
M - the type of the message
Parameters:
messageClass - Defines the type of message for the associated handler
handler - message handler that handles incoming messages.

addConnectionListener

public final void addConnectionListener(ConnectionListener listener)
Description copied from interface: Connection
Adds a new ConnectionListener to the internal list notification subscribers.

An added listener will be notified if a connection event, like e.g. successful or failed establishment of connection, will occur.

Specified by:
addConnectionListener in interface Connection
Parameters:
listener - The ConnectionListener to add to listener list.

removeConnectionListener

public final void removeConnectionListener(ConnectionListener listener)
Description copied from interface: Connection
Removes a given listener from list of ConnectionListener. If there is no such listener in internal list nothing would be removed.

Specified by:
removeConnectionListener in interface Connection
Parameters:
listener - The ConnectionListener to remove.

isAbleToSend

public boolean isAbleToSend()
Description copied from interface: Connection
Returns true if the current state of the connection allows to send messages. For this, the connection at least must be connected (see also Connection.isConnected()) and an Encoder must have been set in the concrete class implementing the Connection interface. The method Connection.hasEncoder() can be used to check if an Encoder has been set.

Specified by:
isAbleToSend in interface Connection
Returns:
True, if the connection can be used to send messages.

isAbleToReceive

public boolean isAbleToReceive()
Description copied from interface: Connection
Returns true if the current state of the connection allows to receive messages. For this, the connection at least must be connected (see also Connection.isConnected()) and an encoder must have been set. The method Connection.hasDecoder() can be used to check if a Decoder has been set.

Specified by:
isAbleToReceive in interface Connection
Returns:
true, if the connection can be used to receive messages

fireConnectionSuccessful

protected final void fireConnectionSuccessful()
Callback called upon successful connection establishment.


fireConnectionFailed

protected final void fireConnectionFailed(Exception reason)
Callback called upon failed connection establishment.

Parameters:
reason - the reason of the connection failure

fireConnectionTimedOut

protected final void fireConnectionTimedOut()
Callback called upon failed connection establishment.

Parameters:
reason - the reason of the connection failure

fireConnectionClosed

protected final void fireConnectionClosed()
Callback called upon closing the connection.


fireReceiveError

protected final void fireReceiveError(Exception reason)
Callback called upon receive errors.

Parameters:
reason - the reason of the connection failure

setAutoReconnectStrategy

public final void setAutoReconnectStrategy(ReconnectStrategy strategy)
Description copied from interface: Connection
Sets the auto reconnection strategy.

Specified by:
setAutoReconnectStrategy in interface Connection
Parameters:
strategy - the strategy implementing the ReconnectStrategy

getAutoReconnectStrategy

public final ReconnectStrategy getAutoReconnectStrategy()
Description copied from interface: Connection
Returns the currently set auto reconnection strategy.

Specified by:
getAutoReconnectStrategy in interface Connection
Returns:
The currently set auto reconnection strategy.


Copyright © 2019. All rights reserved.