Package io.mats3.spring.jms.factories
Class ScenarioConnectionFactoryWrapper
java.lang.Object
io.mats3.util.wrappers.ConnectionFactoryWrapper
io.mats3.spring.jms.factories.ScenarioConnectionFactoryWrapper
- All Implemented Interfaces:
MatsFactory.MatsWrapper<javax.jms.ConnectionFactory>
,javax.jms.ConnectionFactory
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.context.EnvironmentAware
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
public class ScenarioConnectionFactoryWrapper
extends ConnectionFactoryWrapper
implements org.springframework.context.EnvironmentAware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.SmartLifecycle
A
ConnectionFactoryWrapper
which lazily decides which of the three MatsScenario
s are active, and
produces the wrapper-target ConnectionFactory
based on that - you most probably want to use
ScenarioConnectionFactoryProducer
to make an instance of this class, but you can configure it directly too.
The main documentation for this MatsScenario concept is in the JavaDoc of
ScenarioConnectionFactoryProducer
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A ConnectionFactory provider which can throw Exceptions - if it returns aConnectionFactoryWithStartStopWrapper
, start() and stop() will be invoked on that, read more on its JavaDoc.protected static class
protected static class
protected static class
static interface
We need a way to decide between the three differentMatsScenario
s. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected org.springframework.core.env.Environment
protected MatsScenario
protected javax.jms.ConnectionFactory
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorsConstructorDescriptionScenarioConnectionFactoryWrapper
(ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider regular, ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider localhost, ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider localvm, ScenarioConnectionFactoryWrapper.ScenarioDecider scenarioDecider) Constructor takingScenarioConnectionFactoryWrapper.ConnectionFactoryProvider
s for each of the threeMatsScenario
s and aScenarioConnectionFactoryWrapper.ScenarioDecider
to decide which of these to employ - you most probably want to useScenarioConnectionFactoryProducer
to make one of these. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
int
getPhase()
boolean
boolean
void
setBeanName
(String name) void
setEnvironment
(org.springframework.core.env.Environment environment) void
setWrappee
(javax.jms.ConnectionFactory targetConnectionFactory) Sets the wrappedConnectionFactory
, e.g.void
start()
void
stop()
void
javax.jms.ConnectionFactory
unwrap()
Methods inherited from class io.mats3.util.wrappers.ConnectionFactoryWrapper
createConnection, createConnection
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.mats3.MatsFactory.MatsWrapper
unwrapFully, unwrapTo
-
Field Details
-
_regularConnectionFactoryProvider
protected ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider _regularConnectionFactoryProvider -
_localhostConnectionFactoryProvider
protected ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider _localhostConnectionFactoryProvider -
_localVmConnectionFactoryProvider
protected ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider _localVmConnectionFactoryProvider -
_scenarioDecider
-
_beanName
-
_environment
protected org.springframework.core.env.Environment _environment -
_targetConnectionFactory
protected volatile javax.jms.ConnectionFactory _targetConnectionFactory -
_matsScenarioDecision
-
-
Constructor Details
-
ScenarioConnectionFactoryWrapper
public ScenarioConnectionFactoryWrapper(ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider regular, ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider localhost, ScenarioConnectionFactoryWrapper.ConnectionFactoryProvider localvm, ScenarioConnectionFactoryWrapper.ScenarioDecider scenarioDecider) Constructor takingScenarioConnectionFactoryWrapper.ConnectionFactoryProvider
s for each of the threeMatsScenario
s and aScenarioConnectionFactoryWrapper.ScenarioDecider
to decide which of these to employ - you most probably want to useScenarioConnectionFactoryProducer
to make one of these.
-
-
Method Details
-
setBeanName
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
setWrappee
public void setWrappee(javax.jms.ConnectionFactory targetConnectionFactory) Description copied from class:ConnectionFactoryWrapper
Sets the wrappedConnectionFactory
, e.g. in case you instantiated it with the no-args constructor. Do note that the field holding the wrapped instance is not volatile nor synchronized. This means that if you want to set it after it has been published to other threads, you will have to override both this method andConnectionFactoryWrapper.unwrap()
to provide for needed memory visibility semantics, i.e. establish a happens-before edge between the setting of the instance and any other threads getting it.- Specified by:
setWrappee
in interfaceMatsFactory.MatsWrapper<javax.jms.ConnectionFactory>
- Overrides:
setWrappee
in classConnectionFactoryWrapper
- Parameters:
targetConnectionFactory
- theConnectionFactory
which is returned byConnectionFactoryWrapper.unwrap()
, unless that is overridden.
-
unwrap
public javax.jms.ConnectionFactory unwrap()- Specified by:
unwrap
in interfaceMatsFactory.MatsWrapper<javax.jms.ConnectionFactory>
- Overrides:
unwrap
in classConnectionFactoryWrapper
- Returns:
- the wrapped
ConnectionFactory
. All forwarding methods invokes this method to get the wrappedConnectionFactory
, thus if you want to get creative wrt. how and when the ConnectionFactory is decided, you can override this method.
-
getMatsScenarioUsedToMakeConnectionFactory
- Returns:
- the
MatsScenario
that was used to make theConnectionFactory
returned byunwrap()
.
-
createTargetConnectionFactoryBasedOnScenarioDecider
protected void createTargetConnectionFactoryBasedOnScenarioDecider() -
getPhase
public int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stop
in interfaceorg.springframework.context.SmartLifecycle
-