org.spicefactory.cinnamon.service
Class ServiceMessageProcessor

java.lang.Object
  extended by org.spicefactory.cinnamon.service.ServiceMessageProcessor
All Implemented Interfaces:
MessageProcessor<ServiceRequest,ServiceResponse>
Direct Known Subclasses:
PimentoMessageProcessor

public class ServiceMessageProcessor
extends Object
implements MessageProcessor<ServiceRequest,ServiceResponse>

The main MessageProcessor implementation that processes ServiceRequest instances and returns ServiceResponse instances. This mechanism represents the default RPC semantics in Cinnamon.

Author:
Jens Halm

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.spicefactory.cinnamon.io.MessageProcessor
MessageProcessor.ResultHolder<O>
 
Constructor Summary
ServiceMessageProcessor(CinnamonConfig config)
          Creates a new ServiceMessageProcessor.
 
Method Summary
 boolean isFailFast()
          Indicates whether this message processor should apply fail fast behaviour in case of errors.
protected  void logRequest(ServiceRequest request)
           
protected  void logResult(ServiceRequest request, ServiceResponse response)
           
 MessageProcessor.ResultHolder<ServiceResponse> processException(ServiceRequest request, Exception e)
          Processes the specified Exception and returns a result to be sent to the client.
 MessageProcessor.ResultHolder<ServiceResponse> processMessage(ServiceRequest request)
          Processes the given request instance and returns a result.
 void setFailFast(boolean failFast)
          Set whether this message processor should apply fail fast behaviour in case of errors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceMessageProcessor

public ServiceMessageProcessor(CinnamonConfig config)
Creates a new ServiceMessageProcessor.

Parameters:
config - the Cinnamon configuration instance to use
Method Detail

isFailFast

public boolean isFailFast()
Indicates whether this message processor should apply fail fast behaviour in case of errors.

Returns:
true if this message processor should apply fail fast behaviour in case of errors
See Also:
MessageProcessor.processMessage(I)

setFailFast

public void setFailFast(boolean failFast)
Set whether this message processor should apply fail fast behaviour in case of errors

Parameters:
failFast - indicates whether this message processor should apply fail fast behaviour in case of errors
See Also:
MessageProcessor.processMessage(I)

processMessage

public MessageProcessor.ResultHolder<ServiceResponse> processMessage(ServiceRequest request)
Description copied from interface: MessageProcessor
Processes the given request instance and returns a result. The returned ResultHolder instance holds the actual result instance and a boolean property indicating whether the result represents an error outcome. A message processor may also decide to throw an Exception instead of returning a result representing an error. In this case fail fast behaviour will be applied: The processing of subsequent messages in the same request will be prevented and all messages that were already processed will be reprocessed with the processException method. This may be useful if some kind of transactional behaviour needs to be applied to a batch of method invocations.

Specified by:
processMessage in interface MessageProcessor<ServiceRequest,ServiceResponse>
Parameters:
request - the object representing the request
Returns:
a ResultHolder instance containing the result to be sent to the client

processException

public MessageProcessor.ResultHolder<ServiceResponse> processException(ServiceRequest request,
                                                                       Exception e)
Description copied from interface: MessageProcessor
Processes the specified Exception and returns a result to be sent to the client. When this method gets invoked it is possible that the processMessage method has already been invoked for the same request message. This method will be invoked when an Exception occured before or after processing the message (probably in a PhaseListener method. In this case a corresponding message should be returned to the client even if the original message processing succeeded.

Specified by:
processException in interface MessageProcessor<ServiceRequest,ServiceResponse>
Parameters:
request - the object representing the request
e - the Exception that was thrown before or after processing the specified message
Returns:
a ResultHolder instance containing the result to be sent to the client

logRequest

protected void logRequest(ServiceRequest request)

logResult

protected void logResult(ServiceRequest request,
                         ServiceResponse response)