You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2009/12/17 12:28:41 UTC
svn commit: r891650 [4/10] - in /cxf/dosgi/trunk: ./
discovery/distributed/cxf-discovery/
discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/
discovery/distributed/cxf-discovery/src/main/java/org/osgi/service/dis...
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Thu Dec 17 11:28:30 2009
@@ -1,24 +1,26 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
+import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -26,64 +28,61 @@
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
public class PojoConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
private static final Logger LOG = Logger.getLogger(PojoConfigurationTypeHandler.class.getName());
public PojoConfigurationTypeHandler(BundleContext dswBC,
- CxfDistributionProvider dp,
- Map<String, Object> handlerProps) {
- super(dswBC, dp, handlerProps);
- }
- public Object createProxy(ServiceReference serviceReference,
- BundleContext dswContext,
- BundleContext callingContext,
- Class<?> iClass,
- ServiceEndpointDescription sd)
- throws IntentUnsatifiedException {
+ Map<String, Object> handlerProps) {
+ super(dswBC, handlerProps);
+ }
- String address = getPojoAddress(sd, iClass);
+ public Object createProxy(ServiceReference serviceReference, BundleContext dswContext,
+ BundleContext callingContext, Class<?> iClass, EndpointDescription sd)
+ throws IntentUnsatifiedException {
+ //
+ String address = getPojoAddress(sd.getProperties(), iClass);
if (address == null) {
LOG.warning("Remote address is unavailable");
return null;
}
- LOG.info("Creating a " + sd.getProvidedInterfaces().toArray()[0]
- + " client, endpoint address is " + address);
+ LOG.info("Creating a " + sd.getInterfaces().toArray()[0] + " client, endpoint address is " + address);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
DataBinding databinding;
- String dataBindingImpl = (String) serviceReference.getProperty(Constants.WS_DATABINDING_PROP_KEY);
- if("jaxb".equals(dataBindingImpl)) {
- databinding = new JAXBDataBinding();
+ String dataBindingImpl = (String)serviceReference.getProperty(Constants.WS_DATABINDING_PROP_KEY);
+ if ("jaxb".equals(dataBindingImpl)) {
+ databinding = new JAXBDataBinding();
} else {
- databinding = new AegisDatabinding();
+ databinding = new AegisDatabinding();
}
- String frontEndImpl = (String) serviceReference.getProperty(Constants.WS_FRONTEND_PROP_KEY);
+ String frontEndImpl = (String)serviceReference.getProperty(Constants.WS_FRONTEND_PROP_KEY);
ClientProxyFactoryBean factory = createClientProxyFactoryBean(frontEndImpl);
factory.setServiceClass(iClass);
factory.setAddress(address);
factory.getServiceFactory().setDataBinding(databinding);
- applyIntents(dswContext,
- callingContext,
- factory.getFeatures(),
- factory.getClientFactoryBean(),
- sd);
+ applyIntents(dswContext, callingContext, factory.getFeatures(), factory.getClientFactoryBean(),
+ sd.getProperties());
Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());
Object proxy = getProxy(factory.create(), iClass);
- getDistributionProvider().addRemoteService(serviceReference);
+ // MARC: FIXME !!!! getDistributionProvider().addRemoteService(serviceReference);
return proxy;
} catch (Exception e) {
LOG.log(Level.WARNING, "proxy creation failed", e);
@@ -92,71 +91,120 @@
}
return null;
}
-
- public Server createServer(ServiceReference serviceReference,
- BundleContext dswContext,
- BundleContext callingContext,
- ServiceEndpointDescription sd,
- Class<?> iClass,
- Object serviceBean) throws IntentUnsatifiedException {
+
+ public void createServer(ExportRegistrationImpl exportRegistration, BundleContext dswContext,
+ BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean)
+ throws IntentUnsatifiedException {
String address = getPojoAddress(sd, iClass);
if (address == null) {
LOG.warning("Remote address is unavailable");
- return null;
+ exportRegistration.setException(new Throwable("Remote address is unavailable"));
+ return;
}
-
- LOG.info("Creating a " + sd.getProvidedInterfaces().toArray()[0]
- + " endpoint from CXF PublishHook, address is " + address);
-
+
+ LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address is " + address);
+
+ // The properties for the EndpointDescription
+ Map<String, Object> endpointProps = new HashMap<String, Object>();
+
+ copyEndpointProperties(exportRegistration, endpointProps);
+
+ String[] sa = new String[1];
+ sa[0] = iClass.getName();
+ endpointProps.put(org.osgi.framework.Constants.OBJECTCLASS, sa);
+ // endpointProps.put(RemoteConstants.SERVICE_IMPORTED, "someValue;-)"); // should be done when the
+ // service is imported
+ // endpointProps.put(RemoteConstants.SERVICE_REMOTE_ID, "TODO");
+
+ // FIXME: This key is not defined in the spec but is required by the EndpointDescription !!!!!
+ endpointProps.put(RemoteConstants.ENDPOINT_ID, 123L);
+
+ endpointProps.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, getUUID());
+ endpointProps.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, Constants.WS_CONFIG_TYPE);
+ endpointProps.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + sa[0], OsgiUtils.getVersion(iClass, dswContext));
+
DataBinding databinding;
- String dataBindingImpl = (String) serviceReference.getProperty(Constants.WS_DATABINDING_PROP_KEY);
- if("jaxb".equals(dataBindingImpl)) {
- databinding = new JAXBDataBinding();
+ String dataBindingImpl = (String)exportRegistration.getExportedService()
+ .getProperty(Constants.WS_DATABINDING_PROP_KEY);
+ if ("jaxb".equals(dataBindingImpl)) {
+ databinding = new JAXBDataBinding();
} else {
- databinding = new AegisDatabinding();
+ databinding = new AegisDatabinding();
}
- String frontEndImpl = (String) serviceReference.getProperty(Constants.WS_FRONTEND_PROP_KEY);
+ String frontEndImpl = (String)exportRegistration.getExportedService()
+ .getProperty(Constants.WS_FRONTEND_PROP_KEY);
ServerFactoryBean factory = createServerFactoryBean(frontEndImpl);
factory.setServiceClass(iClass);
factory.setAddress(address);
factory.getServiceFactory().setDataBinding(databinding);
factory.setServiceBean(serviceBean);
-
+
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
- String [] intents = applyIntents(
- dswContext, callingContext, factory.getFeatures(), factory, sd);
-
-
+ String[] intents = applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
+
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
- addAddressProperty(sd.getProperties(), address);
- return server;
+ // MARC: FIXME !!!! getDistributionProvider().addExposedService(serviceReference,
+ // registerPublication(server, intents));
+ // TODO: registerPublication(server, intents);
+ endpointProps.put(RemoteConstants.ENDPOINT_URI, address);
+
+ exportRegistration.setServer(server);
+
} catch (IntentUnsatifiedException iue) {
- getDistributionProvider().intentsUnsatisfied(serviceReference);
- throw iue;
+ // MARC: FIXME !!!! getDistributionProvider().intentsUnsatisfied(serviceReference);
+ // throw iue;
+ exportRegistration.setException(iue);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
- }
+
+ // add the information on the new Endpoint to the export registration
+ EndpointDescription ed = new EndpointDescription(endpointProps);
+ exportRegistration.setEndpointdescription(ed);
+ }
+
+
+ private void copyEndpointProperties(ExportRegistrationImpl exportRegistration,
+ Map<String, Object> endpointProps) {
+
+ String[] keys = exportRegistration.getExportedService().getPropertyKeys();
+ for (String key : keys) {
+ if (!key.startsWith("."))
+ endpointProps.put(key, exportRegistration.getExportedService().getProperty(key));
+ }
+
+ }
+
+ private String getUUID() {
+ synchronized ("org.osgi.framework.uuid") {
+ String uuid = getBundleContext().getProperty("org.osgi.framework.uuid");
+ if (uuid == null) {
+ uuid = UUID.randomUUID().toString();
+ System.setProperty("org.osgi.framework.uuid", uuid);
+ }
+ return uuid;
+ }
+ }
+
@Override
Map<String, String> registerPublication(Server server, String[] intents) {
Map<String, String> publicationProperties = super.registerPublication(server, intents);
- publicationProperties.put(Constants.WS_ADDRESS_PROPERTY,
- server.getDestination().getAddress().getAddress().getValue());
+ publicationProperties.put(Constants.WS_ADDRESS_PROPERTY, server.getDestination().getAddress()
+ .getAddress().getValue());
return publicationProperties;
}
- protected String getPojoAddress(ServiceEndpointDescription sd, Class<?> iClass) {
- String address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY);
- if (address == null) {
- address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY_OLD);
- }
-
+ protected String getPojoAddress(Map sd, Class<?> iClass) {
+ String address = OsgiUtils.getProperty(sd, RemoteConstants.ENDPOINT_URI);
+ // if (address == null) {
+ // address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY_OLD);
+ // }
+
if (address == null) {
address = getDefaultAddress(iClass);
if (address != null) {
@@ -165,5 +213,5 @@
}
return address;
}
-
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java Thu Dec 17 11:28:30 2009
@@ -20,6 +20,7 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Dictionary;
import java.util.Map;
import java.util.logging.Logger;
@@ -29,20 +30,20 @@
import org.apache.cxf.common.util.PackageUtils;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
import org.apache.cxf.endpoint.Server;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
public class WsdlConfigurationTypeHandler extends AbstractConfigurationHandler {
private static final String CONFIGURATION_TYPE = "wsdl";
private static final Logger LOG = Logger.getLogger(WsdlConfigurationTypeHandler.class.getName());
public WsdlConfigurationTypeHandler(BundleContext dswBC,
- CxfDistributionProvider dp,
+
Map<String, Object> handlerProps) {
- super(dswBC, dp, handlerProps);
+ super(dswBC, handlerProps);
}
public String getType() {
@@ -53,7 +54,7 @@
BundleContext dswContext,
BundleContext callingContext,
Class<?> iClass,
- ServiceEndpointDescription sd) {
+ EndpointDescription sd) {
String wsdlAddressProp = getWsdlAddress(sd, iClass);
if (wsdlAddressProp == null) {
@@ -69,7 +70,7 @@
return null;
}
- LOG.info("Creating a " + sd.getProvidedInterfaces().toArray()[0] + " client, wsdl address is "
+ LOG.info("Creating a " + sd.getInterfaces().toArray()[0] + " client, wsdl address is "
+ OsgiUtils.getProperty(sd, Constants.WSDL_CONFIG_PREFIX));
String serviceNs = OsgiUtils.getProperty(sd, Constants.SERVICE_NAMESPACE);
@@ -80,7 +81,7 @@
QName serviceQname = new QName(serviceNs, iClass.getSimpleName());
Service service = createWebService(wsdlAddress, serviceQname);
Object proxy = getProxy(service.getPort(iClass), iClass);
- getDistributionProvider().addRemoteService(serviceReference);
+ //MARC: FIXME !!!! getDistributionProvider().addRemoteService(serviceReference);
return proxy;
}
@@ -90,10 +91,10 @@
return Service.create(wsdlAddress, serviceQname);
}
- public Server createServer(ServiceReference sr,
+ public void createServer(ExportRegistrationImpl exportRegistration,
BundleContext dswContext,
BundleContext callingContext,
- ServiceEndpointDescription sd,
+ Map sd,
Class<?> iClass,
Object serviceBean) {
@@ -101,7 +102,7 @@
+ " creating service endpoints");
}
- private String getWsdlAddress(ServiceEndpointDescription sd, Class<?> iClass) {
+ private String getWsdlAddress(EndpointDescription sd, Class<?> iClass) {
String address = OsgiUtils.getProperty(sd, Constants.WSDL_CONFIG_PREFIX);
if (address == null) {
address = getDefaultAddress(iClass);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java Thu Dec 17 11:28:30 2009
@@ -18,299 +18,271 @@
*/
package org.apache.cxf.dosgi.dsw.hooks;
-import static org.osgi.service.discovery.DiscoveredServiceNotification.AVAILABLE;
-import static org.osgi.service.discovery.DiscoveredServiceNotification.MODIFIED;
-import static org.osgi.service.discovery.DiscoveredServiceNotification.UNAVAILABLE;
-import static org.osgi.service.discovery.DiscoveredServiceTracker.FILTER_MATCH_CRITERIA;
-import static org.osgi.service.discovery.DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA;
-import static org.osgi.service.discovery.ServicePublication.ENDPOINT_ID;
-import static org.osgi.service.discovery.ServicePublication.SERVICE_INTERFACE_NAME;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import org.apache.cxf.dosgi.dsw.Constants;
-import org.apache.cxf.dosgi.dsw.handlers.ClientServiceFactory;
-import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.discovery.DiscoveredServiceNotification;
-import org.osgi.service.discovery.DiscoveredServiceTracker;
-import org.osgi.service.discovery.ServiceEndpointDescription;
public class AbstractClientHook extends AbstractHook {
- private static final Logger LOG = Logger.getLogger(AbstractClientHook.class.getName());
-
- private DiscoveredServiceTracker tracker;
- private Dictionary trackerProperties = new Hashtable();
- private Map<String, ServiceRegistration> discoveredServices =
- new HashMap<String, ServiceRegistration>();
- ServiceRegistration trackerRegistration;
-
- protected AbstractClientHook(BundleContext bc, CxfDistributionProvider dp) {
- super(bc, dp);
- tracker = new DiscoveryCallback();
- trackerRegistration =
- bc.registerService(DiscoveredServiceTracker.class.getName(),
- tracker,
- trackerProperties);
- }
-
- protected void processNotification(DiscoveredServiceNotification notification,
- BundleContext requestingContext) {
-
- ServiceEndpointDescription sd =
- notification.getServiceEndpointDescription();
- if ((sd.getProperty(Constants.EXPORTED_INTERFACES) == null) &&
- (sd.getProperty(Constants.EXPORTED_INTERFACES_OLD) == null)) {
- return;
- }
-
- ConfigurationTypeHandler handler =
- ServiceHookUtils.getHandler(getContext(), sd, getDistributionProvider(), getHandlerProperties());
- if (handler == null) {
- LOG.info("not proxifying service, config type handler null");
- return;
- }
-
- Collection<String> matchingInterfaces =
- getMatchingInterfaces(notification, requestingContext);
-
- for (String interfaceName : matchingInterfaces) {
- proxifyMatchingInterface(interfaceName, sd, handler, requestingContext);
- }
-
- }
-
-
- private void proxifyMatchingInterface(String interfaceName,
- ServiceEndpointDescription sd,
- ConfigurationTypeHandler handler,
- BundleContext requestingContext) {
-
- try {
- Class<?> iClass = getContext().getBundle().loadClass(interfaceName);
- if (iClass != null) {
- BundleContext actualContext = getContext();
- Class<?> actualClass = requestingContext.getBundle().loadClass(interfaceName);
- if (actualClass != iClass) {
- LOG.info("Class " + interfaceName + " loaded by DSW's bundle context is not "
- + "equal to the one loaded by the requesting bundle context, "
- + "DSW will use the requesting bundle context to register "
- + "a proxy service");
- iClass = actualClass;
- actualContext = requestingContext;
- }
-
- synchronized(discoveredServices) {
- if (unknownEndpointId(sd)) {
- ServiceRegistration proxyRegistration =
- actualContext.registerService(interfaceName,
- new ClientServiceFactory(actualContext, iClass, sd, handler),
- new Hashtable<String, Object>(getProperties(sd, handler)));
- cacheEndpointId(sd, proxyRegistration);
- }
- }
- } else {
- LOG.info("not proxifying service, cannot load interface class: "
- + interfaceName);
- }
- } catch (ClassNotFoundException ex) {
- LOG.warning("No class can be found for " + interfaceName);
- }
- }
-
- private Collection<String> getMatchingInterfaces(DiscoveredServiceNotification notification, BundleContext context) {
- Collection<String> matches = new ArrayList<String>();
- Iterator interfaces = notification.getServiceEndpointDescription().getProvidedInterfaces().iterator();
-
- while (interfaces.hasNext()) {
- String currInterface = (String)interfaces.next();
- boolean matched = false;
- Iterator matchedInterfaces =
- notification.getInterfaces().iterator();
- while (matchedInterfaces.hasNext() && !matched) {
- matched = currInterface.equals(matchedInterfaces.next());
- if (matched) {
- matches.add(currInterface);
- }
- }
- Iterator matchedFilters =
- notification.getFilters().iterator();
- while (matchedFilters.hasNext() && !matched) {
- String filterString = (String)matchedFilters.next();
- try {
- Filter filter = context.createFilter(filterString);
- matched =
- filter.match(getProperties(notification, currInterface));
- } catch (InvalidSyntaxException ise) {
- LOG.warning("invalid filter syntax: " + filterString);
- }
- if (matched) {
- matches.add(currInterface);
- }
- }
- }
-
- return matches;
- }
-
- private Hashtable getProperties(DiscoveredServiceNotification notification,
- String interfaceName) {
- Hashtable ret = new Hashtable();
- Map properties = notification.getServiceEndpointDescription().getProperties();
- Iterator keys = notification.getServiceEndpointDescription().getPropertyKeys().iterator();
- while (keys.hasNext()) {
- String key = (String)keys.next();
- ret.put(key, properties.get(key));
- }
- ret.put(SERVICE_INTERFACE_NAME, interfaceName);
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- protected Map<String, Object> getProperties(ServiceEndpointDescription sd, ConfigurationTypeHandler handler) {
- Map<String, Object> props = new HashMap<String, Object>();
- props.putAll(sd.getProperties());
-
- for (Iterator<Map.Entry<String, Object>> i = props.entrySet().iterator(); i.hasNext(); ) {
- Map.Entry<String, Object> e = i.next();
- if (e.getKey().startsWith("service.exported")) {
- i.remove();
- }
- }
-
- props.put(Constants.DSW_CLIENT_ID, getIdentificationProperty());
- props.put(Constants.IMPORTED, "true");
- props.put(Constants.IMPORTD_CONFIGS, handler.getType());
- return props;
- }
-
- protected synchronized void lookupDiscoveryService(String interfaceName, String filterValue) {
- LOG.info("lookup discovery service: interface: " + interfaceName
- + " filter: " + filterValue);
-
- boolean change = false;
- if (interfaceName != null) {
- change |= append(trackerProperties,
- INTERFACE_MATCH_CRITERIA,
- interfaceName);
- }
-
- if (filterValue != null) {
- change |= append(trackerProperties,
- FILTER_MATCH_CRITERIA,
- filterValue);
- }
-
- if (change) {
- trackerRegistration.setProperties(trackerProperties);
- }
- }
-
- @SuppressWarnings("unchecked")
- private boolean append(Dictionary properties, String key, String additional) {
- Collection existing = (Collection)properties.get(key);
- if (existing == null) {
- existing = new ArrayList<String>();
- properties.put(key, existing);
- }
-
- if (!existing.contains(additional)) {
- existing.add(additional);
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * @pre called with discoveredServices mutex held
- */
- private boolean unknownEndpointId(ServiceEndpointDescription notified) {
- String endpointId = (String)notified.getProperty(ENDPOINT_ID);
- if (endpointId != null) {
- boolean duplicate = discoveredServices.containsKey(endpointId);
- if (!duplicate) {
- LOG.info("registering proxy for endpoint ID: " + endpointId);
- } else {
- LOG.info("ignoring duplicate notification for endpoint ID: "
- + endpointId);
- }
- return !duplicate;
- } else {
- LOG.warning("registering proxy with unknown duplicate status as endpoint ID unset");
- return true;
- }
- }
-
- /**
- * @pre called with discoveredServices mutex held
- */
- private void cacheEndpointId(ServiceEndpointDescription notified, ServiceRegistration registration) {
- String endpointId = (String)notified.getProperty(ENDPOINT_ID);
- if (endpointId != null) {
- discoveredServices.put(endpointId, registration);
- LOG.info("caching proxy registration for endpoint ID: " + endpointId);
- } else {
- LOG.warning("cannot cache proxy registration as endpoint ID unset");
- }
- }
-
- private void unCacheEndpointId(ServiceEndpointDescription notified) {
- String endpointId = (String)notified.getProperty(ENDPOINT_ID);
- ServiceRegistration proxyRegistration = null;
- if (endpointId != null) {
- synchronized (discoveredServices) {
- proxyRegistration = discoveredServices.remove(endpointId);
- }
- }
- if (proxyRegistration != null) {
- LOG.info("unregistering proxy service for endpoint ID: "
- + endpointId);
- proxyRegistration.unregister();
- }
- }
-
- private class DiscoveryCallback implements DiscoveredServiceTracker {
- public void serviceChanged(DiscoveredServiceNotification notification) {
- ServiceEndpointDescription notified =
- notification.getServiceEndpointDescription();
- switch (notification.getType()) {
-
- case AVAILABLE:
- LOG.info("Notified - AVAILABLE: "
- + notified.getProvidedInterfaces()
- + " endpoint id: "
- + notification.getServiceEndpointDescription().getProperty(ENDPOINT_ID));
- processNotification(notification, getContext());
- break;
-
- case UNAVAILABLE:
- LOG.info("Notified - UNAVAILABLE: " + notified.getProvidedInterfaces()
- + notified.getProvidedInterfaces()
- + " endpoint id: "
- + notification.getServiceEndpointDescription().getProperty(ENDPOINT_ID));
- unCacheEndpointId(notified);
- break;
-
- case MODIFIED:
- LOG.info("Notified - MODIFIED: " + notified.getProvidedInterfaces());
- // we don't currently use this notification, but we could do
- // so to allow to support transparent service re-location
- break;
- }
- }
- }
+// private static final Logger LOG = Logger.getLogger(AbstractClientHook.class.getName());
+//
+// private DiscoveredServiceTracker tracker;
+// private Dictionary trackerProperties = new Hashtable();
+// private Map<String, ServiceRegistration> discoveredServices =
+// new HashMap<String, ServiceRegistration>();
+// ServiceRegistration trackerRegistration;
+//
+// protected AbstractClientHook(BundleContext bc, CxfRemoteServiceAdmin dp) {
+// super(bc, dp);
+//// tracker = new DiscoveryCallback();
+//// trackerRegistration =
+//// bc.registerService(DiscoveredServiceTracker.class.getName(),
+//// tracker,
+//// trackerProperties);
+// }
+//
+//// protected void processNotification(DiscoveredServiceNotification notification,
+//// BundleContext requestingContext) {
+////
+//// EndpointDescription sd =
+//// notification.getEndpointDescription();
+//// if ((sd.getProperty(Constants.EXPORTED_INTERFACES) == null) &&
+//// (sd.getProperty(Constants.EXPORTED_INTERFACES_OLD) == null)) {
+//// return;
+//// }
+////
+//// ConfigurationTypeHandler handler =
+//// ServiceHookUtils.getHandler(getContext(), sd, getHandlerProperties());
+//// if (handler == null) {
+//// LOG.info("not proxifying service, config type handler null");
+//// return;
+//// }
+////
+//// Collection<String> matchingInterfaces =
+//// getMatchingInterfaces(notification, requestingContext);
+////
+//// for (String interfaceName : matchingInterfaces) {
+//// proxifyMatchingInterface(interfaceName, sd, handler, requestingContext);
+//// }
+////
+//// }
+//
+//
+// private void proxifyMatchingInterface(String interfaceName,
+// EndpointDescription sd,
+// ConfigurationTypeHandler handler,
+// BundleContext requestingContext) {
+//
+// try {
+// Class<?> iClass = getContext().getBundle().loadClass(interfaceName);
+// if (iClass != null) {
+// BundleContext actualContext = getContext();
+// Class<?> actualClass = requestingContext.getBundle().loadClass(interfaceName);
+// if (actualClass != iClass) {
+// LOG.info("Class " + interfaceName + " loaded by DSW's bundle context is not "
+// + "equal to the one loaded by the requesting bundle context, "
+// + "DSW will use the requesting bundle context to register "
+// + "a proxy service");
+// iClass = actualClass;
+// actualContext = requestingContext;
+// }
+//
+// synchronized(discoveredServices) {
+// if (unknownEndpointId(sd)) {
+// ServiceRegistration proxyRegistration =
+// actualContext.registerService(interfaceName,
+// new ClientServiceFactory(actualContext, iClass, sd, handler),
+// new Hashtable<String, Object>(getProperties(sd, handler)));
+// cacheEndpointId(sd, proxyRegistration);
+// }
+// }
+// } else {
+// LOG.info("not proxifying service, cannot load interface class: "
+// + interfaceName);
+// }
+// } catch (ClassNotFoundException ex) {
+// LOG.warning("No class can be found for " + interfaceName);
+// }
+// }
+//
+// private Collection<String> getMatchingInterfaces(DiscoveredServiceNotification notification, BundleContext context) {
+// Collection<String> matches = new ArrayList<String>();
+// Iterator interfaces = notification.getEndpointDescription().getProvidedInterfaces().iterator();
+//
+// while (interfaces.hasNext()) {
+// String currInterface = (String)interfaces.next();
+// boolean matched = false;
+// Iterator matchedInterfaces =
+// notification.getInterfaces().iterator();
+// while (matchedInterfaces.hasNext() && !matched) {
+// matched = currInterface.equals(matchedInterfaces.next());
+// if (matched) {
+// matches.add(currInterface);
+// }
+// }
+// Iterator matchedFilters =
+// notification.getFilters().iterator();
+// while (matchedFilters.hasNext() && !matched) {
+// String filterString = (String)matchedFilters.next();
+// try {
+// Filter filter = context.createFilter(filterString);
+// matched =
+// filter.match(getProperties(notification, currInterface));
+// } catch (InvalidSyntaxException ise) {
+// LOG.warning("invalid filter syntax: " + filterString);
+// }
+// if (matched) {
+// matches.add(currInterface);
+// }
+// }
+// }
+//
+// return matches;
+// }
+//
+// private Hashtable getProperties(DiscoveredServiceNotification notification,
+// String interfaceName) {
+// Hashtable ret = new Hashtable();
+// Map properties = notification.getEndpointDescription().getProperties();
+// Iterator keys = notification.getEndpointDescription().getPropertyKeys().iterator();
+// while (keys.hasNext()) {
+// String key = (String)keys.next();
+// ret.put(key, properties.get(key));
+// }
+// ret.put(SERVICE_INTERFACE_NAME, interfaceName);
+// return ret;
+// }
+//
+// @SuppressWarnings("unchecked")
+// protected Map<String, Object> getProperties(EndpointDescription sd, ConfigurationTypeHandler handler) {
+// Map<String, Object> props = new HashMap<String, Object>();
+// props.putAll(sd.getProperties());
+//
+// for (Iterator<Map.Entry<String, Object>> i = props.entrySet().iterator(); i.hasNext(); ) {
+// Map.Entry<String, Object> e = i.next();
+// if (e.getKey().startsWith("service.exported")) {
+// i.remove();
+// }
+// }
+//
+// props.put(Constants.DSW_CLIENT_ID, getIdentificationProperty());
+// props.put(Constants.IMPORTED, "true");
+// props.put(Constants.IMPORTD_CONFIGS, handler.getType());
+// return props;
+// }
+//
+// protected synchronized void lookupDiscoveryService(String interfaceName, String filterValue) {
+// LOG.info("lookup discovery service: interface: " + interfaceName
+// + " filter: " + filterValue);
+//
+// boolean change = false;
+// if (interfaceName != null) {
+// change |= append(trackerProperties,
+// INTERFACE_MATCH_CRITERIA,
+// interfaceName);
+// }
+//
+// if (filterValue != null) {
+// change |= append(trackerProperties,
+// FILTER_MATCH_CRITERIA,
+// filterValue);
+// }
+//
+// if (change) {
+// trackerRegistration.setProperties(trackerProperties);
+// }
+// }
+//
+// @SuppressWarnings("unchecked")
+// private boolean append(Dictionary properties, String key, String additional) {
+// Collection existing = (Collection)properties.get(key);
+// if (existing == null) {
+// existing = new ArrayList<String>();
+// properties.put(key, existing);
+// }
+//
+// if (!existing.contains(additional)) {
+// existing.add(additional);
+// return true;
+// } else {
+// return false;
+// }
+// }
+//
+// /**
+// * @pre called with discoveredServices mutex held
+// */
+// private boolean unknownEndpointId(EndpointDescription notified) {
+// String endpointId = (String)notified.getProperty(ENDPOINT_ID);
+// if (endpointId != null) {
+// boolean duplicate = discoveredServices.containsKey(endpointId);
+// if (!duplicate) {
+// LOG.info("registering proxy for endpoint ID: " + endpointId);
+// } else {
+// LOG.info("ignoring duplicate notification for endpoint ID: "
+// + endpointId);
+// }
+// return !duplicate;
+// } else {
+// LOG.warning("registering proxy with unknown duplicate status as endpoint ID unset");
+// return true;
+// }
+// }
+//
+// /**
+// * @pre called with discoveredServices mutex held
+// */
+// private void cacheEndpointId(EndpointDescription notified, ServiceRegistration registration) {
+// String endpointId = (String)notified.getProperty(ENDPOINT_ID);
+// if (endpointId != null) {
+// discoveredServices.put(endpointId, registration);
+// LOG.info("caching proxy registration for endpoint ID: " + endpointId);
+// } else {
+// LOG.warning("cannot cache proxy registration as endpoint ID unset");
+// }
+// }
+//
+// private void unCacheEndpointId(EndpointDescription notified) {
+// String endpointId = (String)notified.getProperty(ENDPOINT_ID);
+// ServiceRegistration proxyRegistration = null;
+// if (endpointId != null) {
+// synchronized (discoveredServices) {
+// proxyRegistration = discoveredServices.remove(endpointId);
+// }
+// }
+// if (proxyRegistration != null) {
+// LOG.info("unregistering proxy service for endpoint ID: "
+// + endpointId);
+// proxyRegistration.unregister();
+// }
+// }
+
+// private class DiscoveryCallback implements DiscoveredServiceTracker {
+// public void serviceChanged(DiscoveredServiceNotification notification) {
+// EndpointDescription notified =
+// notification.getEndpointDescription();
+// switch (notification.getType()) {
+//
+// case AVAILABLE:
+// LOG.info("Notified - AVAILABLE: "
+// + notified.getProvidedInterfaces()
+// + " endpoint id: "
+// + notification.getEndpointDescription().getProperty(ENDPOINT_ID));
+// processNotification(notification, getContext());
+// break;
+//
+// case UNAVAILABLE:
+// LOG.info("Notified - UNAVAILABLE: " + notified.getProvidedInterfaces()
+// + notified.getProvidedInterfaces()
+// + " endpoint id: "
+// + notification.getEndpointDescription().getProperty(ENDPOINT_ID));
+// unCacheEndpointId(notified);
+// break;
+//
+// case MODIFIED:
+// LOG.info("Notified - MODIFIED: " + notified.getProvidedInterfaces());
+// // we don't currently use this notification, but we could do
+// // so to allow to support transparent service re-location
+// break;
+// }
+// }
+// }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java Thu Dec 17 11:28:30 2009
@@ -18,89 +18,77 @@
*/
package org.apache.cxf.dosgi.dsw.hooks;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cxf.dosgi.dsw.Constants;
-import org.apache.cxf.dosgi.dsw.OsgiService;
-import org.apache.cxf.dosgi.dsw.OsgiUtils;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
public abstract class AbstractHook {
- private final CxfDistributionProvider distributionProvider;
-
- private volatile BundleContext bc;
- private volatile boolean checkBundleForMetadata = true;
- private volatile boolean useMasterMap = true;
- private volatile String defaultPort;
- private volatile String defaultHost;
-
- public AbstractHook(BundleContext bc, CxfDistributionProvider dp) {
- this.bc = bc;
- this.distributionProvider = dp;
- }
-
- protected BundleContext getContext() {
- return bc;
- }
-
- public void updateProperties(Dictionary d) {
-
- Object value = d.get(Constants.CHECK_BUNDLE);
- if (value != null) {
- checkBundleForMetadata = OsgiUtils.toBoolean(value.toString());
- }
-
- value = d.get(Constants.USE_MASTER_MAP);
- if (value != null) {
- useMasterMap = OsgiUtils.toBoolean(value.toString());
- }
-
- value = d.get(Constants.DEFAULT_HOST_CONFIG);
- defaultHost = value == null ? Constants.DEFAULT_HOST_VALUE
- : value.toString();
-
- value = d.get(Constants.DEFAULT_PORT_CONFIG);
- defaultPort = value == null ? Constants.DEFAULT_PORT_VALUE
- : value.toString();
- }
-
- protected boolean checkBundle() {
- return checkBundleForMetadata;
- }
-
- protected Map<String, Object> getHandlerProperties() {
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(Constants.DEFAULT_PORT_CONFIG,
- defaultPort == null ? Constants.DEFAULT_PORT_VALUE : defaultPort);
- props.put(Constants.DEFAULT_HOST_CONFIG,
- defaultHost == null ? Constants.DEFAULT_HOST_VALUE : defaultHost);
- props.put(Constants.USE_MASTER_MAP, useMasterMap);
- return props;
- }
-
-
- protected String getIdentificationProperty() {
- Bundle b = bc.getBundle();
- Object name =
- b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
- if (name == null) {
- name = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
- }
-
- Object version = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
-
- StringBuilder sb = new StringBuilder();
- sb.append(name.toString()).append(", version : " + version.toString());
- return sb.toString();
- }
-
- protected CxfDistributionProvider getDistributionProvider() {
- return distributionProvider;
- }
+// private final CxfRemoteServiceAdmin distributionProvider;
+//
+// private volatile BundleContext bc;
+// private volatile boolean checkBundleForMetadata = true;
+// private volatile boolean useMasterMap = true;
+// private volatile String defaultPort;
+// private volatile String defaultHost;
+//
+// public AbstractHook(BundleContext bc, CxfRemoteServiceAdmin dp) {
+// this.bc = bc;
+// this.distributionProvider = dp;
+// }
+//
+// protected BundleContext getContext() {
+// return bc;
+// }
+//
+// public void updateProperties(Dictionary d) {
+//
+// Object value = d.get(Constants.CHECK_BUNDLE);
+// if (value != null) {
+// checkBundleForMetadata = OsgiUtils.toBoolean(value.toString());
+// }
+//
+// value = d.get(Constants.USE_MASTER_MAP);
+// if (value != null) {
+// useMasterMap = OsgiUtils.toBoolean(value.toString());
+// }
+//
+// value = d.get(Constants.DEFAULT_HOST_CONFIG);
+// defaultHost = value == null ? Constants.DEFAULT_HOST_VALUE
+// : value.toString();
+//
+// value = d.get(Constants.DEFAULT_PORT_CONFIG);
+// defaultPort = value == null ? Constants.DEFAULT_PORT_VALUE
+// : value.toString();
+// }
+//
+// protected boolean checkBundle() {
+// return checkBundleForMetadata;
+// }
+//
+// protected Map<String, Object> getHandlerProperties() {
+// Map<String, Object> props = new HashMap<String, Object>();
+// props.put(Constants.DEFAULT_PORT_CONFIG,
+// defaultPort == null ? Constants.DEFAULT_PORT_VALUE : defaultPort);
+// props.put(Constants.DEFAULT_HOST_CONFIG,
+// defaultHost == null ? Constants.DEFAULT_HOST_VALUE : defaultHost);
+// props.put(Constants.USE_MASTER_MAP, useMasterMap);
+// return props;
+// }
+//
+//
+// protected String getIdentificationProperty() {
+// Bundle b = bc.getBundle();
+// Object name =
+// b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
+// if (name == null) {
+// name = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
+// }
+//
+// Object version = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
+//
+// StringBuilder sb = new StringBuilder();
+// sb.append(name.toString()).append(", version : " + version.toString());
+// return sb.toString();
+// }
+//
+// protected CxfRemoteServiceAdmin getDistributionProvider() {
+// return distributionProvider;
+// }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHook.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHook.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHook.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHook.java Thu Dec 17 11:28:30 2009
@@ -18,108 +18,114 @@
*/
package org.apache.cxf.dosgi.dsw.hooks;
-import static org.osgi.service.discovery.ServicePublication.SERVICE_INTERFACE_NAME;
-
import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
import org.osgi.framework.hooks.service.FindHook;
import org.osgi.framework.hooks.service.ListenerHook;
public class CxfFindListenerHook extends AbstractClientHook implements ListenerHook, FindHook {
- private static final Logger LOG = Logger.getLogger(CxfFindListenerHook.class.getName());
-
-
- private final static String CLASS_NAME_EXPRESSION =
- ".*\\(" + Constants.OBJECTCLASS + "=([a-zA-Z_0-9.]+)\\).*";
- private final static Pattern CLASS_NAME_PATTERN =
- Pattern.compile(CLASS_NAME_EXPRESSION);
- private final static String CLASS_NAME_BASE =
- "(" + Constants.OBJECTCLASS + "=";
- private static final Set<String> SYSTEM_PACKAGES;
-
- static {
- SYSTEM_PACKAGES = new HashSet<String>();
- SYSTEM_PACKAGES.add("org.osgi.service");
- SYSTEM_PACKAGES.add("org.apache.felix");
- SYSTEM_PACKAGES.add("org.ops4j.pax.logging");
- SYSTEM_PACKAGES.add("ch.ethz.iks.slp");
- SYSTEM_PACKAGES.add("org.ungoverned.osgi.service");
- SYSTEM_PACKAGES.add("org.springframework.osgi.context.event.OsgiBundleApplicationContextListener");
- SYSTEM_PACKAGES.add("java.net.ContentHandler");
- }
-
- public CxfFindListenerHook(BundleContext bc, CxfDistributionProvider dp) {
- super(bc, dp);
- }
-
- public void added(Collection /*<? extends ListenerHook.ListenerInfo>*/ listeners) {
- handleListeners(listeners);
- }
- public void removed(Collection /*<? extends ListenerHook.ListenerInfo>*/ listener) {
- // todo add this in - need to unregister the endpoints
- }
-
- private void handleListeners(Collection/*<? extends ListenerHook.ListenerInfo>*/ listeners) {
- for (Iterator/*<? extends ListenerHook.ListenerInfo>*/ it = listeners.iterator(); it.hasNext(); ) {
- ListenerHook.ListenerInfo listener = (ListenerHook.ListenerInfo) it.next();
-
- String className = getClassNameFromFilter(listener.getFilter());
-
- if (!(listener.getFilter() == null
- || listener.getBundleContext() == getContext()
- || isClassExcluded(className))) {
-
- if (onlyClassNameInFilter(className, listener.getFilter())) {
- lookupDiscoveryService(className, null);
- } else {
- String filter = listener.getFilter().replaceAll("objectClass",
- SERVICE_INTERFACE_NAME);
- lookupDiscoveryService(null, filter);
- }
- }
- }
- }
-
- public void find(BundleContext context, String className, String filter, boolean allServices,
- Collection /* <? extends ServiceReference> */ references) {
- lookupDiscoveryService(className, filter);
+ public void added(Collection listeners) {
+ // TODO Auto-generated method stub
+
}
- private String getClassNameFromFilter(String filter) {
- if (filter != null) {
- Matcher matcher = CLASS_NAME_PATTERN.matcher(filter);
- if (matcher.matches() && matcher.groupCount() >= 1) {
- return matcher.group(1);
- }
- }
- return null;
+ public void removed(Collection listeners) {
+ // TODO Auto-generated method stub
+
}
- private boolean onlyClassNameInFilter(String className, String filter) {
- return (CLASS_NAME_BASE + className + ")").equals(filter);
- }
-
- private static boolean isClassExcluded(String className) {
- if (className == null) {
- return true;
- }
+ public void find(BundleContext context, String name, String filter, boolean allServices,
+ Collection references) {
+ // TODO Auto-generated method stub
- for (String p : SYSTEM_PACKAGES) {
- if (className.startsWith(p)) {
- LOG.fine("Lookup for " + className + " is ignored");
- return true;
- }
- }
- return false;
}
+// private static final Logger LOG = Logger.getLogger(CxfFindListenerHook.class.getName());
+//
+//
+// private final static String CLASS_NAME_EXPRESSION =
+// ".*\\(" + Constants.OBJECTCLASS + "=([a-zA-Z_0-9.]+)\\).*";
+// private final static Pattern CLASS_NAME_PATTERN =
+// Pattern.compile(CLASS_NAME_EXPRESSION);
+// private final static String CLASS_NAME_BASE =
+// "(" + Constants.OBJECTCLASS + "=";
+// private static final Set<String> SYSTEM_PACKAGES;
+//
+// static {
+// SYSTEM_PACKAGES = new HashSet<String>();
+// SYSTEM_PACKAGES.add("org.osgi.service");
+// SYSTEM_PACKAGES.add("org.apache.felix");
+// SYSTEM_PACKAGES.add("org.ops4j.pax.logging");
+// SYSTEM_PACKAGES.add("ch.ethz.iks.slp");
+// SYSTEM_PACKAGES.add("org.ungoverned.osgi.service");
+// SYSTEM_PACKAGES.add("org.springframework.osgi.context.event.OsgiBundleApplicationContextListener");
+// SYSTEM_PACKAGES.add("java.net.ContentHandler");
+// }
+//
+// public CxfFindListenerHook(BundleContext bc, CxfRemoteServiceAdmin dp) {
+// super(bc, dp);
+// }
+//
+// public void added(Collection /*<? extends ListenerHook.ListenerInfo>*/ listeners) {
+// handleListeners(listeners);
+// }
+//
+// public void removed(Collection /*<? extends ListenerHook.ListenerInfo>*/ listener) {
+// // todo add this in - need to unregister the endpoints
+// }
+//
+// private void handleListeners(Collection/*<? extends ListenerHook.ListenerInfo>*/ listeners) {
+// for (Iterator/*<? extends ListenerHook.ListenerInfo>*/ it = listeners.iterator(); it.hasNext(); ) {
+// ListenerHook.ListenerInfo listener = (ListenerHook.ListenerInfo) it.next();
+//
+// String className = getClassNameFromFilter(listener.getFilter());
+//
+// if (!(listener.getFilter() == null
+// || listener.getBundleContext() == getContext()
+// || isClassExcluded(className))) {
+//
+// if (onlyClassNameInFilter(className, listener.getFilter())) {
+// lookupDiscoveryService(className, null);
+// } else {
+// String filter = listener.getFilter().replaceAll("objectClass",
+// SERVICE_INTERFACE_NAME);
+// lookupDiscoveryService(null, filter);
+// }
+// }
+// }
+// }
+//
+// public void find(BundleContext context, String className, String filter, boolean allServices,
+// Collection /* <? extends ServiceReference> */ references) {
+// lookupDiscoveryService(className, filter);
+// }
+//
+// private String getClassNameFromFilter(String filter) {
+// if (filter != null) {
+// Matcher matcher = CLASS_NAME_PATTERN.matcher(filter);
+// if (matcher.matches() && matcher.groupCount() >= 1) {
+// return matcher.group(1);
+// }
+// }
+// return null;
+// }
+//
+// private boolean onlyClassNameInFilter(String className, String filter) {
+// return (CLASS_NAME_BASE + className + ")").equals(filter);
+// }
+//
+// private static boolean isClassExcluded(String className) {
+// if (className == null) {
+// return true;
+// }
+//
+// for (String p : SYSTEM_PACKAGES) {
+// if (className.startsWith(p)) {
+// LOG.fine("Lookup for " + className + " is ignored");
+// return true;
+// }
+// }
+// return false;
+// }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java Thu Dec 17 11:28:30 2009
@@ -18,128 +18,114 @@
*/
package org.apache.cxf.dosgi.dsw.hooks;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cxf.dosgi.dsw.OsgiUtils;
-import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
-import org.apache.cxf.endpoint.Server;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.discovery.ServiceEndpointDescription;
public class CxfPublishHook extends AbstractHook {
-
- protected Map<ServiceReference, List<EndpointInfo>> endpoints =
- new LinkedHashMap<ServiceReference, List<EndpointInfo>>();
- private Map<ServiceReference, ServiceRegistration> publications =
- new LinkedHashMap<ServiceReference, ServiceRegistration>();
-
- public CxfPublishHook(BundleContext bc, CxfDistributionProvider dpService) {
- super(bc, dpService);
- }
-
- public void publishEndpoint(ServiceReference sref) {
- synchronized (endpoints) {
- if (endpoints.containsKey(sref)) {
- return;
- }
- }
-
- if (ServiceHookUtils.isCreatedByDsw(sref)) {
- return;
- }
-
- ServiceEndpointDescription sd = null;
- if (checkBundle()) {
- sd = OsgiUtils.getRemoteReference(sref, true);
- }
- // TODO
- // update DSW to check 'local' remote-services metadata either
- // by accepting Configuration Admin Service updates or checking
- // local configuration data, if any available - it will let
- // this code to check for SDs from the additional source
-
- String[] publishableInterfaces =
- sd != null
- ? OsgiUtils.getPublishableInterfaces(sd, sref)
- : null;
- if (publishableInterfaces == null || publishableInterfaces.length == 0) {
- return;
- }
-
- ServiceEndpointDescription[] flatList =
- OsgiUtils.flattenServiceDescription(sd);
- for (int i = 0; i < publishableInterfaces.length; i++) {
- boolean isPublished = false;
- Server server = createServer(sref, flatList[i]);
- if (server != null) {
- ServiceRegistration publication =
- ServiceHookUtils.publish(getContext(), sref, flatList[i]);
- publications.put(sref, publication);
- isPublished = publication != null;
- }
-
- synchronized(endpoints) {
- EndpointInfo ei = new EndpointInfo(getContext(),
- flatList[i],
- server,
- isPublished);
- if (endpoints.containsKey(sref)) {
- endpoints.get(sref).add(ei);
- } else {
- List<EndpointInfo> endpointList =
- new ArrayList<EndpointInfo>();
- endpointList.add(ei);
- endpoints.put(sref, endpointList);
- }
- }
- }
- }
-
- Server createServer(ServiceReference sref, ServiceEndpointDescription sd) {
- return ServiceHookUtils.createServer(
- getHandler(sd, getHandlerProperties()), sref, getContext(),
- sref.getBundle().getBundleContext(), sd, getContext().getService(sref));
- }
-
- public void removeEndpoint(ServiceReference sref) {
- List<EndpointInfo> endpointList = null;
- synchronized(endpoints) {
- endpointList = endpoints.remove(sref);
- }
- if (endpointList != null) {
- for (EndpointInfo ei : endpointList) {
- ServiceHookUtils.unregisterServer(publications.get(sref), ei);
- }
- }
- }
-
- public void removeEndpoints() {
- synchronized(endpoints) {
- for (ServiceReference sref : endpoints.keySet()) {
- List<EndpointInfo> endpointList = endpoints.get(sref);
- for (EndpointInfo ei : endpointList) {
- ServiceHookUtils.unregisterServer(publications.get(sref),
- ei);
- }
- }
- endpoints.clear();
- }
-
- }
-
- public Map<ServiceReference, List<EndpointInfo>> getEndpoints() {
- return Collections.unmodifiableMap(endpoints);
- }
-
- protected ConfigurationTypeHandler getHandler(ServiceEndpointDescription sd,
- Map<String, Object> props) {
- return ServiceHookUtils.getHandler(getContext(), sd, getDistributionProvider(), props);
- }
+//
+// protected Map<ServiceReference, List<EndpointInfo>> endpoints =
+// new LinkedHashMap<ServiceReference, List<EndpointInfo>>();
+// private Map<ServiceReference, ServiceRegistration> publications =
+// new LinkedHashMap<ServiceReference, ServiceRegistration>();
+//
+// public CxfPublishHook(BundleContext bc, CxfRemoteServiceAdmin dpService) {
+// super(bc, dpService);
+// }
+//
+// public void publishEndpoint(ServiceReference sref) {
+// synchronized (endpoints) {
+// if (endpoints.containsKey(sref)) {
+// return;
+// }
+// }
+//
+// if (ServiceHookUtils.isCreatedByDsw(sref)) {
+// return;
+// }
+//
+// EndpointDescription sd = null;
+// if (checkBundle()) {
+// sd = OsgiUtils.getRemoteReference(sref, true);
+// }
+// // TODO
+// // update DSW to check 'local' remote-services metadata either
+// // by accepting Configuration Admin Service updates or checking
+// // local configuration data, if any available - it will let
+// // this code to check for SDs from the additional source
+//
+// String[] publishableInterfaces =
+// sd != null
+// ? OsgiUtils.getPublishableInterfaces(sd, sref)
+// : null;
+// if (publishableInterfaces == null || publishableInterfaces.length == 0) {
+// return;
+// }
+//
+// ServiceEndpointDescription[] flatList =
+// OsgiUtils.flattenServiceDescription(sd);
+// for (int i = 0; i < publishableInterfaces.length; i++) {
+// boolean isPublished = false;
+// Server server = createServer(sref, flatList[i]);
+// if (server != null) {
+// ServiceRegistration publication =
+// ServiceHookUtils.publish(getContext(), sref, flatList[i]);
+// publications.put(sref, publication);
+// isPublished = publication != null;
+// }
+//
+// synchronized(endpoints) {
+// EndpointInfo ei = new EndpointInfo(getContext(),
+// flatList[i],
+// server,
+// isPublished);
+// if (endpoints.containsKey(sref)) {
+// endpoints.get(sref).add(ei);
+// } else {
+// List<EndpointInfo> endpointList =
+// new ArrayList<EndpointInfo>();
+// endpointList.add(ei);
+// endpoints.put(sref, endpointList);
+// }
+// }
+// }
+// }
+//
+// Server createServer(ServiceReference sref, EndpointDescription sd) {
+// return ServiceHookUtils.createServer(
+// getHandler(sd, getHandlerProperties()), sref, getContext(),
+// sref.getBundle().getBundleContext(), sd, getContext().getService(sref));
+// }
+//
+// public void removeEndpoint(ServiceReference sref) {
+// List<EndpointInfo> endpointList = null;
+// synchronized(endpoints) {
+// endpointList = endpoints.remove(sref);
+// }
+// if (endpointList != null) {
+// for (EndpointInfo ei : endpointList) {
+// ServiceHookUtils.unregisterServer(publications.get(sref), ei);
+// }
+// }
+// }
+//
+// public void removeEndpoints() {
+// synchronized(endpoints) {
+// for (ServiceReference sref : endpoints.keySet()) {
+// List<EndpointInfo> endpointList = endpoints.get(sref);
+// for (EndpointInfo ei : endpointList) {
+// ServiceHookUtils.unregisterServer(publications.get(sref),
+// ei);
+// }
+// }
+// endpoints.clear();
+// }
+//
+// }
+//
+// public Map<ServiceReference, List<EndpointInfo>> getEndpoints() {
+// return Collections.unmodifiableMap(endpoints);
+// }
+//
+// protected ConfigurationTypeHandler getHandler(EndpointDescription sd,
+// Map<String, Object> props) {
+// return ServiceHookUtils.getHandler(getContext(), sd, props);
+// }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java?rev=891650&r1=891649&r2=891650&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java Thu Dec 17 11:28:30 2009
@@ -1,161 +1,127 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.hooks;
-import static org.osgi.service.discovery.ServicePublication.ENDPOINT_ID;
-import static org.osgi.service.discovery.ServicePublication.ENDPOINT_LOCATION;
-import static org.osgi.service.discovery.ServicePublication.SERVICE_INTERFACE_NAME;
-import static org.osgi.service.discovery.ServicePublication.SERVICE_PROPERTIES;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.UUID;
-import java.util.logging.Logger;
-
-import org.apache.cxf.dosgi.dsw.ClassUtils;
-import org.apache.cxf.dosgi.dsw.Constants;
-import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
-import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
-import org.apache.cxf.dosgi.dsw.handlers.IntentUnsatifiedException;
-import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
-import org.apache.cxf.endpoint.Server;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.discovery.ServiceEndpointDescription;
-import org.osgi.service.discovery.ServicePublication;
public final class ServiceHookUtils {
-
- private static final Logger LOG = Logger.getLogger(ServiceHookUtils.class.getName());
-
- private ServiceHookUtils() {
-
- }
-
- public static ServiceRegistration publish(BundleContext bc, final ServiceReference sr, ServiceEndpointDescription sd) {
- ServiceRegistration publication = bc.registerService(
- ServicePublication.class.getName(), new ServicePublication() {
- public ServiceReference getReference() {
- return sr;
- }
- }, getPublicationProperties(sd));
-
- if (publication != null) {
- LOG.info("Remote " + sd.getProvidedInterfaces().toArray()[0]
- + " endpoint published via Discovery service");
- }
- return publication;
- }
-
- public static Server createServer(ConfigurationTypeHandler handler,
- ServiceReference serviceReference,
- BundleContext dswContext,
- BundleContext callingContext,
- ServiceEndpointDescription sd,
- Object serviceObject) {
-
- if (handler == null) {
- return null;
- }
-
- String interfaceName = (String)sd.getProvidedInterfaces().toArray()[0];
- // this is an extra sanity check, but do we really need it now ?
- Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, interfaceName);
-
- if (interfaceClass != null) {
- try {
- return handler.createServer(serviceReference,
- dswContext,
- callingContext,
- sd,
- interfaceClass,
- serviceObject);
- } catch (IntentUnsatifiedException iue) {
- LOG.info("Did not remote service " + interfaceName
- + " because intent " + iue.getIntent()
- + " could not be satisfied");
- } catch (Exception ex) {
- LOG.warning("WARNING : Problem creating a remote endpoint for " + interfaceName
- + " from CXF PublishHook, reason is " + ex.getMessage());
- ex.printStackTrace();
- }
- }
-
- return null;
- }
-
- public static void unregisterServer(ServiceRegistration publication,
- EndpointInfo ei) {
-
- try {
- Server server = ei.getServer();
-
- LOG.info("Stopping CXF Endpoint at "
- + server.getDestination().getAddress().getAddress().getValue());
- server.getDestination().shutdown();
- server.stop();
- } catch (Exception ex) {
- // continue
- }
-
- if (ei.isPublished()) {
- LOG.info("Unpublishing Service Description for "
- + ei.getServiceDescription().getProvidedInterfaces().toArray()[0]
- + " from a Discovery service ");
- publication.unregister();
- }
- }
-
- public static ConfigurationTypeHandler getHandler(BundleContext dswBC,
- ServiceEndpointDescription sd,
- CxfDistributionProvider dp,
- Map<String, Object> dswProperties) {
- return ConfigTypeHandlerFactory.getInstance().getHandler(dswBC, sd, dp,
- dswProperties);
- }
-
- public static boolean isCreatedByDsw(ServiceReference sref) {
- return sref != null && sref.getProperty(Constants.DSW_CLIENT_ID) != null;
- }
-
- private static Map<String, Object> getServiceProperties(ServiceEndpointDescription sd) {
- Map<String, Object> props = new HashMap<String, Object>();
- for (Object key : sd.getPropertyKeys()) {
- props.put(key.toString(), sd.getProperty(key.toString()));
- }
- LOG.info("service properties: " + props);
- return props;
- }
- @SuppressWarnings("unchecked")
- private static Dictionary getPublicationProperties(ServiceEndpointDescription sd) {
- Dictionary props = new Hashtable();
- props.put(SERVICE_INTERFACE_NAME, sd.getProvidedInterfaces());
- props.put(SERVICE_PROPERTIES, getServiceProperties(sd));
- props.put(ENDPOINT_ID, UUID.randomUUID().toString());
- if (sd.getLocation() != null) {
- props.put(ENDPOINT_LOCATION, sd.getLocation());
- }
- LOG.info("publication properties: " + props);
- return props;
- }
+// private static final Logger LOG = Logger.getLogger(ServiceHookUtils.class.getName());
+//
+// private ServiceHookUtils() {
+//
+// }
+//
+// public static ServiceRegistration publish(BundleContext bc, final ServiceReference sr,
+// EndpointDescription sd) {
+// ServiceRegistration publication = bc.registerService(ServicePublication.class.getName(),
+// new ServicePublication() {
+// public ServiceReference getReference() {
+// return sr;
+// }
+// }, getPublicationProperties(sd));
+//
+// if (publication != null) {
+// LOG.info("Remote " + sd.getInterfaces().toArray()[0]
+// + " endpoint published via Discovery service");
+// }
+// return publication;
+// }
+//
+// public static Server createServer(ConfigurationTypeHandler handler, ServiceReference serviceReference,
+// BundleContext dswContext, BundleContext callingContext,
+// EndpointDescription sd, Object serviceObject) {
+//
+// if (handler == null) {
+// return null;
+// }
+//
+// String interfaceName = (String)sd.getInterfaces().toArray()[0];
+// // this is an extra sanity check, but do we really need it now ?
+// Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, interfaceName);
+//
+// if (interfaceClass != null) {
+// try {
+// return handler.createServer(serviceReference, dswContext, callingContext, sd, interfaceClass,
+// serviceObject);
+// } catch (IntentUnsatifiedException iue) {
+// LOG.info("Did not remote service " + interfaceName + " because intent " + iue.getIntent()
+// + " could not be satisfied");
+// } catch (Exception ex) {
+// LOG.warning("WARNING : Problem creating a remote endpoint for " + interfaceName
+// + " from CXF PublishHook, reason is " + ex.getMessage());
+// ex.printStackTrace();
+// }
+// }
+//
+// return null;
+// }
+//
+// public static void unregisterServer(ServiceRegistration publication, EndpointInfo ei) {
+//
+// try {
+// Server server = ei.getServer();
+//
+// LOG.info("Stopping CXF Endpoint at "
+// + server.getDestination().getAddress().getAddress().getValue());
+// server.getDestination().shutdown();
+// server.stop();
+// } catch (Exception ex) {
+// // continue
+// }
+//
+// if (ei.isPublished()) {
+// LOG.info("Unpublishing Service Description for "
+// + ei.getServiceDescription().getProvidedInterfaces().toArray()[0]
+// + " from a Discovery service ");
+// publication.unregister();
+// }
+// }
+//
+// public static ConfigurationTypeHandler getHandler(BundleContext dswBC, List<String> configurationTypes,
+// Dictionary serviceProperties, Map<String, Object> props) {
+// return ConfigTypeHandlerFactory.getInstance().getHandler(dswBC, configurationTypes,
+// serviceProperties, props);
+// }
+//
+// public static boolean isCreatedByDsw(ServiceReference sref) {
+// return sref != null && sref.getProperty(Constants.DSW_CLIENT_ID) != null;
+// }
+//
+// private static Map<String, Object> getServiceProperties(EndpointDescription sd) {
+// Map<String, Object> props = sd.getProperties();
+// // for (Object key : sd.getPropertyKeys()) {
+// // props.put(key.toString(), sd.getProperty(key.toString()));
+// // }
+// LOG.info("service properties: " + props);
+// return props;
+// }
+//
+// @SuppressWarnings("unchecked")
+// private static Dictionary getPublicationProperties(EndpointDescription sd) {
+// Dictionary props = new Hashtable();
+// props.put(SERVICE_INTERFACE_NAME, sd.getInterfaces());
+// props.put(SERVICE_PROPERTIES, getServiceProperties(sd));
+// props.put(ENDPOINT_ID, UUID.randomUUID().toString());
+// if (sd.getRemoteURI() != null) {
+// props.put(ENDPOINT_LOCATION, sd.getRemoteURI());
+// }
+// LOG.info("publication properties: " + props);
+// return props;
+// }
}
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java?rev=891650&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java Thu Dec 17 11:28:30 2009
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.dosgi.dsw.service;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.ExportRegistration;
+import org.osgi.service.remoteserviceadmin.ImportRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
+
+public class EventProducer {
+
+ private BundleContext bctx;
+ private EventAdminHelper eaHelper;
+
+ private Logger LOG = Logger.getLogger(EventProducer.class.getName());
+
+ public EventProducer(BundleContext bc) {
+ bctx = bc;
+ eaHelper = new EventAdminHelper(bctx);
+ }
+
+ protected void publishNotifcation(List<ExportRegistrationImpl> erl) {
+ for (ExportRegistration exportRegistration : erl) {
+ publishNotifcation(exportRegistration);
+ }
+ }
+
+ protected void publishNotifcation(ExportRegistration er) {
+ RemoteServiceAdminEvent rsae = null;
+ if (er.getException() != null) {
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_ERROR, bctx.getBundle(), er.getExportReference(), er
+ .getException());
+ } else {
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, bctx.getBundle(),
+ er.getExportReference(), er.getException());
+ }
+
+ notifyListeners(rsae);
+ eaHelper.notifyEventAdmin(rsae);
+ }
+
+ private void notifyListeners(RemoteServiceAdminEvent rsae) {
+ try {
+ ServiceReference[] listenerRefs = bctx.getServiceReferences(RemoteServiceAdminListener.class
+ .getName(), null);
+ if (listenerRefs != null) {
+ for (ServiceReference sref : listenerRefs) {
+ RemoteServiceAdminListener rsal = (RemoteServiceAdminListener)bctx.getService(sref);
+ LOG.info("::::::::::::::::::::: notify RemoteServiceAdminListener " + rsal
+ + " of bundle " + sref.getBundle().getSymbolicName());
+ rsal.remoteAdminEvent(rsae);
+ }
+ }
+
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected void publishNotifcation(ImportRegistration ir) {
+ RemoteServiceAdminEvent rsae = null;
+ if (ir.getException() != null) {
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_ERROR, bctx.getBundle(), ir.getImportReference(), ir
+ .getException());
+ } else {
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION, bctx.getBundle(),
+ ir.getImportReference(), ir.getException());
+ }
+
+ notifyListeners(rsae);
+ eaHelper.notifyEventAdmin(rsae);
+ }
+
+ public void notifyRemoval(ExportRegistrationImpl eri) {
+ RemoteServiceAdminEvent rsae = null;
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, bctx.getBundle(), eri.getExportReference(), eri.getException());
+
+ notifyListeners(rsae);
+ eaHelper.notifyEventAdmin(rsae);
+ }
+
+
+ public void notifyRemoval(ImportRegistrationImpl eri) {
+ RemoteServiceAdminEvent rsae = null;
+ rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, bctx.getBundle(), eri.getImportReference(), eri.getException());
+
+ notifyListeners(rsae);
+ eaHelper.notifyEventAdmin(rsae);
+ }
+
+}
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date