1 10 11 package org.mule.providers.space; 12 13 import org.apache.commons.lang.StringUtils; 14 import org.mule.config.i18n.Message; 15 import org.mule.config.i18n.Messages; 16 import org.mule.providers.AbstractServiceEnabledConnector; 17 import org.mule.umo.UMOComponent; 18 import org.mule.umo.endpoint.UMOEndpoint; 19 import org.mule.umo.endpoint.UMOImmutableEndpoint; 20 import org.mule.umo.lifecycle.InitialisationException; 21 import org.mule.umo.space.UMOSpace; 22 import org.mule.umo.space.UMOSpaceException; 23 import org.mule.umo.space.UMOSpaceFactory; 24 import org.mule.util.BeanUtils; 25 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 35 public class SpaceConnector extends AbstractServiceEnabledConnector 36 { 37 private UMOSpaceFactory spaceFactory; 38 private Map spaceProperties; 39 private Map spaces = new HashMap (); 41 42 public SpaceConnector() 43 { 44 super(); 45 } 46 47 public String getProtocol() 48 { 49 return "space"; 50 } 51 52 public void doInitialise() throws InitialisationException 53 { 54 super.doInitialise(); 55 if (spaceFactory == null) 56 { 57 throw new InitialisationException(new Message(Messages.X_IS_NULL, "spaceFactory"), this); 58 } 59 if (spaceProperties != null) 60 { 61 BeanUtils.populateWithoutFail(spaceFactory, spaceProperties, true); 62 } 63 64 } 65 66 public UMOSpace getSpace(String spaceUrl) throws UMOSpaceException 67 { 68 logger.info("looking for space: " + spaceUrl); 69 UMOSpace space = (UMOSpace)spaces.get(spaceUrl); 70 if (space == null) 71 { 72 logger.info("Space not found, creating space: " + spaceUrl); 73 space = spaceFactory.create(spaceUrl); 74 spaces.put(spaceUrl, space); 75 } 76 return space; 77 } 78 79 88 public UMOSpace getSpace(UMOImmutableEndpoint endpoint) throws UMOSpaceException 89 { 90 String spaceKey = getSpaceKey(endpoint); 91 logger.info("looking for space: " + spaceKey); 92 UMOSpace space = (UMOSpace)spaces.get(spaceKey); 93 if (space == null) 94 { 95 logger.info("Space not found, creating space: " + spaceKey); 96 space = spaceFactory.create(endpoint); 97 spaces.put(spaceKey, space); 98 if (endpoint.getTransactionConfig().getFactory() != null) 99 { 100 space.setTransactionFactory(endpoint.getTransactionConfig().getFactory()); 101 } 102 } 103 return space; 104 } 105 106 protected String getSpaceKey(UMOImmutableEndpoint endpoint) 107 { 108 return endpoint.getEndpointURI().toString(); 109 } 110 111 public UMOSpaceFactory getSpaceFactory() 112 { 113 return spaceFactory; 114 } 115 116 public void setSpaceFactory(UMOSpaceFactory spaceFactory) 117 { 118 this.spaceFactory = spaceFactory; 119 } 120 121 public Map getSpaceProperties() 122 { 123 return spaceProperties; 124 } 125 126 public void setSpaceProperties(Map spaceProperties) 127 { 128 this.spaceProperties = spaceProperties; 129 } 130 131 134 protected void doDispose() 135 { 136 for (Iterator iterator = spaces.values().iterator(); iterator.hasNext();) 137 { 138 UMOSpace space = (UMOSpace)iterator.next(); 139 space.dispose(); 140 } 141 spaces.clear(); 142 } 143 144 151 protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) 152 { 153 return super.getReceiverKey(component, endpoint) 154 + (endpoint.getFilter() != null ? '#' + endpoint.getFilter().toString() : StringUtils.EMPTY); 155 } 156 } 157 | Popular Tags |