Package io.mats3.impl.jms
Class JmsMatsJmsSessionHandler_Pooling
java.lang.Object
io.mats3.impl.jms.JmsMatsJmsSessionHandler_Pooling
- All Implemented Interfaces:
JmsMatsJmsSessionHandler
,JmsMatsStatics
public class JmsMatsJmsSessionHandler_Pooling
extends Object
implements JmsMatsJmsSessionHandler, JmsMatsStatics
Pooling implementation of
JmsMatsJmsSessionHandler
- upon
creation
, you decide how
Connections are shared for JmsMatsStageProcessor
s and MatsInitiator
s.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
static class
static enum
What kind of sharing of JMS Connections to employ for aJmsMatsInitiator
.static enum
What kind of sharing of JMS Connections to employ for aJmsMatsStageProcessor
.Nested classes/interfaces inherited from interface io.mats3.impl.jms.JmsMatsJmsSessionHandler
JmsMatsJmsSessionHandler.JmsSessionHolder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final javax.jms.ConnectionFactory
protected final JmsMatsJmsSessionHandler_Pooling.PoolingKeyInitiator
protected final JmsMatsJmsSessionHandler_Pooling.PoolingKeyStageProcessor
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_MATS_STAGE_INDEX, MDC_TRACE_ID, NO_INVOCATION_POINT, RANDOM_ALPHABET, THREAD_PREFIX, TOTAL_JMS_MSG_PROPS_SIZE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JmsMatsJmsSessionHandler_Pooling
(javax.jms.ConnectionFactory jmsConnectionFactory, JmsMatsJmsSessionHandler_Pooling.PoolingKeyInitiator poolingKeyInitiator, JmsMatsJmsSessionHandler_Pooling.PoolingKeyStageProcessor poolingKeyStageProcessor) -
Method Summary
Modifier and TypeMethodDescriptionint
Closes all Available Session, does not touch Employed.create
(javax.jms.ConnectionFactory jmsConnectionFactory) Returns a JmsMatsJmsSessionHandler which uses theINITIATOR
pooling key for Intitiators (i.e.create
(javax.jms.ConnectionFactory jmsConnectionFactory, JmsMatsJmsSessionHandler_Pooling.PoolingKeyInitiator poolingKeyInitiator, JmsMatsJmsSessionHandler_Pooling.PoolingKeyStageProcessor poolingKeyStageProcessor) Returns a JmsMatsJmsSessionHandler which have specific pooling derivation.protected Object
getSessionHolder
(io.mats3.impl.jms.JmsMatsInitiator<?> initiator) Will be invoked every time an Initiator wants to send a message - it will be returned after the message(s) is sent.getSessionHolder
(io.mats3.impl.jms.JmsMatsStageProcessor<?, ?, ?, ?> stageProcessor) Will be invoked before the StageProcessor goes into its consumer loop - it will be closed once the Stage is stopped, or if the Session "crashes", i.e.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.mats3.impl.jms.JmsMatsStatics
createFlowId, getInvocationPoint, id, id, idThis, ms3, produceAndSendMsgSysMessages, randomString, setConcurrencyWithLog, stageOrInit
-
Field Details
-
_jmsConnectionFactory
protected final javax.jms.ConnectionFactory _jmsConnectionFactory -
_poolingKeyInitiator
-
_poolingKeyStageProcessor
-
_connectionWithSessionPools_live
protected IdentityHashMap<Object,JmsMatsJmsSessionHandler_Pooling.ConnectionWithSessionPool> _connectionWithSessionPools_live -
_connectionWithSessionPools_crashed
protected IdentityHashMap<Object,JmsMatsJmsSessionHandler_Pooling.ConnectionWithSessionPool> _connectionWithSessionPools_crashed
-
-
Constructor Details
-
JmsMatsJmsSessionHandler_Pooling
protected JmsMatsJmsSessionHandler_Pooling(javax.jms.ConnectionFactory jmsConnectionFactory, JmsMatsJmsSessionHandler_Pooling.PoolingKeyInitiator poolingKeyInitiator, JmsMatsJmsSessionHandler_Pooling.PoolingKeyStageProcessor poolingKeyStageProcessor)
-
-
Method Details
-
derivePoolingKey
-
create
public static JmsMatsJmsSessionHandler_Pooling create(javax.jms.ConnectionFactory jmsConnectionFactory) Returns a JmsMatsJmsSessionHandler which uses theINITIATOR
pooling key for Intitiators (i.e. a JMS Connection per Initiator), andFACTORY
pooling key for Endpoints (i.e. a JMS Connection per Endpoint). Note that is seems like ActiveMQ is not all that great at multiplexing multiple sessions and consumers over the same connection. You get lower latency by usingSTAGE
and even better withSTAGE_PROCESSOR
, but when your set of services using Mats gets large, this results in an awful lot of connections.- Parameters:
jmsConnectionFactory
- the JMSConnectionFactory
to get JMS Connections from.- Returns:
- a JmsMatsJmsSessionHandler which employs a single JMS Connection for everything: Initiations, and all consumers.
-
create
public static JmsMatsJmsSessionHandler_Pooling create(javax.jms.ConnectionFactory jmsConnectionFactory, JmsMatsJmsSessionHandler_Pooling.PoolingKeyInitiator poolingKeyInitiator, JmsMatsJmsSessionHandler_Pooling.PoolingKeyStageProcessor poolingKeyStageProcessor) Returns a JmsMatsJmsSessionHandler which have specific pooling derivation.- Parameters:
jmsConnectionFactory
- the JMSConnectionFactory
to get JMS Connections from.poolingKeyInitiator
- what kind of JMS Connection sharing to employ for Initiators.poolingKeyStageProcessor
- what kind of JMS Connection sharing to employ for StageProcessors.- Returns:
- a JmsMatsJmsSessionHandler which has the specified pooling derivation.
-
getSessionHolder
public JmsMatsJmsSessionHandler.JmsSessionHolder getSessionHolder(io.mats3.impl.jms.JmsMatsInitiator<?> initiator) throws JmsMatsException.JmsMatsJmsException Description copied from interface:JmsMatsJmsSessionHandler
Will be invoked every time an Initiator wants to send a message - it will be returned after the message(s) is sent.- Specified by:
getSessionHolder
in interfaceJmsMatsJmsSessionHandler
- Parameters:
initiator
- the initiator in question.- Returns:
- a
JmsMatsJmsSessionHandler.JmsSessionHolder
instance - which is not the same as any other SessionHolders concurrently in use (but it may be pooled, so after aJmsMatsJmsSessionHandler.JmsSessionHolder.release()
, it may be returned to another invocation again). - Throws:
JmsMatsException.JmsMatsJmsException
- if there was a problem getting a Connection. Problems getting a Sessions (e.g. the current Connection is broken) should be internally handled (i.e. try to get a new Connection), except if it can be determined that the problem getting a Session is of a fundamental nature (i.e. the credentials can get a Connection, but cannot get a Session - which would be pretty absurd, but hey).
-
getSessionHolder
public JmsMatsJmsSessionHandler.JmsSessionHolder getSessionHolder(io.mats3.impl.jms.JmsMatsStageProcessor<?, ?, throws JmsMatsException.JmsMatsJmsException?, ?> stageProcessor) Description copied from interface:JmsMatsJmsSessionHandler
Will be invoked before the StageProcessor goes into its consumer loop - it will be closed once the Stage is stopped, or if the Session "crashes", i.e. a method on Session or some downstream API throws an Exception.- Specified by:
getSessionHolder
in interfaceJmsMatsJmsSessionHandler
- Parameters:
stageProcessor
- the StageProcessor in question.- Returns:
- a
JmsMatsJmsSessionHandler.JmsSessionHolder
instance - which is unique for each call. - Throws:
JmsMatsException.JmsMatsJmsException
- if there was a problem getting a Connection. Problems getting a Sessions (e.g. the current Connection is broken) should be internally handled (i.e. try to get a new Connection), except if it can be determined that the problem getting a Session is of a fundamental nature (i.e. the credentials can get a Connection, but cannot get a Session - which would be pretty absurd, but hey).
-
closeAllAvailableSessions
public int closeAllAvailableSessions()Description copied from interface:JmsMatsJmsSessionHandler
Closes all Available Session, does not touch Employed. Net result is that it Connections that do not have any employed Sessions will be closed. The use case for this is to "clear out" theJmsMatsJmsSessionHandler
upon shutdown - the returned value is a count of how many Connections are still alive after the operation, which should be 0.- Specified by:
closeAllAvailableSessions
in interfaceJmsMatsJmsSessionHandler
- Returns:
- the number of Connections still alive after the operation (in the assumed use case, this should be zero).
-
getSessionHolder_internal
protected JmsMatsJmsSessionHandler.JmsSessionHolder getSessionHolder_internal(JmsMatsTransactionManager.JmsMatsTxContextKey txContextKey) throws JmsMatsException.JmsMatsJmsException
-