Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5219A10940 for ; Tue, 11 Jun 2013 22:30:12 +0000 (UTC) Received: (qmail 87741 invoked by uid 500); 11 Jun 2013 22:30:12 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 87621 invoked by uid 500); 11 Jun 2013 22:30:12 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 87614 invoked by uid 99); 11 Jun 2013 22:30:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jun 2013 22:30:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jun 2013 22:29:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 605402388A29; Tue, 11 Jun 2013 22:29:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1491995 [1/2] - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/ discovery/dis... Date: Tue, 11 Jun 2013 22:29:28 -0000 To: commits@cxf.apache.org From: amichai@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130611222930.605402388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: amichai Date: Tue Jun 11 22:29:27 2013 New Revision: 1491995 URL: http://svn.apache.org/r1491995 Log: Begin consolidating utility classes and methods Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java - copied, changed from r1491250, cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java - copied, changed from r1491250, cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtils.java - copied, changed from r1491250, cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/util/EndpointUtilsTest.java - copied, changed from r1491250, cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounter.java - copied, changed from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounter.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/Utils.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/ReferenceCounterTest.java - copied, changed from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounterTest.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/UtilsTest.java - copied, changed from r1491250, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java Removed: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounter.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ReferenceCounterTest.java Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java cxf/dosgi/trunk/discovery/local/pom.xml cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImport.java cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java Tue Jun 11 22:29:27 2013 @@ -18,9 +18,7 @@ */ package org.apache.cxf.dosgi.discovery.zookeeper; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTrackerCustomizer; import org.slf4j.Logger; @@ -33,7 +31,6 @@ import org.slf4j.LoggerFactory; public class EndpointListenerTrackerCustomizer implements ServiceTrackerCustomizer { private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerTrackerCustomizer.class); - private static final Pattern OBJECTCLASS_PATTERN = Pattern.compile(".*\\(objectClass=([^)]+)\\).*"); private final InterfaceMonitorManager imManager; @@ -67,8 +64,8 @@ public class EndpointListenerTrackerCust } } - for (String scope : Util.getScopes(sref)) { - String objClass = getObjectClass(scope); + for (String scope : Utils.getScopes(sref)) { + String objClass = Utils.getObjectClass(scope); LOG.debug("Adding interest in scope {}, objectClass {}", scope, objClass); imManager.addInterest(sref, scope, objClass); } @@ -79,8 +76,4 @@ public class EndpointListenerTrackerCust sref.getProperty(PublishingEndpointListenerFactory.DISCOVERY_ZOOKEEPER_ID))); } - private static String getObjectClass(String scope) { - Matcher m = OBJECTCLASS_PATTERN.matcher(scope); - return m.matches() ? m.group(1) : null; - } } Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java Tue Jun 11 22:29:27 2013 @@ -18,12 +18,12 @@ */ package org.apache.cxf.dosgi.discovery.zookeeper; -import java.io.ByteArrayInputStream; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.cxf.dosgi.discovery.local.LocalDiscoveryUtils; +import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils; +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.apache.zookeeper.AsyncCallback.StatCallback; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.Code; @@ -31,7 +31,6 @@ import org.apache.zookeeper.WatchedEvent import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.Stat; -import org.jdom.Element; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.EndpointListener; import org.slf4j.Logger; @@ -60,7 +59,7 @@ public class InterfaceMonitor implements public InterfaceMonitor(ZooKeeper zk, String intf, EndpointListener epListener, String scope) { this.zookeeper = zk; - this.znode = Util.getZooKeeperPath(intf); + this.znode = Utils.getZooKeeperPath(intf); this.recursive = intf == null || intf.isEmpty(); this.epListener = epListener; LOG.debug("Creating new InterfaceMonitor {} for scope [{}] and objectClass [{}]", @@ -218,9 +217,9 @@ public class InterfaceMonitor implements byte[] data = zookeeper.getData(node, false, null); LOG.debug("Got data for node: {}", node); - List elements = LocalDiscoveryUtils.getElements(new ByteArrayInputStream(data)); - if (!elements.isEmpty()) { - return LocalDiscoveryUtils.getEndpointDescription(elements.get(0)); + EndpointDescription endpoint = EndpointUtils.getFirstEnpointDescription(data); + if (endpoint != null) { + return endpoint; } LOG.warn("No Discovery information found for node: {}", node); } catch (Exception e) { Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java Tue Jun 11 22:29:27 2013 @@ -19,18 +19,14 @@ package org.apache.cxf.dosgi.discovery.zookeeper; import java.util.ArrayList; -import java.util.Dictionary; import java.util.HashMap; -import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.cxf.dosgi.discovery.local.util.Utils; import org.apache.zookeeper.ZooKeeper; import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.EndpointListener; @@ -148,7 +144,7 @@ public class InterfaceMonitorManager { } EndpointListener epl = (EndpointListener) service; LOG.debug("matching {} against {}", epd, currentScope); - if (matches(currentScope, epd)) { + if (Utils.matchFilter(bctx, currentScope, epd)) { LOG.debug("Matched {} against {}", epd, currentScope); if (isAdded) { LOG.info("calling EndpointListener.endpointAdded: " + epl + " from bundle " @@ -168,17 +164,6 @@ public class InterfaceMonitorManager { } } - private static boolean matches(String scope, EndpointDescription epd) { - try { - Filter f = FrameworkUtil.createFilter(scope); - Dictionary dict = new Hashtable(epd.getProperties()); - return f.match(dict); - } catch (InvalidSyntaxException e) { - LOG.error("Scope [" + scope + "] resulted in an invalid filter!", e); - return false; - } - } - public synchronized void close() { for (Interest interest : interestingScopes.values()) { interest.im.close(); Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java Tue Jun 11 22:29:27 2013 @@ -28,7 +28,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.cxf.dosgi.discovery.local.LocalDiscoveryUtils; +import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils; +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs.Ids; @@ -96,7 +97,7 @@ public class PublishingEndpointListener } for (String name : interfaces) { - String path = Util.getZooKeeperPath(name); + String path = Utils.getZooKeeperPath(name); String fullPath = path + '/' + endpointKey; LOG.debug("Creating ZooKeeper node: {}", fullPath); ensurePath(path, zookeeper); @@ -129,7 +130,7 @@ public class PublishingEndpointListener String endpointKey = getKey(endpoint.getId()); for (String name : interfaces) { - String path = Util.getZooKeeperPath(name); + String path = Utils.getZooKeeperPath(name); String fullPath = path + '/' + endpointKey; LOG.debug("Removing ZooKeeper node: {}", fullPath); try { @@ -142,7 +143,7 @@ public class PublishingEndpointListener private static void ensurePath(String path, ZooKeeper zk) throws KeeperException, InterruptedException { StringBuilder current = new StringBuilder(); - String[] parts = Util.removeEmpty(path.split("/")); + String[] parts = Utils.removeEmpty(path.split("/")); for (String part : parts) { current.append('/'); current.append(part); @@ -153,7 +154,7 @@ public class PublishingEndpointListener } static byte[] getData(Map props) { - return LocalDiscoveryUtils.getEndpointDescriptionXML(props).getBytes(); + return EndpointUtils.getEndpointDescriptionXML(props).getBytes(); } static String getKey(String endpoint) throws URISyntaxException { Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListenerFactory.java Tue Jun 11 22:29:27 2013 @@ -23,6 +23,7 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.List; +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.apache.zookeeper.ZooKeeper; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -74,7 +75,7 @@ public class PublishingEndpointListenerF Dictionary props = new Hashtable(); props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(&(" + Constants.OBJECTCLASS + "=*)(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID - + "=" + Util.getUUID(bctx) + "))"); + + "=" + Utils.getUUID(bctx) + "))"); props.put(DISCOVERY_ZOOKEEPER_ID, "true"); serviceRegistration = bctx.registerService(EndpointListener.class.getName(), this, props); } Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java Tue Jun 11 22:29:27 2013 @@ -21,6 +21,7 @@ package org.apache.cxf.dosgi.discovery.z import java.io.IOException; import java.util.Dictionary; +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooKeeper; @@ -98,25 +99,18 @@ public class ZooKeeperDiscovery implemen @SuppressWarnings("rawtypes") private synchronized void createZooKeeper(Dictionary props) { - String zkHost = getProp(props, "zookeeper.host", "localhost"); - String zkPort = getProp(props, "zookeeper.port", "2181"); - int zkTimeout = Integer.parseInt(getProp(props, "zookeeper.timeout", "3000")); + String host = Utils.getProp(props, "zookeeper.host", "localhost"); + String port = Utils.getProp(props, "zookeeper.port", "2181"); + int timeout = Utils.getProp(props, "zookeeper.timeout", 3000); + LOG.debug("ZooKeeper configuration: connecting to {}:{} with timeout {}", + new Object[]{host, port, timeout}); try { - zooKeeper = new ZooKeeper(zkHost + ":" + zkPort, zkTimeout, this); + zooKeeper = new ZooKeeper(host + ":" + port, timeout, this); } catch (IOException e) { LOG.error("Failed to start the Zookeeper Discovery component.", e); } } - @SuppressWarnings("rawtypes") - private static String getProp(Dictionary props, String key, String def) { - Object val = props.get(key); - String rv = val == null ? def : val.toString(); - - LOG.debug("Reading Config Admin property: {} value returned: {}", key, rv); - return rv; - } - /* Callback for ZooKeeper */ public void process(WatchedEvent event) { switch (event.getState()) { Copied: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java (from r1491250, cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java) URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java?p2=cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java&p1=cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java&r1=1491250&r2=1491995&rev=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java Tue Jun 11 22:29:27 2013 @@ -16,29 +16,30 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cxf.dosgi.discovery.zookeeper; +package org.apache.cxf.dosgi.discovery.zookeeper.util; import java.util.Arrays; import java.util.Collection; +import java.util.Dictionary; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointListener; -public final class Util { +public final class Utils { static final String PATH_PREFIX = "/osgi/service_registry"; + static final Pattern OBJECTCLASS_PATTERN = Pattern.compile(".*\\(objectClass=([^)]+)\\).*"); - private Util() { + private Utils() { // never constructed } - static String getZooKeeperPath(String name) { - if (name == null || "".equals(name)) { - return PATH_PREFIX; - } - return PATH_PREFIX + '/' + name.replace('.', '/'); + public static String getZooKeeperPath(String name) { + return name == null || name.isEmpty() ? PATH_PREFIX : PATH_PREFIX + '/' + name.replace('.', '/'); } /** @@ -103,4 +104,21 @@ public final class Util { return uuid; } } + + @SuppressWarnings("rawtypes") + public static String getProp(Dictionary props, String key, String def) { + Object val = props.get(key); + return val == null ? def : val.toString(); + } + + @SuppressWarnings("rawtypes") + public static int getProp(Dictionary props, String key, int def) { + Object val = props.get(key); + return val == null ? def : Integer.parseInt(val.toString()); + } + + public static String getObjectClass(String scope) { + Matcher m = OBJECTCLASS_PATTERN.matcher(scope); + return m.matches() ? m.group(1) : null; + } } Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java Tue Jun 11 22:29:27 2013 @@ -78,7 +78,7 @@ public class FindInZooKeeperCustomizerTe // InterfaceMonitor dm = dmList.iterator().next(); // assertNotNull(dm.listener); // assertSame(zk, dm.zookeeper); -// assertEquals(Util.getZooKeeperPath(String.class.getName()), dm.znode); +// assertEquals(Utils.getZooKeeperPath(String.class.getName()), dm.znode); // // assertEquals("Precondition failed", 1, fc.watchers.size()); // fc.addingService(sr2); @@ -95,8 +95,8 @@ public class FindInZooKeeperCustomizerTe // actual.add(im.znode); // } // Set expected = new HashSet(Arrays.asList( -// Util.getZooKeeperPath(Integer.class.getName()), -// Util.getZooKeeperPath(Comparable.class.getName()))); +// Utils.getZooKeeperPath(Integer.class.getName()), +// Utils.getZooKeeperPath(Comparable.class.getName()))); // assertEquals(expected, actual); // // EasyMock.verify(zk); @@ -124,7 +124,7 @@ public class FindInZooKeeperCustomizerTe // assertEquals(dmList2, fc.watchers.get(dst2)); // List dmList3 = fc.watchers.get(dst); // assertEquals(1, dmList3.size()); -// assertEquals(Util.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode); +// assertEquals(Utils.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode); // // EasyMock.verify(zk); // @@ -199,7 +199,7 @@ public class FindInZooKeeperCustomizerTe // InterfaceMonitor dm = dmList.iterator().next(); // assertNotNull(dm.listener); // assertSame(zk, dm.zookeeper); -// assertEquals(Util.getZooKeeperPath(String.class.getName()), dm.znode); +// assertEquals(Utils.getZooKeeperPath(String.class.getName()), dm.znode); // // assertEquals("Precondition failed", 1, fc.watchers.size()); // fc.addingService(sr2); @@ -215,8 +215,8 @@ public class FindInZooKeeperCustomizerTe // actual.add(im.znode); // } // Set expected = new HashSet(Arrays.asList( -// Util.getZooKeeperPath(Integer.class.getName()), -// Util.getZooKeeperPath(Comparable.class.getName()))); +// Utils.getZooKeeperPath(Integer.class.getName()), +// Utils.getZooKeeperPath(Comparable.class.getName()))); // assertEquals(expected, actual); // // EasyMock.verify(zk); @@ -245,7 +245,7 @@ public class FindInZooKeeperCustomizerTe // assertEquals(dmList2, fc.watchers.get(dst2)); // List dmList3 = fc.watchers.get(dst); // assertEquals(1, dmList3.size()); -// assertEquals(Util.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode); +// assertEquals(Utils.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode); // // EasyMock.verify(zk); // @@ -287,7 +287,7 @@ public class FindInZooKeeperCustomizerTe // } // // private void zkExpectExists(ZooKeeper zk, String className) { -// zk.exists(EasyMock.eq(Util.getZooKeeperPath(className)), +// zk.exists(EasyMock.eq(Utils.getZooKeeperPath(className)), // (Watcher) EasyMock.anyObject(), // (StatCallback) EasyMock.anyObject(), EasyMock.isNull()); // EasyMock.expectLastCall().andAnswer(new IAnswer() { Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java Tue Jun 11 22:29:27 2013 @@ -44,9 +44,9 @@ public class InterfaceDataMonitorListene // initial.store(propBytes, ""); // // ZooKeeper zk = EasyMock.createMock(ZooKeeper.class); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Arrays.asList("x#y#z")); -// EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) +// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) // .andReturn(propBytes.toByteArray()); // EasyMock.replay(zk); // @@ -72,9 +72,9 @@ public class InterfaceDataMonitorListene // // // Again with the same data // EasyMock.reset(zk); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Arrays.asList("x#y#z")); -// EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) +// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) // .andReturn(propBytes.toByteArray()); // EasyMock.replay(zk); // @@ -95,9 +95,9 @@ public class InterfaceDataMonitorListene // modified.store(modBytes, ""); // // EasyMock.reset(zk); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Arrays.asList("x#y#z")); -// EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) +// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) // .andReturn(modBytes.toByteArray()); // EasyMock.replay(zk); // @@ -127,9 +127,9 @@ public class InterfaceDataMonitorListene // modified2.store(modBytes2, ""); // // EasyMock.reset(zk); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Arrays.asList("x#y#z")); -// EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) +// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null)) // .andReturn(modBytes2.toByteArray()); // EasyMock.replay(zk); // @@ -150,7 +150,7 @@ public class InterfaceDataMonitorListene // // Test DiscoveredServiceNotification.UNAVAILABLE // //---------------------------------------------------------------- // EasyMock.reset(zk); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Collections.emptyList()); // EasyMock.replay(zk); // @@ -170,7 +170,7 @@ public class InterfaceDataMonitorListene // // // Try the same again... // EasyMock.reset(zk); -// EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)) +// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false)) // .andReturn(Collections.emptyList()); // EasyMock.replay(zk); // Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java Tue Jun 11 22:29:27 2013 @@ -22,6 +22,7 @@ import java.util.Collections; import junit.framework.TestCase; +import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher.Event.EventType; @@ -45,7 +46,7 @@ public class InterfaceMonitorTest extend String scope = "(myProp=test)"; String interf = "es.schaaf.test"; - String node = Util.getZooKeeperPath(interf); + String node = Utils.getZooKeeperPath(interf); EndpointListener epListener = c.createMock(EndpointListener.class); InterfaceMonitor im = new InterfaceMonitor(zk, interf, epListener, scope); Copied: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java (from r1491250, cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java) URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java?p2=cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java&p1=cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java&r1=1491250&r2=1491995&rev=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java (original) +++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java Tue Jun 11 22:29:27 2013 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cxf.dosgi.discovery.zookeeper; +package org.apache.cxf.dosgi.discovery.zookeeper.util; import java.util.Arrays; @@ -27,64 +27,64 @@ import org.easymock.classextension.IMock import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointListener; -public class UtilTest extends TestCase { +public class UtilsTest extends TestCase { public void testGetZooKeeperPath() { - assertEquals(Util.PATH_PREFIX + '/' + "org/example/Test", - Util.getZooKeeperPath("org.example.Test")); + assertEquals(Utils.PATH_PREFIX + '/' + "org/example/Test", + Utils.getZooKeeperPath("org.example.Test")); // used for the recursive discovery - assertEquals(Util.PATH_PREFIX, Util.getZooKeeperPath(null)); - assertEquals(Util.PATH_PREFIX, Util.getZooKeeperPath("")); + assertEquals(Utils.PATH_PREFIX, Utils.getZooKeeperPath(null)); + assertEquals(Utils.PATH_PREFIX, Utils.getZooKeeperPath("")); } @SuppressWarnings("unchecked") public void testGetStringPlusProperty() { - String[] out = Util.getStringPlusProperty("MyString"); + String[] out = Utils.getStringPlusProperty("MyString"); assertEquals(1, out.length); assertEquals("MyString", out[0]); - out = Util.getStringPlusProperty(new String[]{"MyString"}); + out = Utils.getStringPlusProperty(new String[]{"MyString"}); assertEquals(1, out.length); assertEquals("MyString", out[0]); - out = Util.getStringPlusProperty(Arrays.asList("MyString")); + out = Utils.getStringPlusProperty(Arrays.asList("MyString")); assertEquals(1, out.length); assertEquals("MyString", out[0]); - out = Util.getStringPlusProperty(Arrays.asList(1)); + out = Utils.getStringPlusProperty(Arrays.asList(1)); assertEquals(0, out.length); - out = Util.getStringPlusProperty(new Object()); + out = Utils.getStringPlusProperty(new Object()); assertEquals(0, out.length); - out = Util.getStringPlusProperty(null); + out = Utils.getStringPlusProperty(null); assertEquals(0, out.length); } public void testRemoveEmpty() { - String[] out = Util.removeEmpty(new String[0]); + String[] out = Utils.removeEmpty(new String[0]); assertEquals(0, out.length); - out = Util.removeEmpty(new String[] {null}); + out = Utils.removeEmpty(new String[]{null}); assertEquals(0, out.length); - out = Util.removeEmpty(new String[] {""}); + out = Utils.removeEmpty(new String[]{""}); assertEquals(0, out.length); - out = Util.removeEmpty(new String[] {"hi"}); + out = Utils.removeEmpty(new String[]{"hi"}); assertEquals(1, out.length); assertEquals("hi", out[0]); - out = Util.removeEmpty(new String[] {"", "hi", null}); + out = Utils.removeEmpty(new String[]{"", "hi", null}); assertEquals(1, out.length); assertEquals("hi", out[0]); - out = Util.removeEmpty(new String[] {"hi", null, "", ""}); + out = Utils.removeEmpty(new String[]{"hi", null, "", ""}); assertEquals(1, out.length); assertEquals("hi", out[0]); - out = Util.removeEmpty(new String[] {"", "hi", null, "", "", "bye", null}); + out = Utils.removeEmpty(new String[]{"", "hi", null, "", "", "bye", null}); assertEquals(2, out.length); assertEquals("hi", out[0]); assertEquals("bye", out[1]); @@ -101,7 +101,7 @@ public class UtilTest extends TestCase { c.replay(); - String[] ret = Util.getScopes(sref); + String[] ret = Utils.getScopes(sref); c.verify(); assertEquals(1, ret.length); Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml (original) +++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml Tue Jun 11 22:29:27 2013 @@ -92,7 +92,7 @@ ${project.artifactId} org.apache.cxf.dosgi.discovery.zookeeper.server.Activator * - org.apache.cxf.dosgi.discovery.zookeeper.server + org.apache.cxf.dosgi.discovery.zookeeper.server.* Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java (original) +++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java Tue Jun 11 22:29:27 2013 @@ -20,12 +20,11 @@ package org.apache.cxf.dosgi.discovery.z import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Dictionary; import java.util.Enumeration; -import java.util.List; import java.util.Properties; +import org.apache.cxf.dosgi.discovery.zookeeper.server.util.Utils; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.zookeeper.server.ServerConfig; @@ -65,39 +64,12 @@ public class ZookeeperStarter implements } public void setDefaults(Dictionary dict) throws IOException { - removeEmptyValues(dict); - setDefault(dict, "tickTime", "2000"); - setDefault(dict, "initLimit", "10"); - setDefault(dict, "syncLimit", "5"); - setDefault(dict, "clientPort", "2181"); - setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath()); - } - - /** - * Remove empty values to avoid NumberFormatExceptions - * - * @param dict - */ - private void removeEmptyValues(Dictionary dict) { - List keysToRemove = new ArrayList(); - Enumeration keys = dict.keys(); - while (keys.hasMoreElements()) { - String key = keys.nextElement(); - Object value = dict.get(key); - if (value instanceof String && "".equals(value)) { - keysToRemove.add(key); - } - } - for (String key : keysToRemove) { - dict.remove(key); - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private void setDefault(Dictionary dict, String key, String value) { - if (dict.get(key) == null) { - dict.put(key, value); - } + Utils.removeEmptyValues(dict); // to avoid NumberFormatExceptions + Utils.setDefault(dict, "tickTime", "2000"); + Utils.setDefault(dict, "initLimit", "10"); + Utils.setDefault(dict, "syncLimit", "5"); + Utils.setDefault(dict, "clientPort", "2181"); + Utils.setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -130,11 +102,7 @@ public class ZookeeperStarter implements protected void startFromConfig(final QuorumPeerConfig config) { int numServers = config.getServers().size(); - if (numServers > 1) { - main = new MyQuorumPeerMain(config); - } else { - main = new MyZooKeeperServerMain(config); - } + main = numServers > 1 ? new MyQuorumPeerMain(config) : new MyZooKeeperServerMain(config); zkMainThread = new Thread(new Runnable() { public void run() { try { Added: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java?rev=1491995&view=auto ============================================================================== --- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java (added) +++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/util/Utils.java Tue Jun 11 22:29:27 2013 @@ -0,0 +1,68 @@ +/** + * 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.discovery.zookeeper.server.util; + +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.List; + +/** + * General purpose utility methods. + */ +public final class Utils { + + private Utils() { + // prevent instantiation + } + + /** + * Remove entries whose values are empty from the given dictionary. + * + * @param dict a dictionary + */ + public static void removeEmptyValues(Dictionary dict) { + List keysToRemove = new ArrayList(); + Enumeration keys = dict.keys(); + while (keys.hasMoreElements()) { + String key = keys.nextElement(); + Object value = dict.get(key); + if (value instanceof String && "".equals(value)) { + keysToRemove.add(key); + } + } + for (String key : keysToRemove) { + dict.remove(key); + } + } + + /** + * Puts the given key-value pair in the given dictionary if the key does not + * already exist in it or if its existing value is null. + * + * @param dict a dictionary + * @param key the key + * @param value the default value to set + */ + public static void setDefault(Dictionary dict, String key, String value) { + if (dict.get(key) == null) { + dict.put(key, value); + } + } +} Modified: cxf/dosgi/trunk/discovery/local/pom.xml URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/pom.xml?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/local/pom.xml (original) +++ cxf/dosgi/trunk/discovery/local/pom.xml Tue Jun 11 22:29:27 2013 @@ -92,7 +92,7 @@ org.apache.cxf.dosgi.discovery.local.internal - org.apache.cxf.dosgi.discovery.local + org.apache.cxf.dosgi.discovery.local.util Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java?rev=1491995&r1=1491994&r2=1491995&view=diff ============================================================================== --- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java (original) +++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java Tue Jun 11 22:29:27 2013 @@ -21,30 +21,25 @@ package org.apache.cxf.dosgi.discovery.l import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; -import org.apache.cxf.dosgi.discovery.local.LocalDiscoveryUtils; +import org.apache.cxf.dosgi.discovery.local.util.EndpointUtils; +import org.apache.cxf.dosgi.discovery.local.util.Utils; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleListener; -import org.osgi.framework.Filter; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.EndpointListener; import org.osgi.util.tracker.ServiceTracker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class LocalDiscovery implements BundleListener { - private static final Logger LOG = LoggerFactory.getLogger(LocalDiscovery.class); - // this is effectively a set which allows for multiple service descriptions with the // same interface name but different properties and takes care of itself with respect to concurrency ConcurrentHashMap endpointDescriptions = @@ -126,7 +121,7 @@ public class LocalDiscovery implements B private Collection addListener(ServiceReference reference, EndpointListener listener) { List filters = - LocalDiscoveryUtils.getStringPlusProperty(reference, EndpointListener.ENDPOINT_LISTENER_SCOPE); + Utils.getStringPlusProperty(reference, EndpointListener.ENDPOINT_LISTENER_SCOPE); if (filters.isEmpty()) { return filters; } @@ -179,7 +174,7 @@ public class LocalDiscovery implements B } private void findDeclaredRemoteServices(Bundle bundle) { - List eds = LocalDiscoveryUtils.getAllEndpointDescriptions(bundle); + List eds = EndpointUtils.getAllEndpointDescriptions(bundle); for (EndpointDescription ed : eds) { endpointDescriptions.put(ed, bundle); addedEndpointDescription(ed); @@ -215,7 +210,7 @@ public class LocalDiscovery implements B private void triggerCallbacks(EndpointListener listener, String toMatch, EndpointDescription ed, boolean added) { - if (!filterMatches(toMatch, ed)) { + if (!Utils.matchFilter(bundleContext, toMatch, ed)) { return; } @@ -234,21 +229,4 @@ public class LocalDiscovery implements B } } - private boolean filterMatches(String match, EndpointDescription ed) { - Filter filter = createFilter(match); - return filter != null && filter.match(new Hashtable(ed.getProperties())); - } - - private Filter createFilter(String filterValue) { - if (filterValue == null) { - return null; - } - - try { - return bundleContext.createFilter(filterValue); - } catch (Exception ex) { - LOG.error("Problem creating a Filter from " + filterValue, ex); - } - return null; - } }