Class MUXPool
java.lang.Object
org.jpos.q2.QBeanSupport
org.jpos.q2.iso.MUXPool
- All Implemented Interfaces:
Configurable, ISOSource, MUX, MUXPoolMBean, QBean, QBeanSupportMBean, QPersist
Pool of
MUX instances that selects a delegate per request based on
the configured strategy (one of PRIMARY_SECONDARY, ROUND_ROBIN,
ROUND_ROBIN_WITH_OVERRIDE, or SPLIT_BY_DIVISOR).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA class implementing this interface can be added to aMUXPoolto override the classical built-in strategies.
It could be added to aMUXPoollike this: -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intStrategy: try MUXes in order, falling through to the next when unusable.static final intStrategy: round-robin selection across the registered MUXes.static final intStrategy: round-robin selection with per-MTI override routing.static final intStrategy: hash-by-divisor selection driven by a configured field value.Fields inherited from class QBeanSupport
cfg, log, scheduledThreadPoolExecutorModifier and TypeFieldDescriptionprotected ConfigurationConfiguration applied to this bean by the container.protected LogLogger associated with this bean.protected ScheduledThreadPoolExecutorLazily-allocated scheduler shared with subclasses; seeQBeanSupport.getScheduledThreadPoolExecutor().Fields inherited from interface QBean
DESTROYED, FAILED, STARTED, STARTING, stateString, STOPPED, STOPPINGModifier and TypeFieldDescriptionstatic final intQBean has been destroyed.static final intQBean has failed.static final intQBean is running.static final intQBean is in the process of starting.static final String[]Human-readable names for each QBean state, indexed by state constant.static final intQBean is stopped.static final intQBean is in the process of stopping. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns the default realm for this bean; subclasses may override.protected MUXfirstAvailableMUX(long maxWait) Returns the first usable MUX, scanning from index 0 and waiting up tomaxWait.String[]Returns the names of the MUXes in this pool.intReturns the configured selection strategy.Returns the configured custom strategy handler, if any.protected voidinitHandler(org.jdom2.Element e) Instantiates a customMUXPool.StrategyHandlerfrom an XML configuration element.voidCalled during the init lifecycle phase; subclasses may override.booleanIndicates whether this source is currently connected and able to send messages.protected MUXnextAvailableMUX(int mnumber, long maxWait) Returns the next usable MUX starting frommnumber, waiting up tomaxWait.Sends a message to remote host and wait for responsevoidrequest(ISOMsg m, long timeout, ISOResponseListener r, Object handBack) Sends a message to remote host in async wayvoidsends (or hands back) an ISOMsgvoidCalled during the stop lifecycle phase; subclasses may override.Methods inherited from class QBeanSupport
addAttr, close, createElement, destroy, destroyService, getAttrs, getAttrs, getConfiguration, getDump, getFactory, getLoader, getLoaderURLS, getLog, getLogger, getName, getPersist, getProperties, getProperty, getRealm, getScheduledThreadPoolExecutor, getServer, getState, getStateAsString, init, isModified, running, setAttr, setConfiguration, setLogger, setModified, setName, setPersist, setProperty, setRealm, setServer, setState, start, startService, stopModifier and TypeMethodDescriptionprotected voidAppends an<attr>child element with name/type/value toe.protected voidCloses a sequence ofCloseableresources, logging any failures as a warning.protected org.jdom2.ElementcreateElement(String name, Class mbeanClass) Builds a JDOMElementreflecting the bean's persistent attributes, driven by the JavaBean introspection ofmbeanClass.voiddestroy()destroy the serviceprotected voidCalled during the destroy lifecycle phase; subclasses may override.protected IteratorgetAttrs()Iterates over top-level<attr>children of the persisted element.protected IteratorIterates over<attr>children nested under the given parent element name.Returns the configuration applied to this bean.getDump()Returns a textual dump of this bean's state.Returns theQFactoryassociated with the hosting Q2 server.Returns the QClassLoader for this bean.URL[]Returns the URLs registered with the class loader.getLog()Returns theLogused by this bean.Returns the logger name.getName()Returns the bean name.org.jdom2.ElementReturns the persistent configuration element for this QBean.protected IteratorgetProperties(String parent) Iterates over<property>children nested under the given parent element name.protected StringgetProperty(Iterator props, String name) Returns the value of the named property from an iterator of<property>elements.getRealm()Returns the logging realm.protected ScheduledThreadPoolExecutorLazily creates and returns aScheduledThreadPoolExecutorfor use by subclasses.Returns the Q2 server instance.intgetState()Returns the current state of this QBean.Returns the current state as a human-readable string.voidinit()init the servicebooleanReturnstrueif this QBean's configuration has been modified since last save.booleanrunning()Indicates whether this bean is currently starting or running.protected voidUpdates the value of the named attribute within an iterator of<attr>elements.voidConfigures this object with the suppliedConfiguration.voidSets the logger by name.voidsetModified(boolean modified) Marks this bean's persistent state as modified or in sync.voidSets the bean name.voidsetPersist(org.jdom2.Element persist) Sets the persistent configuration element.protected voidsetProperty(Iterator props, String name, String value) Updates the value attribute of the named property within an iterator of<property>elements.voidSets the logging realm.voidSets the Q2 server instance for this QBean.voidsetState(int state) Sets the lifecycle state of this bean.voidstart()start the serviceprotected voidCalled during the start lifecycle phase; subclasses may override.voidstop()stop the service
-
Field Details
-
PRIMARY_SECONDARY
Strategy: try MUXes in order, falling through to the next when unusable.- See Also:
-
ROUND_ROBIN
Strategy: round-robin selection across the registered MUXes.- See Also:
-
ROUND_ROBIN_WITH_OVERRIDE
Strategy: round-robin selection with per-MTI override routing.- See Also:
-
SPLIT_BY_DIVISOR
Strategy: hash-by-divisor selection driven by a configured field value.- See Also:
-
-
Constructor Details
-
MUXPool
public MUXPool()Default constructor; no instance state to initialise.
-
-
Method Details
-
defaultRealm
Description copied from class:QBeanSupportReturns the default realm for this bean; subclasses may override.- Overrides:
defaultRealmin classQBeanSupport- Returns:
- default realm string, or null
-
initService
Description copied from class:QBeanSupportCalled during the init lifecycle phase; subclasses may override.- Overrides:
initServicein classQBeanSupport- Throws:
ConfigurationException
-
stopService
Description copied from class:QBeanSupportCalled during the stop lifecycle phase; subclasses may override.- Overrides:
stopServicein classQBeanSupport
-
initHandler
Instantiates a customMUXPool.StrategyHandlerfrom an XML configuration element.- Parameters:
e-<strategy-handler>element, ornullto leave the handler unset- Throws:
ConfigurationException- if the handler cannot be instantiated
-
request
Description copied from interface:MUXSends a message to remote host and wait for response- Specified by:
requestin interfaceMUX- Parameters:
m- message to sendtimeout- time to wait for a message- Returns:
- received message or null
- Throws:
ISOException- on pack/unpack error
-
request
public void request(ISOMsg m, long timeout, ISOResponseListener r, Object handBack) throws ISOException Description copied from interface:MUXSends a message to remote host in async way- Specified by:
requestin interfaceMUX- Parameters:
m- message to sendtimeout- time to wait for the responser- reference to response listenerhandBack- optional handback to be given to reponse listener- Throws:
ISOException- on pack/unpack error
-
send
Description copied from interface:ISOSourcesends (or hands back) an ISOMsg- Specified by:
sendin interfaceISOSource- Parameters:
m- the Message to be sent- Throws:
ISOException- on ISO packing failureIOException- on I/O failure
-
firstAvailableMUX
Returns the first usable MUX, scanning from index 0 and waiting up tomaxWait.- Parameters:
maxWait- wall-clock deadline in milliseconds since epoch- Returns:
- a usable MUX, or
nullif none became available before the deadline
-
nextAvailableMUX
Returns the next usable MUX starting frommnumber, waiting up tomaxWait.- Parameters:
mnumber- starting index (round-robin counter)maxWait- wall-clock deadline in milliseconds since epoch- Returns:
- a usable MUX, or
nullif none became available before the deadline
-
getMuxNames
Description copied from interface:MUXPoolMBeanReturns the names of the MUXes in this pool.- Specified by:
getMuxNamesin interfaceMUXPoolMBean- Returns:
- MUX names
-
getStrategy
Description copied from interface:MUXPoolMBeanReturns the configured selection strategy.- Specified by:
getStrategyin interfaceMUXPoolMBean- Returns:
- strategy code (see MUXPool strategy constants)
-
getStrategyHandler
Returns the configured custom strategy handler, if any.- Returns:
- the
MUXPool.StrategyHandler, ornullwhen not configured
-
isConnected
Description copied from interface:ISOSourceIndicates whether this source is currently connected and able to send messages.- Specified by:
isConnectedin interfaceISOSource- Returns:
- true if source is connected and usable
-