org.springframework.batch.item.jms
Class JmsItemReader

java.lang.Object
  extended by org.springframework.batch.item.AbstractItemReader
      extended by org.springframework.batch.item.jms.JmsItemReader
All Implemented Interfaces:
FailedItemIdentifier, ItemKeyGenerator, ItemReader, ItemRecoverer

public class JmsItemReader
extends AbstractItemReader
implements ItemRecoverer, ItemKeyGenerator, FailedItemIdentifier

An ItemReader for JMS using a JmsTemplate. The template should have a default destination, which will be used to provide items in read(). If a recovery step is needed, set the error destination and the item will be sent there if processing fails in an external retry.

Author:
Dave Syer

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
JmsItemReader()
           
 
Method Summary
 Object getKey(Object item)
          If the message is a Message then returns the JMS message ID.
 boolean hasFailed(Object item)
          If the item is a message, check the JMS redelivered flag, otherwise return true to be on the safe side.
 Object read()
          Reads a piece of input data and advance to the next one.
 boolean recover(Object item, Throwable cause)
          Send the message back to the proovider using the specified error destination property of this provider.
 void setErrorDestination(Destination errorDestination)
          Set the error destination.
 void setErrorDestinationName(String errorDestinationName)
          Set the error destination by name.
 void setItemType(Class itemType)
          Set the expected type of incoming message payloads.
 void setJmsTemplate(JmsOperations jmsTemplate)
          Setter for jms template.
 
Methods inherited from class org.springframework.batch.item.AbstractItemReader
mark, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.commons.logging.Log logger
Constructor Detail

JmsItemReader

public JmsItemReader()
Method Detail

setErrorDestination

public void setErrorDestination(Destination errorDestination)
Set the error destination. Should not be the same as the default destination of the jms template.

Parameters:
errorDestination - a JMS Destination

setErrorDestinationName

public void setErrorDestinationName(String errorDestinationName)
Set the error destination by name. Will be resolved by the destination resolver in the jms template.

Parameters:
errorDestinationName - the name of a JMS Destination

setJmsTemplate

public void setJmsTemplate(JmsOperations jmsTemplate)
Setter for jms template.

Parameters:
jmsTemplate - a JmsOperations instance

setItemType

public void setItemType(Class itemType)
Set the expected type of incoming message payloads. Set this to Message to receive the raw underlying message.

Parameters:
itemType - the java class of the items to be delivered.
Throws:
IllegalStateException - if the message payload is of the wrong type.

read

public Object read()
Description copied from interface: ItemReader
Reads a piece of input data and advance to the next one. Implementations must return null at the end of the input data set. In a transactional setting, caller might get the same item twice from successive calls (or otherwise), if the first call was in a transaction that rolled back.

Specified by:
read in interface ItemReader

recover

public boolean recover(Object item,
                       Throwable cause)
Send the message back to the proovider using the specified error destination property of this provider.

Specified by:
recover in interface ItemRecoverer
Parameters:
item - the item that failed.
cause - the cause of the failure that led to this recovery.
Returns:
true if recovery was successful.
See Also:
ItemRecoverer.recover(Object, Throwable)

getKey

public Object getKey(Object item)
If the message is a Message then returns the JMS message ID. Otherwise just delegate to parent class.

Specified by:
getKey in interface ItemKeyGenerator
Parameters:
item - the current item.
Returns:
a unique identifier.
Throws:
UnexpectedInputException - if the JMS id cannot be determined from a JMS Message
See Also:
ItemKeyGenerator.getKey(java.lang.Object)

hasFailed

public boolean hasFailed(Object item)
If the item is a message, check the JMS redelivered flag, otherwise return true to be on the safe side.

Specified by:
hasFailed in interface FailedItemIdentifier
Parameters:
item - the current item.
Returns:
true if the item has been seen before and is known to have failed processing.
See Also:
FailedItemIdentifier.hasFailed(java.lang.Object)


Copyright © 2008 SpringSource. All Rights Reserved.