net.sf.xbus.technical
Class ReceiverThreadBase

java.lang.Object
  extended by net.sf.xbus.technical.ReceiverThreadBase
All Implemented Interfaces:
java.lang.Runnable, Receiver
Direct Known Subclasses:
FileReceiverThread, MQReceiverThread, POP3XMLReceiverThread

public abstract class ReceiverThreadBase
extends java.lang.Object
implements java.lang.Runnable, Receiver

Classes implementing the ReceiverThreadBase are running as background threads to process messages when they arrive. These classes are executed by the ReceiverService.


Field Summary
protected static int DEFAULT_ERROR_TIMEOUT
          Default for the time to wait after an error has occured.
protected static int DEFAULT_TIMEOUT
          Default for the time to wait after the successful processing of a message.
 
Constructor Summary
ReceiverThreadBase(XBUSSystem source)
          Stores the interface name
 
Method Summary
protected  boolean checkProceed()
          Returns a boolean value that indicates whether the thread shall continue to process messages.
protected abstract  java.lang.String getAddress()
          Returns the address of a received message, used for example in the tracing.
protected  long getErrorTimeout()
          Returns the time to wait after an error has occured.
protected abstract  java.lang.String getReceiverClassName()
          Returns the name of the receiver class, used for example to determine values in the configuration.
protected  XBUSSystem getSource()
          Returns the source of the messages.
protected  long getTimeout()
          Returns the time to wait after the successful processing of a message.
protected  void incrementErrorCounter()
          Increments the error counter.
protected  void initializeErrorCounter()
          Initializes the error counter to 0.
protected abstract  void initializeThread()
          Initialization of the the thread, called in the beginning, before the loop for processing messages starts.
 void interruptThread()
          interruptThread shall interrupt the loop of receiving and processing messages and cause the thread to stop.
protected abstract  java.lang.Object receive()
          Receives one message.
protected abstract  void registerResources(TAManager taManager)
          Because the thread clears the list of transactional resources each time after processing a message, this method is called before reading the next message to register a receiver resource in the transaction manager.
 void run()
          Receives and processes messages for one system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.xbus.technical.Receiver
getType
 

Field Detail

DEFAULT_ERROR_TIMEOUT

protected static final int DEFAULT_ERROR_TIMEOUT
Default for the time to wait after an error has occured.

See Also:
Constant Field Values

DEFAULT_TIMEOUT

protected static final int DEFAULT_TIMEOUT
Default for the time to wait after the successful processing of a message.

See Also:
Constant Field Values
Constructor Detail

ReceiverThreadBase

public ReceiverThreadBase(XBUSSystem source)
Stores the interface name

Parameters:
source - name of the interface definition
Method Detail

run

public void run()
Receives and processes messages for one system. It is running until either the thread shall be stopped on demand or until a configurable amount of errors has occured, without a successful processed message between it.

Specified by:
run in interface java.lang.Runnable

initializeThread

protected abstract void initializeThread()
                                  throws XException
Initialization of the the thread, called in the beginning, before the loop for processing messages starts. Used e.g. for opening a connection.

Throws:
XException - if something goes wrong

registerResources

protected abstract void registerResources(TAManager taManager)
                                   throws XException
Because the thread clears the list of transactional resources each time after processing a message, this method is called before reading the next message to register a receiver resource in the transaction manager.

Parameters:
taManager - the transaction manager in which the resources shall be registered
Throws:
XException - if something goes wrong

receive

protected abstract java.lang.Object receive()
                                     throws XException
Receives one message.

Returns:
the received message or null when no message has been available
Throws:
XException - if something goes wrong

getReceiverClassName

protected abstract java.lang.String getReceiverClassName()
Returns the name of the receiver class, used for example to determine values in the configuration.

Returns:
the name of the receiver class

getAddress

protected abstract java.lang.String getAddress()
Returns the address of a received message, used for example in the tracing. The content of the address depends on the type of receiver. FileReceivers will return filenames, the POP3Receiver will return an email address.

Returns:
the address of a received message

interruptThread

public void interruptThread()
interruptThread shall interrupt the loop of receiving and processing messages and cause the thread to stop. It is invoked by the ReceiverServiceon shutdown or restart.


checkProceed

protected boolean checkProceed()
Returns a boolean value that indicates whether the thread shall continue to process messages.

Returns:
a boolean value that indicates whether the thread shall continue to process messages

incrementErrorCounter

protected void incrementErrorCounter()
Increments the error counter.


initializeErrorCounter

protected void initializeErrorCounter()
Initializes the error counter to 0.


getSource

protected XBUSSystem getSource()
Returns the source of the messages.

Returns:
the source of the messages

getErrorTimeout

protected long getErrorTimeout()
Returns the time to wait after an error has occured. The value is read out of the configuration, either a default for all receivers or a value specific for the current source. If no value is specified in the configuration, a hard coded default is used.

Returns:
the time to wait after an error has occured

getTimeout

protected long getTimeout()
Returns the time to wait after the successful processing of a message. The value is read out of the configuration, either a default for the receiver class or a value specific for the current source. If no value is specified in the configuration, a hard coded default is used.

Returns:
the time to wait after the successful processing of a message