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 Details

  • Constructor Details

  • Method Details

    • setServer

      public void setServer(Q2 server)
      Description copied from interface: QBeanSupportMBean
      Sets the Q2 server instance for this QBean.
      Specified by:
      setServer in interface QBeanSupportMBean
      Parameters:
      server - the Q2 server
    • getServer

      public Q2 getServer()
      Description copied from interface: QBeanSupportMBean
      Returns the Q2 server instance.
      Specified by:
      getServer in interface QBeanSupportMBean
      Returns:
      the Q2 server
    • getFactory

      public QFactory getFactory()
      Returns the QFactory associated with the hosting Q2 server.
      Returns:
      the server's QFactory
    • setName

      public void setName(String name)
      Description copied from interface: QBeanSupportMBean
      Sets the bean name.
      Specified by:
      setName in interface QBeanSupportMBean
      Parameters:
      name - the bean name
    • setLogger

      public void setLogger(String loggerName)
      Description copied from interface: QBeanSupportMBean
      Sets the logger by name.
      Specified by:
      setLogger in interface QBeanSupportMBean
      Parameters:
      loggerName - the logger name
    • setRealm

      public void setRealm(String realm)
      Description copied from interface: QBeanSupportMBean
      Sets the logging realm.
      Specified by:
      setRealm in interface QBeanSupportMBean
      Parameters:
      realm - the realm string
    • getRealm

      public String getRealm()
      Description copied from interface: QBeanSupportMBean
      Returns the logging realm.
      Specified by:
      getRealm in interface QBeanSupportMBean
      Returns:
      the realm string
    • getLogger

      public String getLogger()
      Description copied from interface: QBeanSupportMBean
      Returns the logger name.
      Specified by:
      getLogger in interface QBeanSupportMBean
      Returns:
      the logger name
    • getLog

      public Log getLog()
      Returns the Log used by this bean.
      Returns:
      the configured log instance, or null if logging has not been initialized
    • defaultRealm

      protected String defaultRealm()
      Returns the default realm for this bean; subclasses may override.
      Returns:
      default realm string, or null
    • getName

      public String getName()
      Description copied from interface: QBeanSupportMBean
      Returns the bean name.
      Specified by:
      getName in interface QBeanSupportMBean
      Returns:
      the bean name
    • init

      public void init()
      Description copied from interface: QBean
      init the service
      Specified by:
      init in interface QBean
    • start

      public void start()
      Description copied from interface: QBean
      start the service
      Specified by:
      start in interface QBean
    • stop

      public void stop()
      Description copied from interface: QBean
      stop the service
      Specified by:
      stop in interface QBean
    • destroy

      public void destroy()
      Description copied from interface: QBean
      destroy the service
      Specified by:
      destroy in interface QBean
    • getState

      public int getState()
      Description copied from interface: QBean
      Returns the current state of this QBean.
      Specified by:
      getState in interface QBean
      Returns:
      state (STARTING, STARTED, FAILED, DESTROYED ...)
    • getLoaderURLS

      public URL[] getLoaderURLS()
      Description copied from interface: QBeanSupportMBean
      Returns the URLs registered with the class loader.
      Specified by:
      getLoaderURLS in interface QBeanSupportMBean
      Returns:
      array of loader URLs
    • getLoader

      Description copied from interface: QBeanSupportMBean
      Returns the QClassLoader for this bean.
      Specified by:
      getLoader in interface QBeanSupportMBean
      Returns:
      the class loader
    • getStateAsString

      Description copied from interface: QBean
      Returns the current state as a human-readable string.
      Specified by:
      getStateAsString in interface QBean
      Returns:
      state (STARTING, STARTED, FAILED, DESTROYED ...)
    • setState

      public void setState(int state)
      Sets the lifecycle state of this bean.
      Parameters:
      state - one of the QBean state constants
    • setPersist

      public void setPersist(org.jdom2.Element persist)
      Description copied from interface: QBeanSupportMBean
      Sets the persistent configuration element.
      Specified by:
      setPersist in interface QBeanSupportMBean
      Parameters:
      persist - the configuration element
    • getPersist

      public org.jdom2.Element getPersist()
      Description copied from interface: QPersist
      Returns the persistent configuration element for this QBean.
      Specified by:
      getPersist in interface QPersist
      Returns:
      the configuration element
    • setModified

      public void setModified(boolean modified)
      Marks this bean's persistent state as modified or in sync.
      Parameters:
      modified - true if the bean has unsaved changes
    • isModified

      public boolean isModified()
      Description copied from interface: QPersist
      Returns true if this QBean's configuration has been modified since last save.
      Specified by:
      isModified in interface QPersist
      Returns:
      true if modified
    • running

      public boolean running()
      Indicates whether this bean is currently starting or running.
      Returns:
      true if the state is QBean.STARTING or QBean.STARTED
    • setConfiguration

      Description copied from interface: Configurable
      Configures this object with the supplied Configuration.
      Specified by:
      setConfiguration in interface Configurable
      Parameters:
      cfg - Configuration object
      Throws:
      ConfigurationException - if the configuration is invalid
    • getConfiguration

      Returns the configuration applied to this bean.
      Returns:
      the bean's Configuration, or null if not yet configured
    • getDump

      public String getDump()
      Returns a textual dump of this bean's state.

      If the bean implements Loggeable, its dump output is returned; otherwise this delegates to Object.toString().

      Specified by:
      getDump in interface QBeanSupportMBean
      Returns:
      a string representation suitable for diagnostics
    • initService

      protected void initService() throws Exception
      Called during the init lifecycle phase; subclasses may override.
      Throws:
      Exception - on error
    • startService

      protected void startService() throws Exception
      Called during the start lifecycle phase; subclasses may override.
      Throws:
      Exception - on error
    • stopService

      protected void stopService() throws Exception
      Called during the stop lifecycle phase; subclasses may override.
      Throws:
      Exception - on error
    • destroyService

      protected void destroyService() throws Exception
      Called during the destroy lifecycle phase; subclasses may override.
      Throws:
      Exception - on error
    • getScheduledThreadPoolExecutor

      Lazily creates and returns a ScheduledThreadPoolExecutor for use by subclasses.
      Returns:
      shared scheduled executor for this bean
    • createElement

      protected org.jdom2.Element createElement(String name, Class mbeanClass)
      Builds a JDOM Element reflecting the bean's persistent attributes, driven by the JavaBean introspection of mbeanClass.
      Parameters:
      name - the root element name
      mbeanClass - the MBean interface whose properties drive serialization
      Returns:
      populated element ready for persistence
    • addAttr

      protected void addAttr(org.jdom2.Element e, String name, Object obj, String type)
      Appends an <attr> child element with name/type/value to e.
      Parameters:
      e - parent element
      name - attribute name
      obj - value (rendered via toString(); null becomes the literal "null")
      type - optional Java type hint, or null to omit
    • getAttrs

      protected Iterator getAttrs()
      Iterates over top-level <attr> children of the persisted element.
      Returns:
      iterator over the persisted attribute elements
    • getAttrs

      protected Iterator getAttrs(String parent)
      Iterates over <attr> children nested under the given parent element name.
      Parameters:
      parent - name of the parent element under getPersist()
      Returns:
      iterator over the nested attribute elements
    • setAttr

      protected void setAttr(Iterator attrs, String name, Object obj)
      Updates the value of the named attribute within an iterator of <attr> elements.
      Parameters:
      attrs - iterator over candidate attribute elements
      name - name of the attribute to update
      obj - new value (rendered via toString(); null becomes "null")
    • getProperties

      protected Iterator getProperties(String parent)
      Iterates over <property> children nested under the given parent element name.
      Parameters:
      parent - name of the parent element under getPersist()
      Returns:
      iterator over the nested property elements
    • setProperty

      protected void setProperty(Iterator props, String name, String value)
      Updates the value attribute of the named property within an iterator of <property> elements.
      Parameters:
      props - iterator over candidate property elements
      name - name of the property to update
      value - new value to assign
    • getProperty

      protected String getProperty(Iterator props, String name)
      Returns the value of the named property from an iterator of <property> elements.
      Parameters:
      props - iterator over candidate property elements
      name - name of the property to look up
      Returns:
      the property's value, or null if not found
    • close

      protected void close(Closeable... closeables)
      Closes a sequence of Closeable resources, logging any failures as a warning.
      Parameters:
      closeables - resources to close (each is closed independently of the others)