public abstract class ConnectionBase extends Object implements Connection, org.apache.mina.core.service.IoHandler, StatisticsProvider
Modifier and Type | Field and Description |
---|---|
protected Messenger |
messenger |
protected org.apache.mina.core.session.IoSession |
session |
protected StatisticsImpl |
statistics |
Constructor and Description |
---|
ConnectionBase(ConnectionInformation connectionInformation) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionStateListener(ConnectionStateListener connectionStateListener) |
void |
cancelConnection()
Cancel an open connection ...
|
void |
connect()
Start the connection
|
void |
connect(CallbackHandler callbackHandler)
Start the connection with a callback handler
|
protected void |
connectFailed(org.apache.mina.core.future.ConnectFuture future,
Throwable e)
called when a connection attempt failed
|
void |
disconnect()
request a disconnect
|
protected void |
disconnect(Throwable error)
request a disconnect
|
void |
dispose()
Dispose the connection
|
void |
exceptionCaught(org.apache.mina.core.session.IoSession session,
Throwable cause) |
protected void |
finalize() |
ConnectionInformation |
getConnectionInformation() |
int |
getConnectTimeout()
get the timeout used for connecting to the remote host
|
protected Integer |
getIntProperty(String propertyName,
Integer defaultValue) |
int |
getMessageTimeout() |
int |
getPingPeriod() |
Map<String,String> |
getSessionProperties()
Return the session properties as provided by the server.
|
Integer |
getSocketReceiveBufferSize() |
Integer |
getSocketSendBufferSize() |
ConnectionState |
getState()
Get the current connection state
|
Collection<StatisticEntry> |
getStatistics() |
boolean |
isConnected() |
void |
messageReceived(org.apache.mina.core.session.IoSession session,
Object message) |
void |
messageSent(org.apache.mina.core.session.IoSession session,
Object message) |
protected void |
onConnectionBound() |
protected void |
onConnectionClosed() |
protected void |
onConnectionEstablished() |
protected void |
performConnect() |
protected void |
performLookup() |
void |
removeConnectionStateListener(ConnectionStateListener connectionStateListener) |
protected void |
resolvedRemoteAddress(SocketAddress address,
Throwable e) |
void |
sessionClosed(org.apache.mina.core.session.IoSession session) |
void |
sessionCreated(org.apache.mina.core.session.IoSession session) |
void |
sessionIdle(org.apache.mina.core.session.IoSession session,
org.apache.mina.core.session.IdleStatus status) |
void |
sessionOpened(org.apache.mina.core.session.IoSession session) |
void |
setBound(Properties properties)
Set the
ConnectionState.BOUND including the session properties |
void |
setCallbackFactory(CallbackFactory callbackFactory) |
protected void |
setupConnector(ConnectionInformation connectionInformation,
org.apache.mina.core.service.IoConnector connector) |
protected void |
switchState(ConnectionState state,
Throwable error,
Map<String,String> properties) |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPrivilegeListener, getPrivileges, removePrivilegeListener
protected volatile org.apache.mina.core.session.IoSession session
protected final Messenger messenger
protected final StatisticsImpl statistics
public ConnectionBase(ConnectionInformation connectionInformation)
public void setCallbackFactory(CallbackFactory callbackFactory)
setCallbackFactory
in interface Connection
protected void switchState(ConnectionState state, Throwable error, Map<String,String> properties)
public void disconnect()
disconnect
in interface Connection
protected void disconnect(Throwable error)
error
- optionally the error that caused the request to closepublic ConnectionInformation getConnectionInformation()
getConnectionInformation
in interface Connection
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
protected void setupConnector(ConnectionInformation connectionInformation, org.apache.mina.core.service.IoConnector connector)
public boolean isConnected()
public void connect(CallbackHandler callbackHandler)
Connection
connect
in interface Connection
public void connect()
Connection
connect
in interface Connection
protected void performLookup()
protected void resolvedRemoteAddress(SocketAddress address, Throwable e)
protected void performConnect()
protected void connectFailed(org.apache.mina.core.future.ConnectFuture future, Throwable e)
future
- e
- the errorpublic void cancelConnection()
protected void onConnectionClosed()
protected void onConnectionEstablished()
public void setBound(Properties properties)
ConnectionState.BOUND
including the session propertiesproperties
- protected void onConnectionBound()
public void exceptionCaught(org.apache.mina.core.session.IoSession session, Throwable cause) throws Exception
exceptionCaught
in interface org.apache.mina.core.service.IoHandler
Exception
public void messageReceived(org.apache.mina.core.session.IoSession session, Object message) throws Exception
messageReceived
in interface org.apache.mina.core.service.IoHandler
Exception
public void messageSent(org.apache.mina.core.session.IoSession session, Object message) throws Exception
messageSent
in interface org.apache.mina.core.service.IoHandler
Exception
public void sessionClosed(org.apache.mina.core.session.IoSession session) throws Exception
sessionClosed
in interface org.apache.mina.core.service.IoHandler
Exception
public void sessionCreated(org.apache.mina.core.session.IoSession session) throws Exception
sessionCreated
in interface org.apache.mina.core.service.IoHandler
Exception
public void sessionIdle(org.apache.mina.core.session.IoSession session, org.apache.mina.core.session.IdleStatus status) throws Exception
sessionIdle
in interface org.apache.mina.core.service.IoHandler
Exception
public void sessionOpened(org.apache.mina.core.session.IoSession session) throws Exception
sessionOpened
in interface org.apache.mina.core.service.IoHandler
Exception
public int getConnectTimeout()
public int getPingPeriod()
public Integer getSocketReceiveBufferSize()
public Integer getSocketSendBufferSize()
public int getMessageTimeout()
protected void finalize() throws Throwable
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
public Map<String,String> getSessionProperties()
Connection
ConnectionState.BOUND
getSessionProperties
in interface Connection
public Collection<StatisticEntry> getStatistics()
getStatistics
in interface StatisticsProvider