Class Connection
java.lang.Object
com.codingchili.core.listener.transport.Connection
- All Implemented Interfaces:
Messageable
Represents the stateful connection over which requests may be passed.
For stateless requests such as ClusterRequest and RestRequest the
client may only live during a single request.
-
Constructor Summary
ConstructorDescriptionConnection(Consumer<Object> writer, String id)
Creates a new stateful connection that properly implements the ID method. -
Method Summary
Modifier and TypeMethodDescriptiongetProperty(String key)
Retrieves a value from the connection properties.id()
onCloseHandler(Runnable runnable)
Creates a unnamed close handler that cannot be removed.onCloseHandler(String name, Runnable closeHandler)
Adds a listener for the close event.remote()
A textual representation of the sending party.removeCloseHandler(String name)
void
executes the close handlers registered on the connection.setProperty(String key, String value)
Sets a property that will exist for the connections duration.void
Writes an object to the connection that backs the current request.
-
Constructor Details
-
Connection
Creates a new stateful connection that properly implements the ID method.- Parameters:
writer
- a method that writes outbound messages to the remote peer.id
- the unique id of this connection.
-
-
Method Details
-
write
Description copied from interface:Messageable
Writes an object to the connection that backs the current request.- Specified by:
write
in interfaceMessageable
- Parameters:
object
- the object to be written.
-
id
- Returns:
- the unique identifier of this connection.
-
remote
A textual representation of the sending party. This is typically the IP address retrieved from the underlying connection.- Returns:
- the sending party represented as a string.
-
onCloseHandler
Creates a unnamed close handler that cannot be removed.- Parameters:
runnable
- called after the connection is closed.- Returns:
- fluent.
-
onCloseHandler
Adds a listener for the close event.- Parameters:
name
- the name of the close handler so that it can be removed or updated.closeHandler
- called after the connection is closed.- Returns:
- fluent.
-
removeCloseHandler
- Parameters:
name
- the name of the close handler to remove.- Returns:
- fluent.
-
runCloseHandlers
public void runCloseHandlers()executes the close handlers registered on the connection. Does not actually close the connection itself. This method is primarily intended to be called by the listener which created the connection. -
getProperty
Retrieves a value from the connection properties.- Parameters:
key
- the property to retrieve.- Returns:
- an optional of the property value.
-
setProperty
Sets a property that will exist for the connections duration.- Parameters:
key
- the key of the property to set.value
- the value of the property to set.- Returns:
- fluent.
-