Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2011-02-16 16:33:20 +0000
committerWim Jongman2011-02-16 16:33:20 +0000
commit12ab7df3f8e021bdaba52f908a5ed8a5b38ab569 (patch)
treecbf5c45ff76073c24f746c30f0ca75d80d5df557 /providers/bundles/org.eclipse.ecf.provider.zookeeper
parent375f29370ac1591a3af7c2cc5b5e1c84f831eada (diff)
downloadorg.eclipse.ecf-12ab7df3f8e021bdaba52f908a5ed8a5b38ab569.tar.gz
org.eclipse.ecf-12ab7df3f8e021bdaba52f908a5ed8a5b38ab569.tar.xz
org.eclipse.ecf-12ab7df3f8e021bdaba52f908a5ed8a5b38ab569.zip
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335419
Service info properties are passed untouched. Logging bug solved General cosmetics
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.zookeeper')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/AdvertisedService.java137
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java68
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java1
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/IService.java7
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/INode.java3
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java65
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java8
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/WriteRoot.java94
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java4
9 files changed, 163 insertions, 224 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/AdvertisedService.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/AdvertisedService.java
index 0ad4a9007..ea001560a 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/AdvertisedService.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/AdvertisedService.java
@@ -11,12 +11,13 @@
*******************************************************************************/
package org.eclipse.ecf.provider.zookeeper.core;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.net.URI;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import java.util.UUID;
import org.eclipse.core.runtime.Assert;
@@ -30,8 +31,10 @@ import org.eclipse.ecf.provider.zookeeper.core.internal.Configurator;
import org.eclipse.ecf.provider.zookeeper.core.internal.IService;
import org.eclipse.ecf.provider.zookeeper.node.internal.INode;
import org.eclipse.ecf.provider.zookeeper.util.Geo;
+import org.eclipse.ecf.provider.zookeeper.util.Logger;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
/**
* Encapsulate a service to be advertised and made visible for discovery. An
@@ -44,24 +47,21 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
private static final long serialVersionUID = 1001026250299416572L;
private String uuid;
- private Properties internalProperties = new Properties();
+ private Map<String, Object> nodeProperties = new HashMap<String, Object>();
private static Map<String, IServiceInfo> publishedServices = new HashMap<String, IServiceInfo>();
private ServiceReference serviceReference;
public AdvertisedService(ServiceReference ref) {
-
Assert.isNotNull(ref);
-
this.serviceReference = ref;
this.uuid = UUID.randomUUID().toString();
-
+ super.properties = new ServiceProperties();
String services[] = (String[]) this.serviceReference
.getProperty(Constants.OBJECTCLASS);
for (String propertyKey : this.serviceReference.getPropertyKeys()) {
- this.internalProperties.put(propertyKey,
+ super.properties.setProperty(propertyKey,
this.serviceReference.getProperty(propertyKey));
}
-
IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault()
.createServiceTypeID(
ZooDiscoveryContainer.getSingleton()
@@ -75,22 +75,7 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
serviceID = new ZooDiscoveryServiceID(ZooDiscoveryContainer
.getSingleton().getConnectNamespace(), serviceTypeID,
Geo.getLocation());
-
- super.properties = new ServiceProperties(this.internalProperties);
-
- // internal properties
- this.internalProperties.put(Constants.OBJECTCLASS,
- arrayToString(services));
- this.internalProperties.put(LOCATION, Geo.getLocation());
- this.internalProperties.put(WEIGHT, getWeight());
- this.internalProperties.put(PRIORITY, getPriority());
- this.internalProperties.put(NODE_PROPERTY_NAME_PROTOCOLS,
- arrayToString(IServiceTypeID.DEFAULT_PROTO));
- this.internalProperties.put(NODE_PROPERTY_NAME_SCOPE,
- arrayToString(IServiceTypeID.DEFAULT_SCOPE));
- this.internalProperties.put(NODE_PROPERTY_NAME_NA,
- IServiceTypeID.DEFAULT_NA);
- publishedServices.put(serviceTypeID.getInternal(), this);
+ setNodeProperties();
}
public AdvertisedService(IServiceInfo serviceInfo) {
@@ -99,45 +84,25 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
.getPriority(), serviceInfo.getWeight(), serviceInfo
.getServiceProperties());
this.uuid = UUID.randomUUID().toString();
- // internal properties
-
- Enumeration enumm = serviceInfo.getServiceProperties()
- .getPropertyNames();
- while (enumm.hasMoreElements()) {
- String k = (String) enumm.nextElement();
- Object value = serviceInfo.getServiceProperties().getProperty(k);
- byte[] bytes = serviceInfo.getServiceProperties().getPropertyBytes(
- k);
- if (value instanceof String
- && ((String) value).contains("localhost")) {//$NON-NLS-1$
- this.internalProperties.put(k,
- ((String) value).replace("localhost",//$NON-NLS-1$
- Geo.getHost()));
- continue;
- }
- if (bytes != null) {
- this.internalProperties.put(INode._BYTES_ + k,
- new String(bytes));
- } else {
- this.internalProperties.put(k, value);
- }
-
- }
-
- this.internalProperties
- .put(NODE_PROPERTY_NAME_PROTOCOLS, arrayToString(getServiceID()
- .getServiceTypeID().getProtocols()));
- this.internalProperties.put(NODE_PROPERTY_NAME_SCOPE,
- arrayToString(getServiceID().getServiceTypeID().getScopes()));
- this.internalProperties.put(NODE_PROPERTY_SERVICES,
- arrayToString(getServiceID().getServiceTypeID().getServices()));
- this.internalProperties.put(NODE_PROPERTY_NAME_NA, getServiceID()
+ setNodeProperties();
+ }
+
+ private void setNodeProperties() {
+ this.nodeProperties.put(NODE_PROPERTY_SERVICE_NAME, getServiceName());
+ this.nodeProperties.put(NODE_SERVICE_PROPERTIES, super.properties);
+ this.nodeProperties.put(NODE_PROPERTY_NAME_PROTOCOLS, getServiceID()
+ .getServiceTypeID().getProtocols());
+ this.nodeProperties.put(NODE_PROPERTY_NAME_SCOPE, getServiceID()
+ .getServiceTypeID().getScopes());
+ this.nodeProperties.put(NODE_PROPERTY_SERVICES, getServiceID()
+ .getServiceTypeID().getServices());
+ this.nodeProperties.put(NODE_PROPERTY_NAME_NA, getServiceID()
.getServiceTypeID().getNamingAuthority());
- this.internalProperties.put(LOCATION, serviceInfo.getLocation());
- this.internalProperties.put(WEIGHT, getWeight());
- this.internalProperties.put(PRIORITY, getPriority());
- publishedServices.put(serviceInfo.getServiceID().getServiceTypeID()
- .getInternal(), this);
+ this.nodeProperties.put(LOCATION, getLocation());
+ this.nodeProperties.put(WEIGHT, getWeight());
+ this.nodeProperties.put(PRIORITY, getPriority());
+ publishedServices.put(getServiceID().getServiceTypeID().getInternal(),
+ this);
}
public static Map<String, IServiceInfo> getPublishedServices() {
@@ -148,10 +113,6 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
return publishedServices.remove(id);
}
- public Properties getProperties() {
- return this.internalProperties;
- }
-
public String getNodeId() {
return this.uuid;
}
@@ -186,15 +147,34 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
}
public byte[] getPropertiesAsBytes() {
- return getPropertiesAsString().getBytes();
- }
-
- public String getPropertiesAsString() {
- String props = "";
- for (Object k : this.getProperties().keySet()) {
- props += k + "=" + this.getProperties().get(k) + "\n";//$NON-NLS-1$//$NON-NLS-2$
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = null;
+ byte[] bytes = null;
+ try {
+ oout = new ObjectOutputStream(baout);
+ oout.writeObject(nodeProperties);
+ oout.flush();
+ bytes = baout.toByteArray();
+ } catch (IOException e) {
+ Logger.log(LogService.LOG_ERROR,
+ "Error while serializing node data ", e);//$NON-NLS-1$
+ } finally {
+ if (oout != null) {
+ try {
+ oout.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ if (baout != null) {
+ try {
+ baout.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
- return props;
+ return bytes;
}
public String getPath() {
@@ -214,13 +194,4 @@ public class AdvertisedService extends ServiceInfo implements INode, IService {
public IService getWrappedService() {
return this;
}
-
- private String arrayToString(String[] arr) {
- String s = "";//$NON-NLS-1$
- for (String c : arr) {
- s += c + " ";//$NON-NLS-1$
- }
- return s;
- }
-
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java
index 8e33526d3..77a45ce90 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java
@@ -12,13 +12,13 @@
package org.eclipse.ecf.provider.zookeeper.core;
import java.net.URI;
-import java.util.Properties;
+import java.util.Map;
import java.util.UUID;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.discovery.IServiceProperties;
import org.eclipse.ecf.discovery.ServiceInfo;
-import org.eclipse.ecf.discovery.ServiceProperties;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
import org.eclipse.ecf.provider.zookeeper.core.internal.IService;
@@ -27,7 +27,6 @@ import org.eclipse.ecf.provider.zookeeper.core.internal.Notification;
import org.eclipse.ecf.provider.zookeeper.node.internal.INode;
import org.eclipse.ecf.provider.zookeeper.util.Geo;
import org.eclipse.ecf.provider.zookeeper.util.PrettyPrinter;
-import org.osgi.framework.Constants;
public class DiscoverdService extends ServiceInfo implements IService, INode {
@@ -35,52 +34,29 @@ public class DiscoverdService extends ServiceInfo implements IService, INode {
private String uuid;
private URI location;
private IServiceTypeID serviceTypeID;
- private Properties props;
- public DiscoverdService(String path, Properties propMap) {
- Assert.isNotNull(propMap);
+ public DiscoverdService(String path, Map<String, Object> serviceData) {
+ Assert.isNotNull(serviceData);
this.uuid = path.split(INode._URI_)[0];
- this.location = URI.create((String) propMap.remove(IService.LOCATION));
- super.priority = Integer.parseInt((String) propMap
- .remove(IService.PRIORITY));
- super.weight = Integer.parseInt((String) propMap
- .remove(IService.WEIGHT));
- String[] services = (String[]) propMap.remove(Constants.OBJECTCLASS);
- if (services == null) {
- services = (String[]) propMap.remove(INode.NODE_PROPERTY_SERVICES);
- }
- String na = (String) propMap.remove(INode.NODE_PROPERTY_NAME_NA);
- String[] protocols = (String[]) propMap
+ this.location = (URI) serviceData.remove(IService.LOCATION);
+ super.priority = (Integer) serviceData.remove(IService.PRIORITY);
+ super.weight = (Integer) serviceData.remove(IService.WEIGHT);
+ super.serviceName = (String) serviceData.get(IService.SERVICE_NAME);
+ super.properties = (IServiceProperties) serviceData
+ .remove(INode.NODE_SERVICE_PROPERTIES);
+ String[] services = (String[]) serviceData
+ .remove(INode.NODE_PROPERTY_SERVICES);
+ String na = (String) serviceData.remove(INode.NODE_PROPERTY_NAME_NA);
+ String[] protocols = (String[]) serviceData
.remove(INode.NODE_PROPERTY_NAME_PROTOCOLS);
- String[] scopes = (String[]) propMap
+ String[] scopes = (String[]) serviceData
.remove(INode.NODE_PROPERTY_NAME_SCOPE);
- super.properties = createServiceProperties(propMap);
this.serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(
ZooDiscoveryContainer.getSingleton().getConnectNamespace(),
services, scopes, protocols, na);
super.serviceID = new ZooDiscoveryServiceID(ZooDiscoveryContainer
.getSingleton().getConnectNamespace(), this, serviceTypeID,
this.location);
- super.serviceName = propMap.getProperty("component.name", location.toASCIIString());
- }
-
- private ServiceProperties createServiceProperties(Properties props) {
- ServiceProperties result = new ServiceProperties();
- for (Object k : props.keySet()) {
- Object value = (String) props.get(k);
- if (((String) k).startsWith(INode._BYTES_)) {
- result.setPropertyBytes(((String) k).split(INode._BYTES_)[1],
- (value + "").getBytes());
- continue;
- }
- result.setProperty((String) k, value);
- }
- this.props = result.asProperties();
- return result;
- }
-
- public Properties getProperties() {
- return this.props;
}
public void dispose() {
@@ -112,20 +88,12 @@ public class DiscoverdService extends ServiceInfo implements IService, INode {
public int compareTo(Object o) {
Assert.isTrue(o != null && o instanceof DiscoverdService,
"incompatible types for compare"); //$NON-NLS-1$
- return this.getServiceID().getName().compareTo(
- ((DiscoverdService) o).getServiceID().getName());
+ return this.getServiceID().getName()
+ .compareTo(((DiscoverdService) o).getServiceID().getName());
}
public byte[] getPropertiesAsBytes() {
- return getPropertiesAsString().getBytes();
- }
-
- public String getPropertiesAsString() {
- String props = "";
- for (Object k : this.getProperties().keySet()) {
- props += k + "=" + this.getProperties().get(k) + "\n";//$NON-NLS-1$//$NON-NLS-2$
- }
- return props;
+ throw new UnsupportedOperationException();
}
public String getPath() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java
index 7c07073b8..b65c3cf2a 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java
@@ -195,7 +195,6 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
.setTxnLogFactory(fileTxnSnapLog);
ZooDiscoveryContainer.this.zooKeeperServer.setTickTime(conf
.getTickTime());
-
Factory cnxnFactory = new NIOServerCnxn.Factory(
new InetSocketAddress(conf.getClientPort()));
cnxnFactory.startup(ZooDiscoveryContainer.this.zooKeeperServer);
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/IService.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/IService.java
index 4ba774066..692ea14ed 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/IService.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/IService.java
@@ -11,8 +11,6 @@
*******************************************************************************/
package org.eclipse.ecf.provider.zookeeper.core.internal;
-import java.util.Properties;
-
import org.eclipse.ecf.discovery.IServiceInfo;
public interface IService extends IServiceInfo {
@@ -21,8 +19,9 @@ public interface IService extends IServiceInfo {
String WEIGHT = "discovery.service.weight"; //$NON-NLS-1$
String PRIORITY = "discovery.service.priority"; //$NON-NLS-1$
String PROTOCOLS = "discovery.service.protocol"; //$NON-NLS-1$
+ Object SERVICE_NAME = "discovery.service.name";;
- Properties getProperties();
+ // Properties getProperties();
/**
* Stored as value of a zookeeper node
@@ -31,5 +30,5 @@ public interface IService extends IServiceInfo {
*/
byte[] getPropertiesAsBytes();
- String getPropertiesAsString();
+ // String getPropertiesAsString();
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/INode.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/INode.java
index 8bdc6c495..b9d54a8d5 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/INode.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/INode.java
@@ -26,6 +26,8 @@ public interface INode {
String NODE_PROPERTY_NAME_SCOPE = "node.property.name.scope";//$NON-NLS-1$
String NODE_PROPERTY_NAME_NA = "node.property.name.na";//$NON-NLS-1$
String NODE_PROPERTY_SERVICES = "node.property.name.services";//$NON-NLS-1$
+ String NODE_SERVICE_PROPERTIES = "node.property.service.properties";//$NON-NLS-1$;
+ String NODE_PROPERTY_SERVICE_NAME = "node.property.service.name";//$NON-NLS-1$;
String STRING_DELIM = " ";//$NON-NLS-1$
// the id of this running ZooDiscovery
String _ZOODISCOVERYID_ = "_zdid_";//$NON-NLS-1$
@@ -41,5 +43,4 @@ public interface INode {
IServiceInfo getWrappedService();
void regenerateNodeId();
-
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java
index 10d94ddb5..33dc97056 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java
@@ -13,13 +13,14 @@ package org.eclipse.ecf.provider.zookeeper.node.internal;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.util.Properties;
+import java.io.ObjectInputStream;
+import java.util.Map;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
+import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.provider.zookeeper.core.DiscoverdService;
@@ -27,7 +28,6 @@ import org.eclipse.ecf.provider.zookeeper.core.internal.Localizer;
import org.eclipse.ecf.provider.zookeeper.core.internal.Notification;
import org.eclipse.ecf.provider.zookeeper.util.Logger;
import org.eclipse.ecf.provider.zookeeper.util.PrettyPrinter;
-import org.osgi.framework.Constants;
import org.osgi.service.log.LogService;
public class NodeReader implements Watcher,
@@ -64,44 +64,30 @@ public class NodeReader implements Watcher,
return INode.ROOT_SLASH + getPath();
}
- public void processResult(int rc, String p, Object ctx, byte[] data,
- Stat stat) {
+ public synchronized void processResult(int rc, String p, Object ctx,
+ byte[] data, Stat stat) {
if (p == null || !p.equals(getAbsolutePath()) || data == null) {
return;
}
- ByteArrayInputStream bis = null;
- Properties props = new Properties();
+ ObjectInputStream objin = null;
+ ByteArrayInputStream bain = null;
+ Map<String, Object> serviceData = null;
try {
- bis = new ByteArrayInputStream(data);
- props.load(bis);
- if (props.isEmpty()) {
- return;
- }
- if (props.containsKey(Constants.OBJECTCLASS)) {
- props.put(Constants.OBJECTCLASS, ((String) props
- .get(Constants.OBJECTCLASS)).split(INode.STRING_DELIM));
- }
- if (props.containsKey(INode.NODE_PROPERTY_NAME_SCOPE)) {
- props.put(INode.NODE_PROPERTY_NAME_SCOPE, ((String) props
- .get(INode.NODE_PROPERTY_NAME_SCOPE))
- .split(INode.STRING_DELIM));
- }
- if (props.containsKey(INode.NODE_PROPERTY_NAME_PROTOCOLS)) {
- props.put(INode.NODE_PROPERTY_NAME_PROTOCOLS, ((String) props
- .get(INode.NODE_PROPERTY_NAME_PROTOCOLS))
- .split(INode.STRING_DELIM));
+ bain = new ByteArrayInputStream(data);
+ objin = new ObjectInputStream(bain);
+ try {
+ serviceData = (Map<String, Object>) objin.readObject();
+ } catch (ClassNotFoundException e) {
+ Logger.log(LogService.LOG_ERROR, "NodeReader.processResult: "
+ + e.getMessage(), e);
}
- if (props.containsKey(INode.NODE_PROPERTY_SERVICES)) {
- props.put(INode.NODE_PROPERTY_SERVICES, ((String) props
- .get(INode.NODE_PROPERTY_SERVICES))
- .split(INode.STRING_DELIM));
+ if (serviceData == null || serviceData.isEmpty()) {
+ return;
}
- bis.close();
- this.discovered = new DiscoverdService(getPath(), props);
+ this.discovered = new DiscoverdService(getPath(), serviceData);
readRoot.getDiscoverdServices()
- .put(
- this.discovered.getServiceID().getServiceTypeID()
- .getName(), this.discovered);
+ .put(this.discovered.getServiceID().getServiceTypeID()
+ .getName(), this.discovered);
PrettyPrinter.prompt(PrettyPrinter.REMOTE_AVAILABLE,
this.discovered);
Localizer.getSingleton().localize(
@@ -110,9 +96,16 @@ public class NodeReader implements Watcher,
} catch (IOException e) {
Logger.log(LogService.LOG_DEBUG, e.getMessage(), e);
} finally {
- if (bis != null) {
+ if (objin != null) {
+ try {
+ objin.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ if (bain != null) {
try {
- bis.close();
+ bain.close();
} catch (IOException e) {
// ignore
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java
index 8d3427486..75d63f67a 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java
@@ -55,8 +55,7 @@ public class NodeWriter {
false);
if (stat == null) {
this.writeRoot.getWriteKeeper()
- .create(
- parentPath,
+ .create(parentPath,
((AdvertisedService) this.getNode()
.getWrappedService())
.getPropertiesAsBytes(),
@@ -66,13 +65,12 @@ public class NodeWriter {
.getWrappedService());
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.CONNECTIONLOSS) {
- Logger.log(LogService.LOG_DEBUG, "Can't connect to server! "
+ Logger.log(LogService.LOG_ERROR, "Can't connect to server! "
+ e.getMessage(), e);
}
} catch (InterruptedException e) {
- Logger.log(LogService.LOG_DEBUG, e.getMessage(), e);
+ // ignore
}
-
}
public synchronized void remove() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/WriteRoot.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/WriteRoot.java
index 0830e45fc..c29cf31b0 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/WriteRoot.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/WriteRoot.java
@@ -16,8 +16,8 @@ import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.provider.zookeeper.util.Logger;
@@ -39,7 +39,7 @@ class WriteRoot implements Watcher {
initWriteKeeper();
}
- @SuppressWarnings( { "incomplete-switch" })
+ @SuppressWarnings({ "incomplete-switch" })
public void process(WatchedEvent event) {
switch (event.getState()) {
case Disconnected:
@@ -81,55 +81,61 @@ class WriteRoot implements Watcher {
}
private void initWriteKeeper() {
+
+ if (watchManager.getConfig().isQuorum()
+ || watchManager.getConfig().isStandAlone()) {
+ // we write nodes locally but we should check for client port.
+ int port = watchManager.getConfig().getClientPort();
+ if (port != 0)
+ ip += ":" + port;//$NON-NLS-1$
+ } else if (watchManager.getConfig().isCentralized()) {
+ // we write nodes to the machine with this specified IP address.
+ ip = watchManager.getConfig().getServerIps();
+ }
try {
- if (watchManager.getConfig().isQuorum()
- || watchManager.getConfig().isStandAlone()) {
- // we write nodes locally but we should check for client port.
- int port = watchManager.getConfig().getClientPort();
- if (port != 0)
- ip += ":" + port;//$NON-NLS-1$
- } else if (watchManager.getConfig().isCentralized()) {
- // we write nodes to the machine with this specified IP address.
- ip = watchManager.getConfig().getServerIps();
- }
this.writeKeeper = new ZooKeeper(this.ip, 3000, this);
- while (!this.isConnected) {
- if (watchManager.isDisposed()) {
- // no need for connecting, we're disposed.
- try {
- this.writeKeeper.close();
- } catch (Throwable t) {
- // ignore
- }
- break;
- }
+ } catch (Exception e) {
+ // FATAL
+ Logger.log(LogService.LOG_ERROR,
+ "Fatal error while initializing a zookeeper client to write to: "
+ + ip, e);
+ // halt here before the NPE's get out of house in
+ // Publisher.publish()
+ throw new IllegalStateException(e);
+ }
+ while (!this.isConnected) {
+ if (watchManager.isDisposed()) {
+ // no need for connecting, we're disposed.
try {
- Stat s = this.writeKeeper.exists(INode.ROOT, this);
- this.isConnected = true;
- if (s == null) {
- this.writeKeeper.create(INode.ROOT, new byte[0],
- Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- }
-
- } catch (KeeperException e) {
- if (e.code().equals(KeeperException.Code.CONNECTIONLOSS)) {
- this.isConnected = false;
- PrettyPrinter.attemptingConnectionTo(this.ip);
- } else
- Logger
- .log(
- LogService.LOG_ERROR,
- "Error while trying to connect to " + this.ip, e); //$NON-NLS-1$
+ this.writeKeeper.close();
+ } catch (Throwable t) {
+ // ignore
}
+ break;
}
- synchronized (this) {
- this.notifyAll();
- }
- this.watchManager.addZooKeeper(this.writeKeeper);
+ try {
+ Stat s = this.writeKeeper.exists(INode.ROOT, this);
+ this.isConnected = true;
+ if (s == null) {
+ this.writeKeeper.create(INode.ROOT, new byte[0],
+ Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ }
- } catch (Exception e) {
- Logger.log(LogService.LOG_DEBUG, e.getMessage(), e);
+ } catch (KeeperException e) {
+ if (e.code().equals(KeeperException.Code.CONNECTIONLOSS)) {
+ this.isConnected = false;
+ PrettyPrinter.attemptingConnectionTo(this.ip);
+ } else
+ Logger.log(LogService.LOG_ERROR,
+ "Error while trying to connect to " + this.ip, e); //$NON-NLS-1$
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+ synchronized (this) {
+ this.notifyAll();
}
+ this.watchManager.addZooKeeper(this.writeKeeper);
}
public ZooKeeper getWriteKeeper() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java
index 1af13a357..a373e25ef 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java
@@ -39,6 +39,10 @@ public class Logger {
return;
}
for (LogService ls : logServices) {
+ if (ls == null) {
+ System.err.println(message + ": " + e);
+ continue;
+ }
ls.log(DiscoveryActivator.getContext().getServiceReference(
ZooDiscoveryContainer.class.getName()), level, message, e);
}

Back to the top