org.spicefactory.cinnamon.io
Interface MessageProcessor<I,O>

All Known Implementing Classes:
KeepAliveMessageProcessor, ServiceMessageProcessor

public interface MessageProcessor<I,O>

A MessageProcessor implementation is responsible for processing the request object and returning a result instance. Implementations should be stateless since they will be reused for multiple requests. The two type parameters represent the classes used for the request and the response message respectively. Cinnamon comes with two default implementations which will be added automatically to the configuration: ServiceRequestMessageProcessor and KeepAliveMessageProcessor. The former is repsonsible for processing regular service invocation requests while the latter handles simple keep-alive messages sent from a client-side ServiceChannel. You can replace the default implementations with custom implementations or create completely new message types and their corresponding handlers. In the latter case you'd have to use a custom ServiceInvocationHandler on the client side that produces the new message type.

Author:
Jens Halm

Nested Class Summary
static class MessageProcessor.ResultHolder<O>
          Represents a single result produced by a MessageProcessor.
 
Method Summary
 MessageProcessor.ResultHolder<O> processException(I request, Exception e)
          Processes the specified Exception and returns a result to be sent to the client.
 MessageProcessor.ResultHolder<O> processMessage(I request)
          Processes the given request instance and returns a result.
 

Method Detail

processMessage

MessageProcessor.ResultHolder<O> processMessage(I request)
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.

Parameters:
request - the object representing the request
Returns:
a ResultHolder instance containing the result to be sent to the client

processException

MessageProcessor.ResultHolder<O> processException(I request,
                                                  Exception e)
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.

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