Class QBeanSupport
java.lang.Object
org.jpos.q2.QBeanSupport
- All Implemented Interfaces:
Configurable, QBean, QBeanSupportMBean, QPersist
- Direct Known Subclasses:
BSH, ChannelAdaptor, ContextMaker, DailyTaskAdaptor, DirPollAdaptor, KeyStoreAdaptor, LoggerAdaptor, LoggerService, MUXPool, OneShotChannelAdaptor, OneShotChannelAdaptorMK2, PrometheusService, QBeanAsyncSupport, QBeanFactory, QConfig, QExec, QMUX, QMUXProxyAdaptor, QServer, QSingleInstanceFileBasedManager, QSingleInstancePortBasedManager, QThreadPoolExecutor, QXmlConfig, Shutdown, SMAdaptor, SpaceAdaptor, SpaceLet, SpaceProxyAdaptor, SystemMonitor, TaskAdaptor, TemplateDeployer, TransactionManager, UI
public class QBeanSupport
extends Object
implements QBean, QPersist, QBeanSupportMBean, Configurable
Base class providing lifecycle management and configuration support for Q2 beans (QBean components).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConfigurationConfiguration applied to this bean by the container.protected LogLogger associated with this bean.protected ScheduledThreadPoolExecutorLazily-allocated scheduler shared with subclasses; seegetScheduledThreadPoolExecutor().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 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.protected StringReturns the default realm for this bean; subclasses may override.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 serviceprotected voidCalled during the init lifecycle phase; subclasses may override.booleanReturnstrueif 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 serviceprotected voidCalled during the stop lifecycle phase; subclasses may override.
-
Field Details
-
log
-
cfg
Configuration applied to this bean by the container. -
scheduledThreadPoolExecutor
Lazily-allocated scheduler shared with subclasses; seegetScheduledThreadPoolExecutor().
-
-
Constructor Details
-
QBeanSupport
public QBeanSupport()Default constructor.
-
-
Method Details
-
setServer
Description copied from interface:QBeanSupportMBeanSets the Q2 server instance for this QBean.- Specified by:
setServerin interfaceQBeanSupportMBean- Parameters:
server- the Q2 server
-
getServer
Description copied from interface:QBeanSupportMBeanReturns the Q2 server instance.- Specified by:
getServerin interfaceQBeanSupportMBean- Returns:
- the Q2 server
-
getFactory
Returns theQFactoryassociated with the hosting Q2 server.- Returns:
- the server's QFactory
-
setName
Description copied from interface:QBeanSupportMBeanSets the bean name.- Specified by:
setNamein interfaceQBeanSupportMBean- Parameters:
name- the bean name
-
setLogger
Description copied from interface:QBeanSupportMBeanSets the logger by name.- Specified by:
setLoggerin interfaceQBeanSupportMBean- Parameters:
loggerName- the logger name
-
setRealm
Description copied from interface:QBeanSupportMBeanSets the logging realm.- Specified by:
setRealmin interfaceQBeanSupportMBean- Parameters:
realm- the realm string
-
getRealm
Description copied from interface:QBeanSupportMBeanReturns the logging realm.- Specified by:
getRealmin interfaceQBeanSupportMBean- Returns:
- the realm string
-
getLogger
Description copied from interface:QBeanSupportMBeanReturns the logger name.- Specified by:
getLoggerin interfaceQBeanSupportMBean- Returns:
- the logger name
-
getLog
-
defaultRealm
Returns the default realm for this bean; subclasses may override.- Returns:
- default realm string, or null
-
getName
Description copied from interface:QBeanSupportMBeanReturns the bean name.- Specified by:
getNamein interfaceQBeanSupportMBean- Returns:
- the bean name
-
init
-
start
-
stop
-
destroy
-
getState
-
getLoaderURLS
Description copied from interface:QBeanSupportMBeanReturns the URLs registered with the class loader.- Specified by:
getLoaderURLSin interfaceQBeanSupportMBean- Returns:
- array of loader URLs
-
getLoader
Description copied from interface:QBeanSupportMBeanReturns the QClassLoader for this bean.- Specified by:
getLoaderin interfaceQBeanSupportMBean- Returns:
- the class loader
-
getStateAsString
Description copied from interface:QBeanReturns the current state as a human-readable string.- Specified by:
getStateAsStringin interfaceQBean- Returns:
- state (STARTING, STARTED, FAILED, DESTROYED ...)
-
setState
Sets the lifecycle state of this bean.- Parameters:
state- one of the QBean state constants
-
setPersist
Description copied from interface:QBeanSupportMBeanSets the persistent configuration element.- Specified by:
setPersistin interfaceQBeanSupportMBean- Parameters:
persist- the configuration element
-
getPersist
Description copied from interface:QPersistReturns the persistent configuration element for this QBean.- Specified by:
getPersistin interfaceQPersist- Returns:
- the configuration element
-
setModified
Marks this bean's persistent state as modified or in sync.- Parameters:
modified-trueif the bean has unsaved changes
-
isModified
Description copied from interface:QPersistReturnstrueif this QBean's configuration has been modified since last save.- Specified by:
isModifiedin interfaceQPersist- Returns:
- true if modified
-
running
Indicates whether this bean is currently starting or running.- Returns:
trueif the state isQBean.STARTINGorQBean.STARTED
-
setConfiguration
Description copied from interface:ConfigurableConfigures this object with the suppliedConfiguration.- Specified by:
setConfigurationin interfaceConfigurable- Parameters:
cfg- Configuration object- Throws:
ConfigurationException- if the configuration is invalid
-
getConfiguration
Returns the configuration applied to this bean.- Returns:
- the bean's
Configuration, ornullif not yet configured
-
getDump
Returns a textual dump of this bean's state.If the bean implements
Loggeable, itsdumpoutput is returned; otherwise this delegates toObject.toString().- Specified by:
getDumpin interfaceQBeanSupportMBean- Returns:
- a string representation suitable for diagnostics
-
initService
Called during the init lifecycle phase; subclasses may override.- Throws:
Exception- on error
-
startService
Called during the start lifecycle phase; subclasses may override.- Throws:
Exception- on error
-
stopService
Called during the stop lifecycle phase; subclasses may override.- Throws:
Exception- on error
-
destroyService
Called during the destroy lifecycle phase; subclasses may override.- Throws:
Exception- on error
-
getScheduledThreadPoolExecutor
Lazily creates and returns aScheduledThreadPoolExecutorfor use by subclasses.- Returns:
- shared scheduled executor for this bean
-
createElement
Builds a JDOMElementreflecting the bean's persistent attributes, driven by the JavaBean introspection ofmbeanClass.- Parameters:
name- the root element namembeanClass- the MBean interface whose properties drive serialization- Returns:
- populated element ready for persistence
-
addAttr
Appends an<attr>child element with name/type/value toe.- Parameters:
e- parent elementname- attribute nameobj- value (rendered viatoString();nullbecomes the literal "null")type- optional Java type hint, ornullto omit
-
getAttrs
-
getAttrs
Iterates over<attr>children nested under the given parent element name.- Parameters:
parent- name of the parent element undergetPersist()- Returns:
- iterator over the nested attribute elements
-
setAttr
Updates the value of the named attribute within an iterator of<attr>elements.- Parameters:
attrs- iterator over candidate attribute elementsname- name of the attribute to updateobj- new value (rendered viatoString();nullbecomes "null")
-
getProperties
Iterates over<property>children nested under the given parent element name.- Parameters:
parent- name of the parent element undergetPersist()- Returns:
- iterator over the nested property elements
-
setProperty
Updates the value attribute of the named property within an iterator of<property>elements.- Parameters:
props- iterator over candidate property elementsname- name of the property to updatevalue- new value to assign
-
getProperty
Returns the value of the named property from an iterator of<property>elements.- Parameters:
props- iterator over candidate property elementsname- name of the property to look up- Returns:
- the property's value, or
nullif not found
-
close
-