1 10 11 package org.mule.providers.space; 12 13 import org.apache.commons.collections.MapUtils; 14 import org.mule.config.i18n.Message; 15 import org.mule.impl.MuleMessage; 16 import org.mule.providers.ConnectException; 17 import org.mule.providers.TransactedPollingMessageReceiver; 18 import org.mule.umo.UMOComponent; 19 import org.mule.umo.endpoint.UMOEndpoint; 20 import org.mule.umo.lifecycle.InitialisationException; 21 import org.mule.umo.provider.UMOConnector; 22 import org.mule.umo.provider.UMOMessageAdapter; 23 import org.mule.umo.space.UMOSpace; 24 import org.mule.umo.space.UMOSpaceException; 25 26 import java.util.List ; 27 import java.util.Properties ; 28 29 32 public class TransactedSpaceMessageReceiver extends TransactedPollingMessageReceiver 33 { 34 private UMOSpace space; 35 private SpaceConnector connector; 36 37 public TransactedSpaceMessageReceiver(UMOConnector connector, 38 UMOComponent component, 39 final UMOEndpoint endpoint) throws InitialisationException 40 { 41 super(connector, component, endpoint, new Long (0)); 42 this.connector = (SpaceConnector)connector; 43 this.frequency = MapUtils.getLongValue(endpoint.getProperties(), "frequency", 100000L); 44 } 45 46 protected List getMessages() throws Exception 47 { 48 Object message = space.take(frequency); 49 if (message == null) 50 { 51 return null; 52 } 53 54 if (logger.isDebugEnabled()) 56 { 57 logger.debug("Message received it is of type: " + message.getClass().getName()); 58 } 59 60 UMOMessageAdapter adapter = connector.getMessageAdapter(message); 61 routeMessage(new MuleMessage(adapter), true); 62 return null; 63 } 64 65 protected void processMessage(Object message) throws Exception 66 { 67 } 69 70 public void doConnect() throws Exception 71 { 72 String destination = endpoint.getEndpointURI().getAddress(); 73 74 Properties props = new Properties (); 75 props.putAll(endpoint.getProperties()); 76 try 77 { 78 logger.info("Connecting to space: " + destination); 79 space = connector.getSpace(endpoint); 80 } 81 catch (UMOSpaceException e) 82 { 83 throw new ConnectException(new Message("space", 1, destination), e, this); 84 } 85 } 86 87 public void doDisconnect() throws Exception 88 { 89 } 91 92 public UMOSpace getSpace() 93 { 94 return space; 95 } 96 } 97 | Popular Tags |