I started to build a messaging framework and I decided to use the decoration pattern for creating JMSMessages.
class BaseMessage implements Message { ... }
Abstract decoration
class AbstractDecoration implements Message {
Message message;
public AbstractDecoration(Message message) {
this.message = message
}
}
Decoration example:
class JsonPayloadDecoration extends AbstractDecoration { ... }
Usage example:
...
IMessage m = new BaseMessage(...);
m = new ExpireDecoration(m, 10, TimeUnit.MINUTES);
m = new TextPayloadDecoration(m, "Text!");
m = new CorrelationDecoration(m, "123456");
m = new PriorityDecoration(m, 9);
m = new NonPersistentDecoration(m);
m = new QueueDestinationDecoration(m, "JMSTEST.DECORATIONTEST1");
m = new ErrorHandlerDecoration(m, errorhandler, 1000);
// requestor handles MessageProducers
// m.send will create the real JMSMessage and use the requestor
// to send the message with a MessageProducer
m.send(requestor);
At first I would like to get some input about the whole decoration idea and now to my real question. The errorhandler
of ErrorHandlerDecoration
has a timeout. When should the timeout
start? When it's created or when m.send
is called? I am arguing with my colleagues about that.