1 10 11 package org.mule.providers.gs.space; 12 13 import net.jini.core.entry.Entry; 14 import net.jini.core.lease.Lease; 15 import net.jini.core.transaction.server.TransactionManager; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.mule.config.i18n.Message; 20 import org.mule.config.i18n.Messages; 21 import org.mule.impl.space.CreateSpaceException; 22 import org.mule.providers.gs.GSConnector; 23 import org.mule.providers.gs.JiniMessage; 24 import org.mule.providers.gs.JiniTransactionFactory; 25 import org.mule.providers.gs.filters.JavaSpaceTemplateFilter; 26 import org.mule.providers.space.SpaceConstants; 27 import org.mule.umo.UMOFilter; 28 import org.mule.umo.endpoint.UMOEndpoint; 29 import org.mule.umo.endpoint.UMOImmutableEndpoint; 30 import org.mule.umo.space.UMOSpace; 31 import org.mule.umo.space.UMOSpaceException; 32 import org.mule.umo.space.UMOSpaceFactory; 33 import org.mule.util.MapUtils; 34 35 import com.j_spaces.core.IJSpace; 36 import com.j_spaces.core.client.FinderException; 37 import com.j_spaces.core.client.LocalTransactionManager; 38 39 45 public class GSSpaceFactory implements UMOSpaceFactory 46 { 47 50 protected transient Log logger = LogFactory.getLog(getClass()); 51 52 private boolean enableMonitorEvents = true; 53 54 public UMOSpace create(String spaceIdentifier) throws UMOSpaceException 55 { 56 if (spaceIdentifier == null) 57 { 58 throw new NullPointerException (new Message(Messages.X_IS_NULL, "spaceIdentifier").toString()); 59 } 60 61 try 62 { 63 GSSpace space = new GSSpace(spaceIdentifier, enableMonitorEvents); 64 space.setEntryTemplate(createDefaultEntry(spaceIdentifier)); 65 return space; 66 } 67 catch (FinderException e) 68 { 69 throw new CreateSpaceException(e); 70 } 71 } 72 73 81 public UMOSpace create(UMOImmutableEndpoint endpoint) throws UMOSpaceException 82 { 83 try 84 { 85 long leaseValue = MapUtils.getLongValue(endpoint.getProperties(), 87 SpaceConstants.SPACE_LEASE_PROPERTY, Lease.FOREVER); 88 89 GSSpace space = new GSSpace(endpoint.getEndpointURI().toString(), enableMonitorEvents, leaseValue); 92 93 if (endpoint.getTransactionConfig().getFactory() != null) 97 { 98 JiniTransactionFactory txFactory = (JiniTransactionFactory)endpoint.getTransactionConfig() 99 .getFactory(); 100 TransactionManager transactionManager = LocalTransactionManager.getInstance((IJSpace)space.getJavaSpace()); 101 txFactory.setTransactionManager(transactionManager); 102 txFactory.setTransactionTimeout(((GSConnector)endpoint.getConnector()).getTransactionTimeout()); 103 space.setTransactionFactory(txFactory); 104 } 105 106 if (!endpoint.getType().equalsIgnoreCase(UMOEndpoint.ENDPOINT_TYPE_SENDER)) 109 { 110 if (endpoint.getFilter() != null) 112 { 113 UMOFilter filter = endpoint.getFilter(); 114 if (filter instanceof JavaSpaceTemplateFilter) 115 { 116 space.setEntryTemplate(((JavaSpaceTemplateFilter)filter).getEntry()); 117 } 118 else 119 { 120 if (!endpoint.getType().equals(UMOImmutableEndpoint.ENDPOINT_TYPE_SENDER)) 121 { 122 logger.warn("Filter on endpoint " 123 + endpoint.getEndpointURI().toString() 124 + " Was not a JiniEntryFilter. Endpoint will match all entries of all types for this endpoint"); 125 } 126 space.setEntryTemplate(createDefaultEntry(endpoint.getEndpointURI().toString())); 127 } 128 } 129 else 130 { 131 if (!endpoint.getType().equals(UMOImmutableEndpoint.ENDPOINT_TYPE_SENDER)) 132 { 133 logger.warn("Filter on endpoint " 134 + endpoint.getEndpointURI().toString() 135 + " Was not set. Endpoint will match all entries of all types for this endpoint"); 136 } 137 space.setEntryTemplate(createDefaultEntry(endpoint.getEndpointURI().toString())); 138 } 139 } 140 return space; 141 } 142 catch (Exception e) 143 { 144 throw new CreateSpaceException(e); 145 } 146 } 147 148 protected Entry createDefaultEntry(String identifier) 149 { 150 return new JiniMessage(); 152 } 153 } 154 | Popular Tags |