Connection

<p> A handle which represents connection between two end-points regardless of transport types. </p> <p> {@link Connection} provides user-defined attributes. User-defined attributes are application-specific data which are associated with a connection. It often contains objects that represents the state of a higher-level protocol and becomes a way to exchange data between filters and handlers. </p> <h3>Adjusting Transport Type Specific Properties</h3> <p> You can simply downcast the connection to an appropriate subclass. </p> <h3>Thread Safety</h3> <p> {@link Connection} is thread-safe. But please note that performing more than one {@link #write(Object)} calls at the same time will cause the {@link IoFilter#filterWrite(IoFilter.NextFilter,Connection,WriteRequest)} to be executed simultaneously, and therefore you have to make sure the {@link IoFilter} implementations you're using are thread-safe, too. </p> <h3>Equality of Connections</h3> TODO : The getId() method is totally wrong. We can't base a method which is designed to create a unique ID on the hashCode method. {@link Object#equals(Object)} and {@link Object#hashCode()} shall not be overriden to the default behavior that is defined in {@link Object}.

@author <a href="http://mina.apache.org">Apache MINA Project</a>

interface Connection : Closeable {}

Members

Functions

close
void close()
Undocumented in source.
containsAttribute
bool containsAttribute(string key)

@param key The key of the attribute we are looking for in the connection @return <tt>true</tt> if this connection contains the attribute with the specified <tt>key</tt>.

encode
void encode(Object message)
Undocumented in source.
getAttribute
Object getAttribute(string key)

Returns the value of the user-defined attribute of this connection.

getAttribute
Object getAttribute(string key, Object defaultValue)

Returns the value of user defined attribute associated with the specified key. If there's no such attribute, the specified default value is associated with the specified key, and the default value is returned. This method is same with the following code except that the operation is performed atomically. <pre> if (containsAttribute(key)) { return getAttribute(key); } else { setAttribute(key, defaultValue); return defaultValue; } </pre>

getAttributeKeys
string[] getAttributeKeys()

@return the set of keys of all user-defined attributes.

getCloseTime
long getCloseTime()
Undocumented in source.
getDuration
long getDuration()
Undocumented in source.
getHandler
NetConnectionHandler getHandler()

@return the EventHandler which handles this connection.

getId
int getId()
Undocumented in source.
getIdleTimeout
long getIdleTimeout()
Undocumented in source.
getLastActiveTime
long getLastActiveTime()
Undocumented in source.
getLastReadTime
long getLastReadTime()
Undocumented in source.
getLastWrittenTime
long getLastWrittenTime()
Undocumented in source.
getLocalAddress
Address getLocalAddress()
Undocumented in source.
getMaxIdleTimeout
Duration getMaxIdleTimeout()
Undocumented in source.
getOpenTime
long getOpenTime()
Undocumented in source.
getReadBytes
size_t getReadBytes()
Undocumented in source.
getRemoteAddress
Address getRemoteAddress()
Undocumented in source.
getState
ConnectionState getState()
Undocumented in source.
getStream
TcpStream getStream()
Undocumented in source.
getWrittenBytes
size_t getWrittenBytes()
Undocumented in source.
isActive
bool isActive()

@return <tt>true</tt> if this connection is active.

isClosing
bool isClosing()

@return <tt>true</tt> if and only if this connection is being closed (but not disconnected yet) or is closed.

isConnected
bool isConnected()

@return <tt>true</tt> if this connection is connected with remote peer.

isSecured
bool isSecured()

@return <tt>true</tt> if the connection has started and initialized a SslEngine, <tt>false</tt> if the connection is not yet secured (the handshake is not completed) or if SSL is not set for this connection, or if SSL is not even an option.

isShutdownInput
bool isShutdownInput()
Undocumented in source.
isShutdownOutput
bool isShutdownOutput()
Undocumented in source.
isWaitingForClose
bool isWaitingForClose()
Undocumented in source.
removeAttribute
Object removeAttribute(string key)

Removes a user-defined attribute with the specified key.

removeAttribute
bool removeAttribute(string key, Object value)

Removes a user defined attribute with the specified key if the current attribute value is equal to the specified value. This method is same with the following code except that the operation is performed atomically. <pre> if (containsAttribute(key) &amp;&amp; getAttribute(key).equals(value)) { removeAttribute(key); return true; } else { return false; } </pre>

replaceAttribute
bool replaceAttribute(string key, Object oldValue, Object newValue)

Replaces a user defined attribute with the specified key if the value of the attribute is equals to the specified old value. This method is same with the following code except that the operation is performed atomically. <pre> if (containsAttribute(key) &amp;&amp; getAttribute(key).equals(oldValue)) { setAttribute(key, newValue); return true; } else { return false; } </pre>

setAttribute
Object setAttribute(string key, Object value)

Sets a user-defined attribute.

setAttribute
Object setAttribute(string key)

Sets a user defined attribute without a value. This is useful when you just want to put a 'mark' attribute. Its value is set to {@link bool#TRUE}.

setAttributeIfAbsent
Object setAttributeIfAbsent(string key, Object value)

Sets a user defined attribute if the attribute with the specified key is not set yet. This method is same with the following code except that the operation is performed atomically. <pre> if (containsAttribute(key)) { return getAttribute(key); } else { return setAttribute(key, value); } </pre>

setAttributeIfAbsent
Object setAttributeIfAbsent(string key)

Sets a user defined attribute without a value if the attribute with the specified key is not set yet. This is useful when you just want to put a 'mark' attribute. Its value is set to {@link bool#TRUE}. This method is same with the following code except that the operation is performed atomically. <pre> if (containsAttribute(key)) { return getAttribute(key); // might not always be bool.TRUE. } else { return setAttribute(key); } </pre>

setState
void setState(ConnectionState state)
Undocumented in source.
shutdownInput
void shutdownInput()
Undocumented in source.
shutdownOutput
void shutdownOutput()
Undocumented in source.
toString
string toString()
Undocumented in source.
write
void write(Object message)

Writes the specified <code>message</code> to remote peer. This operation is asynchronous; {@link IoHandler#messageSent(Connection,Object)} will be invoked when the message is actually sent to remote peer. You can also wait for the returned {@link WriteFuture} if you want to wait for the message actually written.

write
void write(const(ubyte)[] data)
Undocumented in source.
write
void write(string str)
Undocumented in source.
write
void write(ByteBuffer buffer)
Undocumented in source.
write
void write(ByteBuffer byteBuffer, Callback callback)
Undocumented in source.

Meta