View Javadoc

1   package se.citerus.dddsample.infrastructure.messaging.jms;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import se.citerus.dddsample.application.HandlingEventService;
6   import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
7   
8   import javax.jms.Message;
9   import javax.jms.MessageListener;
10  import javax.jms.ObjectMessage;
11  
12  /**
13   * Consumes handling event registration attempt messages and delegates to
14   * proper registration.
15   * 
16   */
17  public class HandlingEventRegistrationAttemptConsumer implements MessageListener {
18  
19    private HandlingEventService handlingEventService;
20    private static final Log logger = LogFactory.getLog(HandlingEventRegistrationAttemptConsumer.class);
21  
22    @Override
23    public void onMessage(final Message message) {
24      try {
25        final ObjectMessage om = (ObjectMessage) message;
26        HandlingEventRegistrationAttempt attempt = (HandlingEventRegistrationAttempt) om.getObject();
27        handlingEventService.registerHandlingEvent(
28          attempt.getCompletionTime(),
29          attempt.getTrackingId(),
30          attempt.getVoyageNumber(),
31          attempt.getUnLocode(),
32          attempt.getType()
33        );
34      } catch (Exception e) {
35        logger.error(e, e);
36      }
37    }
38  
39    public void setHandlingEventService(HandlingEventService handlingEventService) {
40      this.handlingEventService = handlingEventService;
41    }
42  
43  }