public class AxonServerConnectionManager extends Object
Channel
s per context and providing them as the means to dispatch/receive messages.Modifier and Type | Class and Description |
---|---|
static class |
AxonServerConnectionManager.Builder
Builder class to instantiate an
AxonServerConnectionManager . |
Modifier | Constructor and Description |
---|---|
|
AxonServerConnectionManager(AxonServerConfiguration axonServerConfiguration)
Deprecated.
in favor of using the
AxonServerConnectionManager.Builder (with the convenience builder() method)to instantiate
an Axon Server Connection Manager |
|
AxonServerConnectionManager(AxonServerConfiguration axonServerConfiguration,
TagsConfiguration tagsConfiguration)
Deprecated.
in favor of using the
AxonServerConnectionManager.Builder (with the convenience builder() method)to instantiate
an Axon Server Connection Manager |
protected |
AxonServerConnectionManager(AxonServerConnectionManager.Builder builder)
Instantiate a
AxonServerConnectionManager based on the fields contained in the AxonServerConnectionManager.Builder . |
Modifier and Type | Method and Description |
---|---|
void |
addDisconnectListener(Consumer<String> action)
Registers a disconnect listener which executes a given
action when a connection is disconnected. |
void |
addDisconnectListener(String context,
Runnable action)
Registers a disconnect listener which executes a given
action when the connection is disconnected for
given the context . |
void |
addReconnectInterceptor(Function<Consumer<String>,Consumer<String>> interceptor)
Registers an interceptor that may alter the behavior on an incoming "reconnect request" from the server.
|
void |
addReconnectListener(Consumer<String> action)
Registers a reconnect listener that executes given
action when a connection is re-established. |
void |
addReconnectListener(String context,
Runnable action)
Registers a reconnect listener for the given
context that executes given action when a
connection is re-established for the given context . |
static AxonServerConnectionManager.Builder |
builder()
Instantiate a Builder to be able to create an
AxonServerConnectionManager . |
void |
disconnect()
Disconnects any active connections, forcing a new connection to be established when one is requested.
|
void |
disconnect(String context)
Disconnects any active connection for the given
context , forcing a new connection to be established when
one is requested. |
void |
disconnectExceptionally(String context,
Throwable cause)
Forces a disconnection from AxonServer for the specified context.
|
io.grpc.Channel |
getChannel()
Returns a Channel for the default context, opening one if necessary.
|
io.grpc.Channel |
getChannel(String context)
Returns a Channel representing the connection for the given
context , opening one if necessary. |
io.grpc.stub.StreamObserver<CommandProviderOutbound> |
getCommandStream(String context,
io.grpc.stub.StreamObserver<CommandProviderInbound> inboundCommandStream)
Opens a Stream for incoming commands from AxonServer in the given
context . |
String |
getDefaultContext()
Returns the name of the default context of this application.
|
io.grpc.stub.StreamObserver<PlatformInboundInstruction> |
getPlatformStream(String context,
io.grpc.stub.StreamObserver<PlatformOutboundInstruction> outboundInstructionStream)
Opens a Stream for platform instructions in given
context . |
io.grpc.stub.StreamObserver<QueryProviderOutbound> |
getQueryStream(String context,
io.grpc.stub.StreamObserver<QueryProviderInbound> inboundQueryStream)
Opens a Stream for incoming queries from AxonServer in the given
context . |
boolean |
isConnected(String context)
Returns
true if a gRPC channel for the specific context is opened between client and AxonServer. |
void |
onOutboundInstruction(BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
Registers a handler to handle instructions from AxonServer.
|
void |
onOutboundInstruction(BiPredicate<String,PlatformOutboundInstruction.RequestCase> handlerSelector,
BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
Registers a handler to handle instructions from AxonServer.
|
void |
onOutboundInstruction(PlatformOutboundInstruction.RequestCase requestCase,
BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
Registers a handler to handle instructions from AxonServer.
|
void |
onOutboundInstruction(PlatformOutboundInstruction.RequestCase requestCase,
Consumer<PlatformOutboundInstruction> consumer)
Deprecated.
in favor of
onOutboundInstruction(String, PlatformOutboundInstruction.RequestCase, Consumer)
as the context should be specified on any outbound instruction |
void |
onOutboundInstruction(String context,
BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
Registers a handler to handle instructions from AxonServer.
|
void |
onOutboundInstruction(String context,
PlatformOutboundInstruction.RequestCase requestCase,
BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
Registers a handler to handle instructions from AxonServer.
|
void |
onOutboundInstruction(String context,
PlatformOutboundInstruction.RequestCase requestCase,
Consumer<PlatformOutboundInstruction> consumer)
Registers a handler to handle instructions from AxonServer.
|
void |
send(String context,
PlatformInboundInstruction instruction)
Send the given
instruction for given context to AxonServer. |
void |
shutdown()
Stops the Connection Manager, closing any active connections and preventing new connections from being created.
|
@Deprecated public AxonServerConnectionManager(AxonServerConfiguration axonServerConfiguration)
AxonServerConnectionManager.Builder
(with the convenience builder()
method)to instantiate
an Axon Server Connection ManagerTagsConfiguration
is used in this case.axonServerConfiguration
- the configuration of Axon Server used to correctly establish connections@Deprecated public AxonServerConnectionManager(AxonServerConfiguration axonServerConfiguration, TagsConfiguration tagsConfiguration)
AxonServerConnectionManager.Builder
(with the convenience builder()
method)to instantiate
an Axon Server Connection ManageraxonServerConfiguration
- the configuration of Axon Server used to correctly establish connectionstagsConfiguration
- the TagsConfiguration used to add the tags of this instance as client informationprotected AxonServerConnectionManager(AxonServerConnectionManager.Builder builder)
AxonServerConnectionManager
based on the fields contained in the AxonServerConnectionManager.Builder
.builder
- the AxonServerConnectionManager.Builder
used to instantiate a AxonServerConnectionManager
instancepublic static AxonServerConnectionManager.Builder builder()
AxonServerConnectionManager
.
The TagsConfiguration
is defaulted to TagsConfiguration.TagsConfiguration()
and the
ScheduledExecutorService
defaults to an instance using a single thread with an AxonThreadFactory
tied to it. The AxonServerConfiguration
is a hard requirements and as such should be provided.
AxonServerConnectionManager
public io.grpc.Channel getChannel()
public io.grpc.Channel getChannel(String context)
context
, opening one if necessary.context
- the context for which to open a connectioncontext
public void addReconnectListener(String context, Runnable action)
context
that executes given action
when a
connection is re-established for the given context
.context
- the context to register the reconnect listener foraction
- the action to perform when the connection for the given context
is re-establishedpublic void addReconnectListener(Consumer<String> action)
action
when a connection is re-established. The
parameter of the invoked action
is the name of the context for which the application was lost.action
- the action to perform when a connection is re-establishedpublic void addDisconnectListener(String context, Runnable action)
action
when the connection is disconnected for
given the context
.context
- the context to register the disconnect listener foraction
- the action to perform when the connection for the given context
is disconnectedpublic void addDisconnectListener(Consumer<String> action)
action
when a connection is disconnected. The
parameter of the invoked action
is the name of the context for which the connection was lost.action
- the action to perform when a connection is disconnectedpublic void addReconnectInterceptor(Function<Consumer<String>,Consumer<String>> interceptor)
The registered interceptor may deny these requests by blocking the call to the input Consumer.
interceptor
- a function altering the original reconnect requestpublic io.grpc.stub.StreamObserver<CommandProviderOutbound> getCommandStream(String context, io.grpc.stub.StreamObserver<CommandProviderInbound> inboundCommandStream)
context
. While either reuse an existing
Channel or create a new one.context
- the context to open the command stream forinboundCommandStream
- the callback to invoke with incoming command messagespublic io.grpc.stub.StreamObserver<QueryProviderOutbound> getQueryStream(String context, io.grpc.stub.StreamObserver<QueryProviderInbound> inboundQueryStream)
context
. While either reuse an existing
Channel or create a new one.context
- the context to open the query stream forinboundQueryStream
- the callback to invoke with incoming query messagespublic io.grpc.stub.StreamObserver<PlatformInboundInstruction> getPlatformStream(String context, io.grpc.stub.StreamObserver<PlatformOutboundInstruction> outboundInstructionStream)
context
. It assumes that channel with given context
is already opened.context
- the contextoutboundInstructionStream
- the callback to invoke outbounding instructions@Deprecated public void onOutboundInstruction(PlatformOutboundInstruction.RequestCase requestCase, Consumer<PlatformOutboundInstruction> consumer)
onOutboundInstruction(String, PlatformOutboundInstruction.RequestCase, Consumer)
as the context should be specified on any outbound instructionrequestCase
- the type of instruction to respond toconsumer
- the handler of the instructionpublic void onOutboundInstruction(String context, PlatformOutboundInstruction.RequestCase requestCase, Consumer<PlatformOutboundInstruction> consumer)
context
- the context for which the instruction is intendedrequestCase
- the type of instruction to respond toconsumer
- the handler of the instructionpublic void onOutboundInstruction(PlatformOutboundInstruction.RequestCase requestCase, BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
requestCase
- the type of instruction to respond tohandler
- the handler of the instructionpublic void onOutboundInstruction(String context, BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
context
- the contexthandler
- the handler of the instructionpublic void onOutboundInstruction(BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
handler
- the handler of the instructionpublic void onOutboundInstruction(String context, PlatformOutboundInstruction.RequestCase requestCase, BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
context
- the contextrequestCase
- the type of instruction to respond tohandler
- the handler of the instructionpublic void onOutboundInstruction(BiPredicate<String,PlatformOutboundInstruction.RequestCase> handlerSelector, BiConsumer<PlatformOutboundInstruction,io.grpc.stub.StreamObserver<PlatformInboundInstruction>> handler)
handlerSelector
- selects a handler based on context and request casehandler
- the handler of the instructionpublic void send(String context, PlatformInboundInstruction instruction)
instruction
for given context
to AxonServer. Will not send anything if no Channel
can be created or found for the given context
.context
- the context for which the instruction is intendedinstruction
- the message containing information for AxonServer to processpublic void disconnectExceptionally(String context, Throwable cause)
context
- the (Bounded) Context for which the disconnection is requiredcause
- the cause of the disconnectionpublic boolean isConnected(String context)
true
if a gRPC channel for the specific context is opened between client and AxonServer.context
- the (Bounded) Context for for which is verified the AxonServer connection through the gRPC channel@ShutdownHandler(phase=-134217728) public void shutdown()
Phase.EXTERNAL_CONNECTIONS
phase.public void disconnect(String context)
context
, forcing a new connection to be established when
one is requested.context
- the context for which the connection must be disconnectedpublic void disconnect()
public String getDefaultContext()
Copyright © 2010–2020. All rights reserved.