KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > dq > DQMessageReceiver


1 /*
2  * $Id: DQMessageReceiver.java 3982 2006-11-22 14:28:01Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.dq;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.impl.MuleMessage;
16 import org.mule.providers.PollingMessageReceiver;
17 import org.mule.umo.UMOComponent;
18 import org.mule.umo.UMOMessage;
19 import org.mule.umo.endpoint.UMOEndpoint;
20 import org.mule.umo.lifecycle.InitialisationException;
21 import org.mule.umo.provider.UMOConnector;
22
23 import com.ibm.as400.access.AS400;
24 import com.ibm.as400.access.DataQueue;
25 import com.ibm.as400.access.DataQueueEntry;
26 import com.ibm.as400.access.RecordFormat;
27
28 /**
29  * DQMessageReceiver TODO document
30  */

31 public class DQMessageReceiver extends PollingMessageReceiver
32 {
33     private DataQueue dataQueue = null;
34     private RecordFormat format = null;
35
36     public DQMessageReceiver(UMOConnector connector,
37                              UMOComponent component,
38                              UMOEndpoint endpoint,
39                              Long JavaDoc frequency,
40                              DataQueue pDq,
41                              AS400 pAs400) throws InitialisationException
42     {
43         super(connector, component, endpoint, frequency);
44
45         this.dataQueue = pDq;
46
47         String JavaDoc recordDescriptor = (String JavaDoc)endpoint.getEndpointURI().getParams().get(
48             DQConnector.RECORD_DESCRIPTOR_PROPERTY);
49         if (recordDescriptor == null)
50         {
51             format = ((DQConnector)connector).getFormat();
52             if (format == null)
53             {
54                 throw new InitialisationException(new Message("dq", 1), this);
55             }
56         }
57         else
58         {
59             try
60             {
61                 format = DQMessageUtils.getRecordFormat(recordDescriptor, pAs400);
62             }
63             catch (Exception JavaDoc e)
64             {
65                 throw new InitialisationException(new Message(Messages.FAILED_LOAD_X, "recordDescriptor: "
66                                                                                       + recordDescriptor), e,
67                     this);
68             }
69         }
70     }
71
72     /**
73      * @see org.mule.providers.PollingMessageReceiver#poll()
74      */

75     public final void poll()
76     {
77         try
78         {
79             DataQueueEntry entry = dataQueue.read();
80
81             if (entry == null)
82             {
83                 return;
84             }
85
86             processEntry(entry);
87
88         }
89         catch (Exception JavaDoc e)
90         {
91             handleException(e);
92         }
93
94     }
95
96     /**
97      * Process a received message entry
98      *
99      * @param entry The entry
100      * @throws Exception Error during process
101      */

102     private void processEntry(final DataQueueEntry entry) throws Exception JavaDoc
103     {
104         DQMessage message = DQMessageUtils.getDQMessage(entry.getData(), format);
105         message.setSenderInformation(entry.getSenderInformation());
106
107         UMOMessage umoMessage = new MuleMessage(connector.getMessageAdapter(message));
108         routeMessage(umoMessage);
109     }
110
111     public void doConnect() throws Exception JavaDoc
112     {
113         // template method
114
}
115
116     public void doDisconnect() throws Exception JavaDoc
117     {
118         // template method
119
}
120
121 }
122
Popular Tags