1 10 11 package org.mule.providers.dq; 12 13 import org.mule.impl.MuleMessage; 14 import org.mule.providers.AbstractMessageDispatcher; 15 import org.mule.umo.UMOEvent; 16 import org.mule.umo.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.umo.endpoint.UMOEndpointURI; 19 import org.mule.umo.endpoint.UMOImmutableEndpoint; 20 21 import com.ibm.as400.access.AS400; 22 import com.ibm.as400.access.DataQueue; 23 import com.ibm.as400.access.DataQueueEntry; 24 import com.ibm.as400.access.Record; 25 import com.ibm.as400.access.RecordFormat; 26 27 30 public class DQMessageDispatcher extends AbstractMessageDispatcher 31 { 32 private final DQConnector connector; 33 34 39 public DQMessageDispatcher(UMOImmutableEndpoint endpoint) 40 { 41 super(endpoint); 42 this.connector = (DQConnector)endpoint.getConnector(); 43 } 44 45 protected void doDispatch(UMOEvent event) throws Exception 46 { 47 try 48 { 49 DQMessage msg = (DQMessage)event.getMessage().getPayload(); 50 AS400 system = connector.getSystem(); 51 52 RecordFormat format = getRecordFormat(event.getEndpoint().getEndpointURI()); 53 Record rec = DQMessageUtils.getRecord(msg, format); 54 55 DataQueue dq = new DataQueue(system, event.getEndpoint().getEndpointURI().getAddress()); 56 dq.write(rec.getContents()); 57 58 } 59 catch (Exception e) 60 { 61 getConnector().handleException(e); 62 } 63 if (logger.isDebugEnabled()) 64 { 65 logger.debug("doDispatch(UMOEvent) - end"); 66 } 67 } 68 69 protected RecordFormat getRecordFormat(UMOEndpointURI endpointUri) throws Exception 70 { 71 String recordDescriptor = (String )endpointUri.getParams().get(DQConnector.RECORD_DESCRIPTOR_PROPERTY); 72 if (recordDescriptor == null) 73 { 74 if (connector.getFormat() == null) 75 { 76 throw new IllegalArgumentException ("Property " + DQConnector.RECORD_DESCRIPTOR_PROPERTY 77 + " must be set on the endpoint"); 78 } 79 else 80 { 81 if (logger.isDebugEnabled()) 82 { 83 logger.debug("Defaulting to connector format: " + connector.getRecordFormat()); 84 } 85 return connector.getFormat(); 86 } 87 } 88 if (logger.isDebugEnabled()) 89 { 90 logger.debug("Using endpoint-specific format: " + connector.getRecordFormat()); 91 } 92 return DQMessageUtils.getRecordFormat(recordDescriptor, connector.getSystem()); 93 } 94 95 protected UMOMessage doSend(UMOEvent event) throws Exception 96 { 97 doDispatch(event); 98 return null; 99 } 100 101 public Object getDelegateSession() throws UMOException 102 { 103 return null; 104 } 105 106 118 protected UMOMessage doReceive(UMOImmutableEndpoint endpoint, long timeout) throws Exception 119 { 120 DataQueue dq = new DataQueue(connector.getSystem(), endpoint.getEndpointURI().getAddress()); 121 DataQueueEntry entry = dq.read((int)timeout); 122 if (entry != null) 123 { 124 RecordFormat format = getRecordFormat(endpoint.getEndpointURI()); 125 DQMessage message = DQMessageUtils.getDQMessage(entry.getData(), format); 126 message.setSenderInformation(entry.getSenderInformation()); 127 return new MuleMessage(connector.getMessageAdapter(message)); 128 } 129 return null; 130 } 131 132 protected void doDispose() 133 { 134 } 136 137 protected void doConnect(UMOImmutableEndpoint endpoint) throws Exception 138 { 139 } 141 142 protected void doDisconnect() throws Exception 143 { 144 } 146 147 } 148 | Popular Tags |