com.kuka.comm.net
Class NetConnection

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

public abstract class NetConnection
extends AbstractConnection

Abstract subclass which names the generic type for an AbstractConnection regarding to network specific use of ByteBuffer.


Field Summary
protected  byte[] _inputBuffer
          A buffer that can be used to store bytes from an input stream of the connection.
protected  InetSocketAddress _localAddress
          The local connection address.
protected  byte[] _outputBuffer
          A buffer that can be used to store bytes for an output stream of the connection.
protected  InetSocketAddress _remoteAddress
          The remote connection address.
 
Constructor Summary
NetConnection()
           
 
Method Summary
 Decoder<ByteBuffer,Object> getDecoder()
           
 Encoder<Object,ByteBuffer> getEncoder()
          Getter for Encoder.
 InetSocketAddress getLocalAddress()
           
 InetSocketAddress getRemoteAddress()
           
abstract  NetConnectionStatistics getStatistics()
          Returns general connection statistics about this connection.
 boolean hasDecoder()
          Returns true if a valid decoder has been set for this connection.
 boolean hasEncoder()
          Returns true if a valid encoder has been set for this connection.
 NetConnection setDecoder(Decoder<ByteBuffer,Object> decoder)
          Sets the decoder that should be used by this connection to decoder incoming messages.
 NetConnection setEncoder(Encoder<Object,ByteBuffer> encoder)
          Sets the encoder that should be used by this connection to encode outgoing messages.
 NetConnection setInputBufferSize(int size)
          Builder option to adjust the buffer size of output buffer.
 NetConnection setOutputBufferSize(int size)
          Builder option to adjust the buffer size of output buffer.
 
Methods inherited from class com.kuka.comm.AbstractConnection
addConnectionListener, addMessageHandler, awaitIsConnected, disconnect, dispatchMessages, fireConnectionClosed, fireConnectionFailed, fireConnectionSuccessful, fireConnectionTimedOut, fireReceiveError, getAutoReconnectStrategy, isAbleToReceive, isAbleToSend, removeConnectionListener, removeMessageHandler, setAutoReconnectStrategy
 
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, isConnected, isConnectionless, send
 

Field Detail

_inputBuffer

protected byte[] _inputBuffer
A buffer that can be used to store bytes from an input stream of the connection.


_outputBuffer

protected byte[] _outputBuffer
A buffer that can be used to store bytes for an output stream of the connection.


_localAddress

protected InetSocketAddress _localAddress
The local connection address.


_remoteAddress

protected InetSocketAddress _remoteAddress
The remote connection address.

Constructor Detail

NetConnection

public NetConnection()
Method Detail

getLocalAddress

public InetSocketAddress getLocalAddress()
Returns:
InetSocketAddress of local connection endpoint

getRemoteAddress

public InetSocketAddress getRemoteAddress()
Returns:
InetSocketAddress of remote connection endpoint

setEncoder

public final NetConnection setEncoder(Encoder<Object,ByteBuffer> encoder)
Sets the encoder that should be used by this connection to encode outgoing messages.

Parameters:
encoder - the encoder for outgoing messages
Returns:
this connection (fluent interface)

setDecoder

public final NetConnection setDecoder(Decoder<ByteBuffer,Object> decoder)
Sets the decoder that should be used by this connection to decoder incoming messages.

Parameters:
decoder - the decoder for incoming messages
Returns:
this connection (fluent interface)

getEncoder

public final Encoder<Object,ByteBuffer> getEncoder()
Getter for Encoder.

Returns:
The Encoder.

getDecoder

public final Decoder<ByteBuffer,Object> getDecoder()
Returns:
The Decoder.

hasEncoder

public final boolean hasEncoder()
Description copied from interface: Connection
Returns true if a valid encoder has been set for this connection.

Returns:
true if connection has an encoder, false otherwise.

hasDecoder

public final boolean hasDecoder()
Description copied from interface: Connection
Returns true if a valid decoder has been set for this connection.

Returns:
true if connection has a decoder, false otherwise.

setInputBufferSize

public final NetConnection setInputBufferSize(int size)
Builder option to adjust the buffer size of output buffer. The bufferSize won't be smaller than 512 Bytes to avoid the lack of buffer for incoming data. The size should be the same as the one of the receiving endpoint at the opposite end of this connection. Otherwise TCP negotiates the smallest value for both sides.

There is no upper limit to ensure an optimal network bandwidth use. This optimal bufferSize has to be calculated by the application which uses this framework. A common formula is RoundTripTime * bandwidth. To retrieve these values use to ConnectionStatsProvider.

Parameters:
size - An integer stating the new size for the buffer.
Returns:
This TcpConnection. Necessary to use builder-Pattern.

setOutputBufferSize

public final NetConnection setOutputBufferSize(int size)
Builder option to adjust the buffer size of output buffer. The bufferSize won't be smaller than 512 Bytes to avoid the lack of buffer for incoming data. The size should be the same as the one of the sending endpoint at the opposite end of this connection. Otherwise TCP negotiates the smallest value for both sides.

There is no upper limit to ensure an optimal network bandwidth use. This optimal bufferSize has to be calculated by the application which uses this framework. A common formula is RoundTripTime * bandwidth. To retrieve these values use to ConnectionStatsProvider.

Parameters:
size - An integer stating the new size for the buffer.
Returns:
The TcpConnection of this call. Necessary to use builder-Pattern.

getStatistics

public abstract NetConnectionStatistics getStatistics()
Description copied from interface: Connection
Returns general connection statistics about this connection.

Returns:
general connection statistics about this connection


Copyright © 2019. All rights reserved.