Class JdbcListener<M>

Type Parameters:
M - MessageWrapper or key. Key is also used as messageId
All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, IConfigurable, IHasProcessState<M>, IListener<M>, IPeekableListener<M>, IPullingListener<M>, IScopeProvider, IXAEnabled, NameAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle
Direct Known Subclasses:
JdbcQueryListener, JdbcTableListener

public class JdbcListener<M> extends JdbcFacade implements IPeekableListener<M>, IHasProcessState<M>
JdbcListener base class.
Since:
4.7
Author:
Gerrit van Brakel
  • Field Details

  • Constructor Details

    • JdbcListener

      public JdbcListener()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      Description copied from interface: IConfigurable
      Configure this component.

      configure() is called once at startup of the framework in the configure method of the owner of this IConfigurable. Purpose of this method is to check whether the static configuration of the object is correct. As much as possible class-instantiating should take place in the configure(), to improve performance.

      In the case of a container, this will propagate the configure signal to all components that apply.

      Specified by:
      configure in interface IConfigurable
      Overrides:
      configure in class JdbcFacade
      Throws:
      ConfigurationException - in case it was not able to configure the component.
    • start

      public void start()
      Description copied from interface: IListener
      Prepares the listener for receiving messages. start() is called once each time the listener is started.
      Specified by:
      start in interface IListener<M>
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Overrides:
      start in class JdbcFacade
    • stop

      public void stop()
      Description copied from interface: IListener
      Close all resources used for listening. Called once each time the listener is stopped.
      Specified by:
      stop in interface IListener<M>
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Overrides:
      stop in class JdbcFacade
    • openThread

      @Nonnull public Map<String,Object> openThread() throws ListenerException
      Description copied from interface: IPullingListener
      Prepares a thread for receiving messages. Called once for each thread that will listen for messages.
      Specified by:
      openThread in interface IPullingListener<M>
      Returns:
      the threadContext for this thread. The threadContext is a Map in which thread-specific data can be stored. May not be null, must be a mutable map type.
      Throws:
      ListenerException
    • closeThread

      public void closeThread(@Nonnull Map<String,Object> threadContext) throws ListenerException
      Description copied from interface: IPullingListener
      Finalizes a message receiving thread. Called once for each thread that listens for messages, just before IListener.stop() is called.
      Specified by:
      closeThread in interface IPullingListener<M>
      Throws:
      ListenerException
    • hasRawMessageAvailable

      public boolean hasRawMessageAvailable() throws ListenerException
      Specified by:
      hasRawMessageAvailable in interface IPeekableListener<M>
      Throws:
      ListenerException
    • hasRawMessageAvailable

      protected boolean hasRawMessageAvailable(Connection conn) throws ListenerException
      Throws:
      ListenerException
    • getRawMessage

      public RawMessageWrapper<M> getRawMessage(@Nonnull Map<String,Object> threadContext) throws ListenerException
      Description copied from interface: IPullingListener
      Retrieves messages from queue or other channel, but does no processing on it. Multiple objects may try to call this method at the same time, from different threads. Implementations of this method should therefore be thread-safe, or synchronized.

      Any thread-specific properties should be stored in and retrieved from the threadContext.

      Specified by:
      getRawMessage in interface IPullingListener<M>
      Throws:
      ListenerException
    • getRawMessage

      protected RawMessageWrapper<M> getRawMessage(Connection conn, Map<String,Object> threadContext) throws ListenerException
      Throws:
      ListenerException
    • extractRawMessage

      protected RawMessageWrapper<M> extractRawMessage(ResultSet rs) throws JdbcException
      This method returns a MessageWrapper containing contents of the message stored in the database.
      Parameters:
      rs - JDBC ResultSet from which to extract message data.
      Returns:
      Either a String being the message key, or a MessageWrapper. The message key as String is returned if messageField, messageIdField and correlationIdField all are not set. If messageIdField and / or correlationIdField are set but messageField is not, then the message key is returned as value of a Message wrapped in a MessageWrapper. Otherwise the message is loaded from the rs parameter and returned wrapped in a MessageWrapper.
      Throws:
      JdbcException - If loading the message resulted in a database exception.
    • getKeyFromRawMessage

      protected String getKeyFromRawMessage(RawMessageWrapper<M> rawMessage) throws ListenerException
      Throws:
      ListenerException
    • extractMessage

      public Message extractMessage(@Nonnull RawMessageWrapper<M> rawMessage, @Nonnull Map<String,Object> context) throws ListenerException
      Description copied from interface: IListener
      Extracts data from message obtained from IPullingListener.getRawMessage(Map) or IPushingListener.wrapRawMessage(Object, PipeLineSession). May also extract other parameters from the message and put those into the context.
      Specified by:
      extractMessage in interface IListener<M>
      Parameters:
      rawMessage - The RawMessageWrapper from which to extract the Message.
      context - Context to populate. Either a PipeLineSession or a Map threadContext depending on caller.
      Returns:
      input Message for adapter.
      Throws:
      ListenerException
    • afterMessageProcessed

      public void afterMessageProcessed(PipeLineResult processResult, RawMessageWrapper<M> rawMessage, PipeLineSession pipeLineSession) throws ListenerException
      Description copied from interface: IListener
      Called to perform actions (like committing or sending a reply) after a message has been processed by the Pipeline.
      Specified by:
      afterMessageProcessed in interface IListener<M>
      Throws:
      ListenerException
    • knownProcessStates

      public Set<ProcessState> knownProcessStates()
      Description copied from interface: IHasProcessState
      Provides the set of ProcessStates used by this listener.
      Specified by:
      knownProcessStates in interface IHasProcessState<M>
    • targetProcessStates

      public Map<ProcessState,Set<ProcessState>> targetProcessStates()
      Description copied from interface: IHasProcessState
      Provides the set of ProcessStates that a message in the specified state can be moved to, e.g. from a MessageBrowser for that state.
      Specified by:
      targetProcessStates in interface IHasProcessState<M>
    • changeProcessState

      public RawMessageWrapper<M> changeProcessState(RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) throws ListenerException
      Description copied from interface: IHasProcessState
      Change the processState of the message to the specified state, if that state is supported. If it is not supported, nothing changes, and false is returned.
      Specified by:
      changeProcessState in interface IHasProcessState<M>
      Returns:
      the moved message, or null if no message was moved.
      Throws:
      ListenerException
    • changeProcessState

      protected RawMessageWrapper<M> changeProcessState(Connection connection, RawMessageWrapper<M> rawMessage, ProcessState toState, String reason) throws ListenerException
      Throws:
      ListenerException
    • execute

      protected boolean execute(Connection conn, String query, List<String> parameters) throws ListenerException
      Throws:
      ListenerException
    • convertQuery

      protected String convertQuery(String query) throws SQLException, DbmsException
      Throws:
      SQLException
      DbmsException
    • setUpdateStatusQuery

      protected void setUpdateStatusQuery(ProcessState state, String query)
    • getUpdateStatusQuery

      public String getUpdateStatusQuery(ProcessState state)
    • setSelectQuery

      protected void setSelectQuery(String string)
    • setPeekUntransacted

      public void setPeekUntransacted(boolean b)
      Description copied from interface: IPeekableListener
      when true, then PollingListener container will execute getRawMessage() only when hasRawMessageAvailable() has returned true. This avoids rolling back a lot of XA transactions, that appears to be problematic on MS SQL Server
      Specified by:
      setPeekUntransacted in interface IPeekableListener<M>
    • setPeekQuery

      public void setPeekQuery(String string)
      (only used when peekUntransacted=true) peek query to determine if the select query should be executed. Peek queries are, unlike select queries, executed without a transaction and without a rowlock
      Default value
      selectQuery
    • setKeyField

      public void setKeyField(String fieldname)
      Primary key field of the table, used to identify and differentiate messages. NB: there should be an index on this field!
    • setMessageField

      public void setMessageField(String fieldname)
      Field containing the message data
      Default value
      same as keyField
    • setMessageFieldType

      public void setMessageFieldType(JdbcListener.MessageFieldType value)
      Type of the field containing the message data
      Default value
      String
    • setMessageIdField

      public void setMessageIdField(String fieldname)
      Field containing the messageId. NB: If this column is not set the default (primary key) keyField will be used as messageId!
      Default value
      same as keyField
    • setCorrelationIdField

      public void setCorrelationIdField(String fieldname)
      Field containing the correlationId. NB: If this column is not set, the messageId and correlationId will be the same!
      Default value
      same as messageIdField
    • setSqlDialect

      public void setSqlDialect(String string)
      If set, the SQL dialect in which the queries are written and should be translated from to the actual SQL dialect
    • setBlobsCompressed

      public void setBlobsCompressed(boolean b)
      Controls whether BLOB is considered stored compressed in the database
      Default value
      true
    • setBlobCharset

      @Deprecated(forRemoval=true, since="7.6.0") public void setBlobCharset(String string)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Charset used to read BLOB. When specified, then the BLOB will be converted into a string
    • setBlobSmartGet

      public void setBlobSmartGet(boolean b)
      Controls automatically whether blobdata is stored compressed and/or serialized in the database. N.B. When set true, then the BLOB will be converted into a string
      Default value
      false
    • getSelectQuery

      public String getSelectQuery()
    • getPeekQuery

      public String getPeekQuery()
    • getKeyField

      public String getKeyField()
    • getMessageField

      public String getMessageField()
    • getMessageIdField

      public String getMessageIdField()
    • getCorrelationIdField

      public String getCorrelationIdField()
    • getMessageFieldType

      public JdbcListener.MessageFieldType getMessageFieldType()
    • getSqlDialect

      public String getSqlDialect()
    • getBlobCharset

      public String getBlobCharset()
    • isBlobsCompressed

      public boolean isBlobsCompressed()
    • isBlobSmartGet

      public boolean isBlobSmartGet()
    • setTrace

      public void setTrace(boolean trace)
    • isTrace

      public boolean isTrace()
    • isPeekUntransacted

      public boolean isPeekUntransacted()
      Specified by:
      isPeekUntransacted in interface IPeekableListener<M>