Class AxonServerContainerUtils
AxonServerContainer, used to initialize the cluster.- Since:
- 4.8.0
- Author:
- Milan Savic, Sara Pelligrini
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanConstantbooleanspecifying that a context supports DCB.static final booleanConstantbooleanspecifying that a context does not support DCB. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves all the contexts of the Axon Server instance located at the givenhostnameandportcombination.static voidcreateContext(String hostname, int port, String context, boolean dcbContext) Calls the API of Axon Server at the givenhostnameand (http)portto create a context with the givencontextname.static voidcreateContext(String hostname, int port, String context, boolean dcbContext, String replicationGroup) Calls the API of Axon Server at the givenhostnameand (http)portto create a context with the givencontextname.static voiddeleteContext(String hostname, int port, String context) Calls the API of Axon Server at the givenhostnameand (http)portto delete the givencontext.static voidinitCluster(String hostname, int port, boolean shouldBeReused, boolean dcbContext) Initialize the cluster of the Axon Server instance located at the givenhostnameandportcombination.internalContexts(String hostname, int port) Retrieves all the internal contexts (registered in the RAFT protocol) of the Axon Server instance located at the givenhostnameandportcombination.static voidpurgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext) Calls the API of Axon Server at givenhostnameand (http)portto purge events of the givencontext.static voidpurgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext, String replicationGroup) Calls the API of Axon Server at givenhostnameand (http)portto purge events of the givencontext.
-
Field Details
-
DCB_CONTEXT
public static final boolean DCB_CONTEXTConstantbooleanspecifying that a context supports DCB.- See Also:
-
NO_DCB_CONTEXT
public static final boolean NO_DCB_CONTEXTConstantbooleanspecifying that a context does not support DCB.- See Also:
-
-
Method Details
-
initCluster
public static void initCluster(String hostname, int port, boolean shouldBeReused, boolean dcbContext) throws IOException Initialize the cluster of the Axon Server instance located at the givenhostnameandportcombination.Note that this constructs the contexts
_adminanddefault.A reusable container (e.g.
SharedAxonServerContainer.INSTANCE) can be attached to by more than one Surefire/Failsafe JVM fork at nearly the same time --synchronizedin the caller only guards within a single JVM, not across forked processes. Two concurrent/v2/cluster/initrequests against the same, still-uninitialized node corrupt its single-node Raft group membership: the node gets stuck in a perpetual pre-vote/follower loop and never becomes leader, soinitClusteralways times out (observed directly in CI: two "Request to initialize cluster" log lines 82ms apart on the same node, followed by an endless "Timeout in follower state" / "Starting pre-vote" cycle). AFileLockon a path derived fromhostname/portserializes callers targeting the *same* instance across processes, without blocking callers initializing a different instance.- Parameters:
hostname- The hostname of the Axon Server instance to initiate the cluster for.port- The port of the Axon Server instance to initiate the cluster for.shouldBeReused- If set totrue, ensure the cluster is not accidentally initialized twice.dcbContext- Abooleanstating whether a DCB or non-DCB context is being created.- Throws:
IOException- When there are issues with the HTTP connection to the Axon Server instance at the givenhostnameandport, or acquiring the cross-process init lock.
-
contexts
Retrieves all the contexts of the Axon Server instance located at the givenhostnameandportcombination.- Parameters:
hostname- The hostname of the Axon Server instance to create the givencontextof.port- The port of the Axon Server instance to create the givencontextof.- Returns:
- All the contexts of the Axon Server instances located at the given
hostnameandportcombination. - Throws:
IOException- When there are issues with the HTTP connection to the Axon Server instance at the givenhostnameandport.
-
internalContexts
Retrieves all the internal contexts (registered in the RAFT protocol) of the Axon Server instance located at the givenhostnameandportcombination.- Parameters:
hostname- The hostname of the Axon Server instance to create the givencontextof.port- The port of the Axon Server instance to create the givencontextof.- Returns:
- All the contexts of the Axon Server instances located at the given
hostnameandportcombination. - Throws:
IOException- When there are issues with the HTTP connection to the Axon Server instance at the givenhostnameandport.
-
purgeEventsFromAxonServer
public static void purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext) throws IOException Calls the API of Axon Server at givenhostnameand (http)portto purge events of the givencontext.- Parameters:
hostname- The hostname where AxonServer can be reached.port- The HTTP port AxonServer listens to for API calls.context- The context to purge.dcbContext- Abooleanstating whether a DCB or non-DCB context is being purged.- Throws:
IOException- When an error occurs communicating with Axon Server.- Since:
- 5.0.0
-
purgeEventsFromAxonServer
public static void purgeEventsFromAxonServer(String hostname, int port, String context, boolean dcbContext, String replicationGroup) throws IOException Calls the API of Axon Server at givenhostnameand (http)portto purge events of the givencontext.- Parameters:
hostname- The hostname where AxonServer can be reached.port- The HTTP port AxonServer listens to for API calls.context- The context to purge.dcbContext- Abooleanstating whether a DCB or non-DCB context is being purged.replicationGroup- The replication group to use for recreating the contest.- Throws:
IOException- When an error occurs communicating with Axon Server.- Since:
- 5.0.0
-
deleteContext
Calls the API of Axon Server at the givenhostnameand (http)portto delete the givencontext.Concurrent context-mutating calls (create or delete, for any context) against the same Axon Server instance can race each other on its single Raft-backed admin replication group, the same way concurrent cluster-init calls do (see
initCluster(java.lang.String, int, boolean, boolean)): a request arriving while the admin group is mid-operation for another context can be rejected with a transient non-2xx response that clears up moments later. This retries on any such response for up to 30 seconds, except a 404 -- that means the context genuinely doesn't exist, which callers commonly rely on failing fast for (e.g. deleting a context that may or may not be there yet, ignoring the failure) -- so a 404 is thrown immediately instead of retried.- Parameters:
hostname- The hostname where Axon Server can be reached.port- The HTTP port Axon Server listens to for API calls.context- The context to delete.- Throws:
IOException- When the context does not exist (HTTP 404), or deletion did not succeed within 30 seconds of retrying.
-
createContext
public static void createContext(String hostname, int port, String context, boolean dcbContext) throws IOException Calls the API of Axon Server at the givenhostnameand (http)portto create a context with the givencontextname. ThedcbContextdictates whether the context to be created support DCB, yes or no.- Parameters:
hostname- The hostname where Axon Server can be reached.port- The HTTP port Axon Server listens to for API calls.context- The context to create.dcbContext- Abooleanstating whether a DCB or non-DCB context is being created.- Throws:
IOException- When an error occurs communicating with Axon Server.
-
createContext
public static void createContext(String hostname, int port, String context, boolean dcbContext, String replicationGroup) throws IOException Calls the API of Axon Server at the givenhostnameand (http)portto create a context with the givencontextname. ThedcbContextdictates whether the context to be created support DCB, yes or no.Concurrent context-mutating calls (create or delete, for any context) against the same Axon Server instance can race each other on its single Raft-backed admin replication group, the same way concurrent cluster-init calls do (see
initCluster(java.lang.String, int, boolean, boolean)): a request arriving while the admin group is mid-operation for another context can be rejected with a transient non-2xx response that clears up moments later. This retries on any such response for up to 30 seconds.- Parameters:
hostname- The hostname where Axon Server can be reached.port- The HTTP port Axon Server listens to for API calls.context- The context to create.dcbContext- Abooleanstating whether a DCB or non-DCB context is being created.replicationGroup- The replication group to be used.- Throws:
IOException- When creation did not succeed within 30 seconds of retrying.
-