1 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 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 frequency, 40 DataQueue pDq, 41 AS400 pAs400) throws InitialisationException 42 { 43 super(connector, component, endpoint, frequency); 44 45 this.dataQueue = pDq; 46 47 String recordDescriptor = (String )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 e) 64 { 65 throw new InitialisationException(new Message(Messages.FAILED_LOAD_X, "recordDescriptor: " 66 + recordDescriptor), e, 67 this); 68 } 69 } 70 } 71 72 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 e) 90 { 91 handleException(e); 92 } 93 94 } 95 96 102 private void processEntry(final DataQueueEntry entry) throws Exception 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 112 { 113 } 115 116 public void doDisconnect() throws Exception 117 { 118 } 120 121 } 122 | Popular Tags |