public abstract class ClientBaseConnection extends BaseConnection implements Connection
Modifier and Type | Field and Description |
---|---|
protected CallbackFactory |
callbackFactory |
protected CallbackHandler |
connectCallbackHandler |
connectionInformation, executor, statistics
Constructor and Description |
---|
ClientBaseConnection(IoHandlerFactory handlerFactory,
IoLoggerFilterChainBuilder chainBuilder,
ConnectionInformation connectionInformation) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionStateListener(ConnectionStateListener connectionStateListener) |
void |
addPrivilegeListener(PrivilegeListener listener)
Add a listener to the privileges of the session
|
void |
connect()
Start the connection
|
void |
connect(CallbackHandler callbackHandler)
Start the connection with a callback handler
|
void |
disconnect()
Stop the connection
|
void |
dispose()
Dispose the connection
|
protected void |
firePrivilegeChange(Set<String> granted) |
Set<String> |
getPrivileges()
Return the list of currently granted privileges.
|
protected IoSession |
getSession() |
SSLSession |
getSslSession() |
ConnectionState |
getState()
Get the current connection state
|
protected void |
handleConnectComplete(ConnectFuture future) |
protected abstract void |
handleMessage(Object message)
Handle a message that came in by the current session.
|
boolean |
isDisposed() |
void |
messageReceived(IoSession session,
Object message) |
protected void |
onConnectionBound()
Called when the connection got bound
|
protected void |
onConnectionClosed()
Called when the connection got closed
|
protected void |
onConnectionConnected()
Called when the connection got connected
|
protected void |
performClosed(IoSession session,
Throwable error) |
protected void |
performDisconnected(Throwable error) |
void |
performOpened(IoSession session) |
void |
removeConnectionStateListener(ConnectionStateListener connectionStateListener) |
void |
removePrivilegeListener(PrivilegeListener listener) |
protected void |
sendMessage(Object message) |
protected void |
sendMessageChecked(Object message)
Send a message if a connection exists
|
void |
setCallbackFactory(CallbackFactory callbackFactory) |
protected void |
setState(ConnectionState connectionState,
Throwable error) |
protected void |
switchState(ConnectionState state,
Throwable error) |
getConnectionInformation, getSessionProperties, getStatistics, setSessionProperties
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConnectionInformation, getSessionProperties
protected volatile CallbackHandler connectCallbackHandler
protected CallbackFactory callbackFactory
public ClientBaseConnection(IoHandlerFactory handlerFactory, IoLoggerFilterChainBuilder chainBuilder, ConnectionInformation connectionInformation) throws Exception
Exception
public void setCallbackFactory(CallbackFactory callbackFactory)
setCallbackFactory
in interface Connection
public void connect()
Connection
connect
in interface Connection
public void connect(CallbackHandler callbackHandler)
Connection
connect
in interface Connection
public void disconnect()
Connection
disconnect
in interface Connection
protected void switchState(ConnectionState state, Throwable error)
protected void onConnectionBound()
This method is called while the connection lock is held.
The default implementation does nothing.
protected void onConnectionConnected()
This method is called while the connection lock is held.
The default implementation switches directly to
ConnectionState.BOUND
protected void onConnectionClosed()
This method is called while the connection lock is held.
The default implementation does nothing.
protected void performDisconnected(Throwable error)
protected void handleConnectComplete(ConnectFuture future)
public boolean isDisposed()
public void dispose()
Connection
A dispose will also act as a disconnect.
Connections must be disposed in order to clean up all resources. In the
past the Connection.disconnect()
call was enough and, if possible, most
resources (sockets) should be closed when disconnecting. Still some
resources can be re-used and these need to be cleaned up in the
Connection.dispose()
call.
dispose
in interface Connection
dispose
in class BaseConnection
protected void setState(ConnectionState connectionState, Throwable error)
public void addConnectionStateListener(ConnectionStateListener connectionStateListener)
addConnectionStateListener
in interface Connection
public void removeConnectionStateListener(ConnectionStateListener connectionStateListener)
removeConnectionStateListener
in interface Connection
public ConnectionState getState()
Connection
getState
in interface Connection
public void performOpened(IoSession session)
protected abstract void handleMessage(Object message)
Note that the method is called while holding the lock the connection itself.
message
- the received messageprotected void sendMessageChecked(Object message) throws NoConnectionException
Works like sendMessage(Object)
, but the connection is not
established it will throw an exception instead of silently ignoring the
fact.
message
- the message to sendNoConnectionException
- thrown in case no connection currently existsprotected void sendMessage(Object message)
public SSLSession getSslSession()
public void addPrivilegeListener(PrivilegeListener listener)
Connection
When adding a new listener it will receive an initial call with the current privileges.
addPrivilegeListener
in interface Connection
public void removePrivilegeListener(PrivilegeListener listener)
removePrivilegeListener
in interface Connection
public Set<String> getPrivileges()
Connection
getPrivileges
in interface Connection
null
.protected IoSession getSession()