public class ConnectionBuilder<T extends ExecutionContext>
extends java.lang.Object
Constructor and Description |
---|
ConnectionBuilder() |
Modifier and Type | Method and Description |
---|---|
Connection<T> |
build(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Build a Connection using the given input and output streams.
|
Connection<T> |
build(MessageReader reader,
MessageWriter writer)
Build a Connection using the given
MessageReader and MessageWriter . |
Connection<T> |
build(java.net.Socket socket)
Build a Connection using the given Socket.
|
ConnectionBuilder<T> |
withContextualTasks(java.util.function.Consumer<T>... tasks)
Build a connection that includes the given contextual task to be executed synchronously with message execution.
|
ConnectionBuilder<T> |
withErrorCallback(java.util.function.BiConsumer<Connection<T>,java.lang.Throwable> callback)
Build a connection with the given error callback function.
|
ConnectionBuilder<T> |
withExecutionContextFactory(ExecutionContextFactory<T> context)
Build a connection with the given ExecutionContext.
|
ConnectionBuilder<T> |
withMessageIOFactory(MessageIOFactory factory)
Use the given MessageIOFactory to create MessageReader and MessageWriter instances from Java Input and Output
streams.
|
ConnectionBuilder<T> |
withMessageReaderFactory(MessageReaderFactory factory)
Use the specified MessageReaderFactory to build a MessageReader from any InputStreams.
|
ConnectionBuilder<T> |
withMessageWriterFactory(MessageWriterFactory factory)
Use the specified MessageWriterFactory to build a MessageWriter from any OutputStreams.
|
ConnectionBuilder<T> |
withRecurringTaskFactories(RecurringTaskFactory<T>... factories)
Specify factories which generate recurring tasks.
|
ConnectionBuilder<T> |
withRecurringTasks(RecurringTask<T>... tasks)
Build a connection that include the given recurring tasks; these tasks are executed synchronously with message
execution, and at regular (although undefined) intervals.
|
ConnectionBuilder<T> |
withShutdownCallbacks(java.util.function.Consumer<Connection<T>>... callbacks)
Build a connection that includes the given contextual task to be executed synchronously with message execution.
|
public Connection<T> build(java.net.Socket socket) throws java.io.IOException
socket
- The Socket that will back the given Connection.java.io.IOException
- If there is an error retrieving input and output streams from the Socket.public Connection<T> build(java.io.InputStream inputStream, java.io.OutputStream outputStream)
inputStream
- The InputStream
used to read messages.outputStream
- The OutputStream
used to write messages.public Connection<T> build(MessageReader reader, MessageWriter writer)
MessageReader
and MessageWriter
.reader
- The MessageReader
used to read messages.writer
- The MessageWriter
used to write messages.public ConnectionBuilder<T> withMessageIOFactory(MessageIOFactory factory)
factory
- The MessageIOFactory.public ConnectionBuilder<T> withMessageReaderFactory(MessageReaderFactory factory)
factory
- The MessageReaderFactory.public ConnectionBuilder<T> withMessageWriterFactory(MessageWriterFactory factory)
factory
- The MessageWriterFactory.public ConnectionBuilder<T> withErrorCallback(java.util.function.BiConsumer<Connection<T>,java.lang.Throwable> callback)
callback
- The Consumer (accepting a Connection and Throwable) that will be invoked when an error is
encountered.public ConnectionBuilder<T> withContextualTasks(java.util.function.Consumer<T>... tasks)
tasks
- The task(s) to be executed; Consumers accepting an ExecutionContext.public ConnectionBuilder<T> withRecurringTasks(RecurringTask<T>... tasks)
These tasks are likely to be executed very frequently (on the order of 100 times per second) so they should be kept as short as possible.
It also should be noted that there is no way to "cancel" one of these tasks.
tasks
- The tasks to be executed repeatedly.public ConnectionBuilder<T> withShutdownCallbacks(java.util.function.Consumer<Connection<T>>... callbacks)
callbacks
- The task(s) to be executed; Consumers accepting a Connection.public ConnectionBuilder<T> withExecutionContextFactory(ExecutionContextFactory<T> context)
context
- The context in which the Connection will execute messages.public ConnectionBuilder<T> withRecurringTaskFactories(RecurringTaskFactory<T>... factories)
factories
- The factories.