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/04/15 17:11:52 UTC
svn commit: r765232 -
/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/
Author: davidb
Date: Wed Apr 15 15:11:52 2009
New Revision: 765232
URL: http://svn.apache.org/viewvc?rev=765232&view=rev
Log:
More classes for the Discovery implementation. Tests to follow separately.
Added:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java (with props)
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java (with props)
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java (with props)
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java (with props)
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java (with props)
Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java?rev=765232&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java Wed Apr 15 15:11:52 2009
@@ -0,0 +1,82 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.AsyncCallback.StatCallback;
+import org.apache.zookeeper.KeeperException.Code;
+import org.apache.zookeeper.data.Stat;
+import org.osgi.service.discovery.DiscoveredServiceTracker;
+
+public class DataMonitor implements StatCallback {
+ private static final Logger LOG = Logger.getLogger(DataMonitor.class.getName());
+
+ DataMonitorListener listener;
+ final String znode;
+ final ZooKeeper zookeeper;
+ private byte [] prevData;
+
+ public DataMonitor(ZooKeeper zk, String intf, DiscoveredServiceTracker dst) {
+ listener = new DataMonitorListenerImpl(zk, intf, dst);
+ zookeeper = zk;
+ znode = Util.getZooKeeperPath(intf);
+
+ zookeeper.exists(znode, true, this, null);
+ }
+
+ public void processResult(int rc, String path, Object ctx, Stat stat) {
+ boolean exists;
+
+ switch (rc) {
+ case Code.Ok:
+ exists = true;
+ break;
+ case Code.NoNode:
+ exists = false;
+ break;
+ case Code.SessionExpired:
+ LOG.info("ZooKeeper reports: SessionExpired on node: " + znode);
+ return;
+ case Code.NoAuth:
+ LOG.info("ZooKeeper reports: NoAuth on node: " + znode);
+ return;
+ default:
+ zookeeper.exists(znode, true, this, null);
+ return;
+ }
+
+ byte [] b = null;
+ if (exists) {
+ try {
+ b = zookeeper.getData(znode, false, null);
+ } catch (Exception ke) {
+ LOG.log(Level.SEVERE, "Error getting ZooKeeper data.", ke);
+ }
+
+ if (!Arrays.equals(prevData, b)) {
+ listener.exists();
+ prevData = b;
+ }
+ }
+ }
+}
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java?rev=765232&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java Wed Apr 15 15:11:52 2009
@@ -0,0 +1,23 @@
+/**
+ * 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;
+
+interface DataMonitorListener {
+ void exists();
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java?rev=765232&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java Wed Apr 15 15:11:52 2009
@@ -0,0 +1,86 @@
+/**
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.dosgi.discovery.local.ServiceEndpointDescriptionImpl;
+import org.apache.zookeeper.ZooKeeper;
+import org.osgi.service.discovery.DiscoveredServiceNotification;
+import org.osgi.service.discovery.DiscoveredServiceTracker;
+
+public class DataMonitorListenerImpl implements DataMonitorListener {
+ private static final Logger LOG = Logger.getLogger(DataMonitorListenerImpl.class.getName());
+
+ final ZooKeeper zookeeper;
+ final String znode;
+ final String interFace;
+ final DiscoveredServiceTracker discoveredServiceTracker;
+
+ public DataMonitorListenerImpl(ZooKeeper zk, String intf, DiscoveredServiceTracker dst) {
+ zookeeper = zk;
+ znode = Util.getZooKeeperPath(intf);
+ interFace = intf;
+ discoveredServiceTracker = dst;
+ }
+
+ public void exists() {
+ try {
+ LOG.info("Zookeeper callback on node: " + znode);
+ List<String> children = zookeeper.getChildren(znode, false);
+
+ for (String child : children) {
+ byte[] data = zookeeper.getData(znode + '/' + child, false, null);
+ Properties p = new Properties();
+ p.load(new ByteArrayInputStream(data));
+
+ Map<String, Object> p2 = new HashMap<String, Object>();
+ for (Map.Entry<Object, Object> entry : p.entrySet()) {
+ /* TODO this is probably not necessary
+ if (Constants.SERVICE_ID.equals(entry.getKey()) ||
+ Constants.SERVICE_PID.equals(entry.getKey()) ||
+ Constants.OBJECTCLASS.equals(entry.getKey())) {
+ continue;
+ } */
+
+ p2.put(entry.getKey().toString(), entry.getValue());
+ }
+
+ ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(Collections.singletonList(interFace), p2);
+ DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
+ Collections.singleton(interFace), DiscoveredServiceNotification.AVAILABLE, sed);
+ discoveredServiceTracker.serviceChanged(dsn);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Problem processing Zookeeper callback", e);
+ }
+ }
+
+ public void closing(int rc) {
+ System.out.println("*** closing " + rc);
+ // TODO do we need this callback?
+ }
+}
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorListenerImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java?rev=765232&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java Wed Apr 15 15:11:52 2009
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import java.util.Collection;
+
+import org.osgi.service.discovery.DiscoveredServiceNotification;
+import org.osgi.service.discovery.ServiceEndpointDescription;
+
+@SuppressWarnings("unchecked")
+class DiscoveredServiceNotificationImpl implements DiscoveredServiceNotification {
+ private final Collection filters;
+ private final Collection interfaces;
+ private final int type;
+ private final ServiceEndpointDescription sed;
+
+ DiscoveredServiceNotificationImpl(Collection filters, Collection interfaces,
+ int type, ServiceEndpointDescription sed) {
+ this.filters = filters;
+ this.interfaces = interfaces;
+ this.type = type;
+ this.sed = sed;
+ }
+
+ public Collection getFilters() {
+ return filters;
+ }
+
+ public Collection getInterfaces() {
+ return interfaces;
+ }
+
+ public ServiceEndpointDescription getServiceEndpointDescription() {
+ return sed;
+ }
+
+ public int getType() {
+ return type;
+ }
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveredServiceNotificationImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java?rev=765232&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java Wed Apr 15 15:11:52 2009
@@ -0,0 +1,67 @@
+/**
+ * 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.zookeeper.ZooKeeper;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.DiscoveredServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class FindInZooKeeperCustomizer implements ServiceTrackerCustomizer {
+ private final BundleContext bundleContext;
+ private final ZooKeeper zookeeper;
+ final Map<String, DataMonitor> watchers = new HashMap<String, DataMonitor>();
+
+ public FindInZooKeeperCustomizer(BundleContext bc, ZooKeeper zk) {
+ bundleContext = bc;
+ zookeeper = zk;
+ }
+
+ public Object addingService(ServiceReference sr) {
+ Object svcObj = bundleContext.getService(sr);
+
+ if (svcObj instanceof DiscoveredServiceTracker) {
+ DiscoveredServiceTracker dst = (DiscoveredServiceTracker) svcObj;
+ Collection<String> interfaces = Util.getMultiValueProperty(
+ sr.getProperty(DiscoveredServiceTracker.PROP_KEY_MATCH_CRITERIA_INTERFACES));
+
+ for (String intf : interfaces) {
+ DataMonitor dm = new DataMonitor(zookeeper, intf, dst);
+ watchers.put(intf, dm);
+ }
+ }
+ return svcObj;
+ }
+
+ public void modifiedService(ServiceReference arg0, Object arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removedService(ServiceReference arg0, Object arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date