Package io.mats3.impl.jms
Class JmsMatsEndpoint<R,S,Z>
java.lang.Object
io.mats3.impl.jms.JmsMatsEndpoint<R,S,Z>
- All Implemented Interfaces:
JmsMatsStartStoppable
,JmsMatsStatics
,MatsConfig.StartStoppable
,MatsEndpoint<R,
S>
public class JmsMatsEndpoint<R,S,Z>
extends Object
implements MatsEndpoint<R,S>, JmsMatsStatics, JmsMatsStartStoppable
The JMS implementation of
MatsEndpoint
.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.mats3.MatsEndpoint
MatsEndpoint.DetachedProcessContext, MatsEndpoint.EndpointConfig<R,
S>, MatsEndpoint.MatsObject, MatsEndpoint.MatsRefuseMessageException, MatsEndpoint.ProcessContext<R>, MatsEndpoint.ProcessContextWrapper<R>, MatsEndpoint.ProcessLambda<R, S, I>, MatsEndpoint.ProcessReturnLambda<R, S, I>, MatsEndpoint.ProcessSingleLambda<R, I>, MatsEndpoint.ProcessTerminatorLambda<S, I> -
Field Summary
Fields inherited from interface io.mats3.impl.jms.JmsMatsStatics
EXTRA_GRACE_MILLIS, ILLEGAL_CALL_FLOWS, JMS_MSG_PROP_AUDIT, JMS_MSG_PROP_DISPATCH_TYPE, JMS_MSG_PROP_FROM, JMS_MSG_PROP_INITIALIZING_APP, JMS_MSG_PROP_INITIATOR_ID, JMS_MSG_PROP_MATS_MESSAGE_ID, JMS_MSG_PROP_MESSAGE_TYPE, JMS_MSG_PROP_TO, JMS_MSG_PROP_TRACE_ID, LOG_PREFIX, MAX_STACK_HEIGHT, MAX_TOTAL_CALL_NUMBER, MDC_MATS_APP_NAME, MDC_MATS_APP_VERSION, MDC_MATS_CALL_NUMBER, MDC_MATS_IN_MESSAGE_SYSTEM_ID, MDC_MATS_INIT, MDC_MATS_OUT_MATS_MESSAGE_ID, MDC_MATS_STAGE, MDC_MATS_STAGE_ID, MDC_TRACE_ID, NO_INVOCATION_POINT, RANDOM_ALPHABET, THREAD_PREFIX, TOTAL_JMS_MSG_PROPS_SIZE
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Should be invoked when all stages has been added.Must be implemented to provide your children.int
hashCode()
idThis()
lastStage
(Class<I> incomingClass, MatsEndpoint.ProcessReturnLambda<R, S, I> processor) Adds the last stage to a multi-stage endpoint, which alsofinishes setup
of the endpoint.lastStage
(Class<I> incomingClass, Consumer<? super MatsStage.StageConfig<R, S, I>> stageConfigLambda, MatsEndpoint.ProcessReturnLambda<R, S, I> processor) Variation ofMatsEndpoint.lastStage(Class, ProcessReturnLambda)
that can be configured "on the fly".boolean
remove
(int gracefulShutdownMillis) Should most probably only be used for testing!stage
(Class<I> incomingClass, MatsEndpoint.ProcessLambda<R, S, I> processor) Adds a new stage to a multi-stage endpoint.stage
(Class<I> incomingClass, Consumer<? super MatsStage.StageConfig<R, S, I>> stageConfigLambda, MatsEndpoint.ProcessLambda<R, S, I> processor) Variation ofMatsEndpoint.stage(Class, ProcessLambda)
that can be configured "on the fly".void
start()
Starts the endpoint (unlessMatsEndpoint.finishSetup()
has NOT been invoked), invokingMatsStage.start()
on any not-yet started stages of the endpoint (which should be all of them at application startup).boolean
stop
(int gracefulShutdownMillis) Stops the endpoint, invokingMatsStage.stop(int)
on allMatsStage
s.toString()
boolean
waitForReceiving
(int timeoutMillis) Waits till all stages of the endpoint has entered their receive-loops, i.e.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.mats3.impl.jms.JmsMatsStartStoppable
stopPhase0_SetRunFlagFalse, stopPhase1_CloseSessionIfInReceive, stopPhase2_GracefulWaitAfterRunflagFalse, stopPhase3_InterruptIfStillAlive, stopPhase4_GracefulWaitAfterInterrupt
Methods inherited from interface io.mats3.impl.jms.JmsMatsStatics
createFlowId, getInvocationPoint, id, id, ms3, produceAndSendMsgSysMessages, randomString, setConcurrencyWithLog, stageOrInit
-
Method Details
-
getParentFactory
- Specified by:
getParentFactory
in interfaceMatsEndpoint<R,
S> - Returns:
- the parent
MatsFactory
.
-
getEndpointConfig
- Specified by:
getEndpointConfig
in interfaceMatsEndpoint<R,
S> - Returns:
- the config for this endpoint. If endpoint is not yet started, you may invoke mutators on it.
-
stage
public <I> MatsStage<R,S, stageI> (Class<I> incomingClass, MatsEndpoint.ProcessLambda<R, S, I> processor) Description copied from interface:MatsEndpoint
Adds a new stage to a multi-stage endpoint. If this is the last stage of a multi-stage endpoint, you must invokeMatsEndpoint.finishSetup()
afterwards - or you could instead use theMatsEndpoint.lastStage(Class, ProcessReturnLambda)
variant which does this automatically.- Specified by:
stage
in interfaceMatsEndpoint<R,
S> - Type Parameters:
I
- the type of the incoming DTO. The very first stage's incoming DTO is the endpoint's incoming DTO. If the special typeMatsEndpoint.MatsObject
, this stage can take any type.processor
- the lambda that will be invoked when messages arrive in the corresponding queue.- See Also:
-
stage
public <I> MatsStage<R,S, stageI> (Class<I> incomingClass, Consumer<? super MatsStage.StageConfig<R, S, I>> stageConfigLambda, MatsEndpoint.ProcessLambda<R, S, I> processor) Description copied from interface:MatsEndpoint
Variation ofMatsEndpoint.stage(Class, ProcessLambda)
that can be configured "on the fly".- Specified by:
stage
in interfaceMatsEndpoint<R,
S>
-
lastStage
public <I> MatsStage<R,S, lastStageI> (Class<I> incomingClass, MatsEndpoint.ProcessReturnLambda<R, S, I> processor) Description copied from interface:MatsEndpoint
Adds the last stage to a multi-stage endpoint, which alsofinishes setup
of the endpoint. Note that the last-stage concept is just a convenience that lets the developer reply from the endpoint with areturn replyDTO
statement - you may just as well add a standard stage, and invoke theMatsEndpoint.ProcessContext.reply(Object)
method. Note: If using a normal stage as the last stage, you must remember to invokeMatsEndpoint.finishSetup()
afterwards, as that is then not done automatically.- Specified by:
lastStage
in interfaceMatsEndpoint<R,
S> - Type Parameters:
I
- the type of the incoming DTO. The very first stage's incoming DTO is the endpoint's incoming DTO. If the special typeMatsEndpoint.MatsObject
, this stage can take any type.processor
- the lambda that will be invoked when messages arrive in the corresponding queue.
-
lastStage
public <I> MatsStage<R,S, lastStageI> (Class<I> incomingClass, Consumer<? super MatsStage.StageConfig<R, S, I>> stageConfigLambda, MatsEndpoint.ProcessReturnLambda<R, S, I> processor) Description copied from interface:MatsEndpoint
Variation ofMatsEndpoint.lastStage(Class, ProcessReturnLambda)
that can be configured "on the fly".- Specified by:
lastStage
in interfaceMatsEndpoint<R,
S>
-
getStages
- Specified by:
getStages
in interfaceMatsEndpoint<R,
S> - Returns:
- a List of
MatsStage
s, representing all the stages of the endpoint. The order is the same as the order in which the stages will be invoked. For single-staged endpoints and terminators, this list is of size 1.
-
finishSetup
public void finishSetup()Description copied from interface:MatsEndpoint
Should be invoked when all stages has been added. Will automatically be invoked by invocation ofMatsEndpoint.lastStage(Class, ProcessReturnLambda)
, which again implies that it will be invoked when creatingsingle-stage endpoints
andterminators
andsubscription terminators
. This sets the state of the endpoint to "finished setup", and will invokeMatsEndpoint.start()
on the endpoint, unlessMatsFactory.holdEndpointsUntilFactoryIsStarted()
has been invoked prior to creating the endpoint. You may implement "delayed start" of an endpoint by not invoking finishedSetup() after setting it up. Taking into account the first chapter of this JavaDoc, note that you must then only use thestaged
type of Endpoint setup, as the others implicitly invokes finishSetup(), and also not invokelastStage
on it as this also implicitly invokes finishSetup(). When setting an Endpoint up without calling finishSetup(), even whenMatsFactory.start()
is invoked, such a not-finished endpoint will then not be started. You may then later invoke finishSetup(), e.g. when any needed caches are finished populated, and the endpoint will then be finished and started. Another way to implement "delayed start" is to obviously just not create the endpoint until later: MatsFactory has no "that's it, now all endpoints must have been created"-lifecycle stage, and can fire up new endpoints until the JVM is dead.- Specified by:
finishSetup
in interfaceMatsEndpoint<R,
S>
-
start
public void start()Description copied from interface:MatsEndpoint
Starts the endpoint (unlessMatsEndpoint.finishSetup()
has NOT been invoked), invokingMatsStage.start()
on any not-yet started stages of the endpoint (which should be all of them at application startup).- Specified by:
start
in interfaceMatsConfig.StartStoppable
- Specified by:
start
in interfaceMatsEndpoint<R,
S>
-
getChildrenStartStoppable
Description copied from interface:JmsMatsStartStoppable
Must be implemented to provide your children.- Specified by:
getChildrenStartStoppable
in interfaceJmsMatsStartStoppable
-
waitForReceiving
public boolean waitForReceiving(int timeoutMillis) Description copied from interface:MatsEndpoint
Waits till all stages of the endpoint has entered their receive-loops, i.e. invokesMatsStage.waitForReceiving(int)
on allMatsStage
s of the endpoint. Note: This method makes most sense forSubscriptionTerminators
: These are based on MQ Topics, whose semantics are that if you do not listen right when someone says something, you will not hear it. This means that a SubscriptionTerminator will never receive a message that was sent before it had started the receive-loop. Thus, if you in a service-"boot" phase send a message whose result will come in to a SubscriptionTerminator, you will not receive this result if the receive-loop has not started. This is relevant for certain cache setups where you listen for event updates, and when "booting" the cache, you need to be certain that you have started receiving updates before asking for the "initial load" of the cache. It is also relevant for tools like theMatsFuturizer
, which uses a node-specific Topic for the final reply message from the requested service; If the SubscriptionTerminator has not yet made it to the receive-loop, any replies will simply be lost and the future never completed. Note: Currently, this only holds for the initial start. If the entity has started the receive-loop at some point, it will always immediately return - even though it is currently stopped.- Specified by:
waitForReceiving
in interfaceJmsMatsStartStoppable
- Specified by:
waitForReceiving
in interfaceMatsConfig.StartStoppable
- Specified by:
waitForReceiving
in interfaceMatsEndpoint<R,
S> - Parameters:
timeoutMillis
- number of milliseconds before giving up the wait, returningfalse
. 0 is indefinite wait, negative values are not allowed.- Returns:
- whether it was started (i.e.
true
if successfully started listening for messages).
-
stop
public boolean stop(int gracefulShutdownMillis) Description copied from interface:MatsEndpoint
Stops the endpoint, invokingMatsStage.stop(int)
on allMatsStage
s.- Specified by:
stop
in interfaceJmsMatsStartStoppable
- Specified by:
stop
in interfaceMatsConfig.StartStoppable
- Specified by:
stop
in interfaceMatsEndpoint<R,
S> - Parameters:
gracefulShutdownMillis
- number of milliseconds to let the stage processors wait after having asked for them to shut down, and interrupting them if they have not shut down yet.- Returns:
- whether it was successfully stopped (i.e.
true
if successfully stopped all listening threads).
-
remove
public boolean remove(int gracefulShutdownMillis) Description copied from interface:MatsEndpoint
Should most probably only be used for testing! First invokesstop(gracefulShutdownMillis)
, and if successful removes the endpoint from its MatsFactory. This enables a new endpoint to be registered with the same endpointId as the one removed (which otherwise is not accepted). This might be of interest in testing scenarios, where you want to change the implementation of an endpoint from one test to another. There is currently no known situation where this makes sense to do "in production": Once the system is set up with the correct endpoints, it should most probably stay that way!- Specified by:
remove
in interfaceMatsEndpoint<R,
S> - Returns:
- whether the
MatsEndpoint.stop(int gracefulShutdownMillis)
was successful, and thus whether the endpoint was removed from its MatsFactory.
-
equals
-
hashCode
public int hashCode() -
idThis
- Specified by:
idThis
in interfaceJmsMatsStatics
-
toString
-