com.hazelcast.client.connection.nio
Class ClientConnection

java.lang.Object
  extended by com.hazelcast.client.connection.nio.ClientConnection
All Implemented Interfaces:
Connection, Closeable

public class ClientConnection
extends Object
implements Connection, Closeable


Constructor Summary
ClientConnection(ClientConnectionManager connectionManager, IOSelector in, IOSelector out, int connectionId, SocketChannelWrapper socketChannelWrapper, ClientExecutionService executionService, ClientInvocationServiceImpl invocationService, SerializationService serializationService)
           
 
Method Summary
 void close()
          Closes this connection.
 void close(Throwable t)
           
 void decrementPacketCount()
           
 ClientCallFuture deRegisterCallId(int callId)
           
 ClientCallFuture deRegisterEventHandler(int callId)
           
 boolean equals(Object o)
           
 ClientConnectionManager getConnectionManager()
           
 Address getEndPoint()
          Gets the Address of the other side of this Connection.
 EventHandler getEventHandler(int callId)
           
 InetAddress getInetAddress()
          Returns remote address of this Connection.
 InetSocketAddress getLocalSocketAddress()
           
 int getPort()
          The remote port.
 ClientReadHandler getReadHandler()
           
 Address getRemoteEndpoint()
           
 InetSocketAddress getRemoteSocketAddress()
          Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.
 SerializationService getSerializationService()
           
 SocketChannelWrapper getSocketChannelWrapper()
           
 ConnectionType getType()
          Returns the ConnectionType of this Connection.
 int hashCode()
           
 void incrementPacketCount()
           
 void init()
           
 boolean isAlive()
          Checks if the Connection is still alive.
 boolean isClient()
          Checks if it is a client connection.
 boolean isHeartBeating()
           
 long lastReadTime()
          Returns the clock time of the most recent read using this connection.
 long lastWriteTime()
          Returns the clock time of the most recent write using this connection.
 Data read()
           
 void registerCallId(ClientCallFuture future)
           
 void setRemoteEndpoint(Address remoteEndpoint)
           
 String toString()
           
 void write(Data data)
           
 boolean write(SocketWritable packet)
          Writes a SocketWritable packet to the other side.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClientConnection

public ClientConnection(ClientConnectionManager connectionManager,
                        IOSelector in,
                        IOSelector out,
                        int connectionId,
                        SocketChannelWrapper socketChannelWrapper,
                        ClientExecutionService executionService,
                        ClientInvocationServiceImpl invocationService,
                        SerializationService serializationService)
                 throws IOException
Throws:
IOException
Method Detail

incrementPacketCount

public void incrementPacketCount()

decrementPacketCount

public void decrementPacketCount()

registerCallId

public void registerCallId(ClientCallFuture future)

deRegisterCallId

public ClientCallFuture deRegisterCallId(int callId)

deRegisterEventHandler

public ClientCallFuture deRegisterEventHandler(int callId)

getEventHandler

public EventHandler getEventHandler(int callId)

getSerializationService

public SerializationService getSerializationService()

write

public boolean write(SocketWritable packet)
Description copied from interface: Connection
Writes a SocketWritable packet to the other side.

The packet could be stored in an internal queue before it actually is written, so this call doesn't need to be a synchronous call.

Specified by:
write in interface Connection
Parameters:
packet - the packet to write.
Returns:
false if the packet was not accepted to be written, e.g. because the Connection was not alive.

init

public void init()
          throws IOException
Throws:
IOException

write

public void write(Data data)
           throws IOException
Throws:
IOException

read

public Data read()
          throws IOException
Throws:
IOException

getEndPoint

public Address getEndPoint()
Description copied from interface: Connection
Gets the Address of the other side of this Connection.

todo: rename to get remoteAddress?

Specified by:
getEndPoint in interface Connection
Returns:
the Address.

isAlive

public boolean isAlive()
Description copied from interface: Connection
Checks if the Connection is still alive.

Specified by:
isAlive in interface Connection
Returns:
true if alive, false otherwise.

lastReadTime

public long lastReadTime()
Description copied from interface: Connection
Returns the clock time of the most recent read using this connection.

Specified by:
lastReadTime in interface Connection
Returns:
the clock time of the most recent read

lastWriteTime

public long lastWriteTime()
Description copied from interface: Connection
Returns the clock time of the most recent write using this connection.

Specified by:
lastWriteTime in interface Connection
Returns:
the clock time of the most recent write.

close

public void close()
Description copied from interface: Connection
Closes this connection.

todo: what happens with all pending SocketWritables? Are they flushed, discarded or undefined behavior?

If the Connection already is closed, the call is ignored. So it can safely be called multiple times.

Specified by:
close in interface Connection
Specified by:
close in interface Closeable

getType

public ConnectionType getType()
Description copied from interface: Connection
Returns the ConnectionType of this Connection.

Specified by:
getType in interface Connection
Returns:
the ConnectionType. It could be that null is returned.

isClient

public boolean isClient()
Description copied from interface: Connection
Checks if it is a client connection.

Specified by:
isClient in interface Connection
Returns:
true if client connection, false otherwise.

getInetAddress

public InetAddress getInetAddress()
Description copied from interface: Connection
Returns remote address of this Connection.

Specified by:
getInetAddress in interface Connection
Returns:
the remote address. The returned value could be null if the connection is not alive.

getRemoteSocketAddress

public InetSocketAddress getRemoteSocketAddress()
Description copied from interface: Connection
Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.

Specified by:
getRemoteSocketAddress in interface Connection
Returns:
address of the endpoint.

todo: do we really need this method because we have getInetAddress, InetSocketAddress and getEndPoint.


getPort

public int getPort()
Description copied from interface: Connection
The remote port.

todo: rename to getRemotePort? And do we need it because we already have getEndPoint which returns an address which includes port. It is only used in testing

Specified by:
getPort in interface Connection
Returns:
the remote port number to which this Connection is connected, or 0 if the socket is not connected yet.

getSocketChannelWrapper

public SocketChannelWrapper getSocketChannelWrapper()

getConnectionManager

public ClientConnectionManager getConnectionManager()

getReadHandler

public ClientReadHandler getReadHandler()

setRemoteEndpoint

public void setRemoteEndpoint(Address remoteEndpoint)

getRemoteEndpoint

public Address getRemoteEndpoint()

getLocalSocketAddress

public InetSocketAddress getLocalSocketAddress()

close

public void close(Throwable t)

isHeartBeating

public boolean isHeartBeating()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.