Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2012-12-04 14:47:19 +0000
committerWim Jongman2012-12-04 14:47:19 +0000
commit41dec86b52fe10c473010a85f2d2c2bb361380c4 (patch)
tree4d5cb55845725f5334b920882f38f3c0489458c8 /providers/bundles/org.eclipse.ecf.provider.zookeeper
parent7560800f3bdf849ff21057d69d8e5c77b5020295 (diff)
downloadorg.eclipse.ecf-41dec86b52fe10c473010a85f2d2c2bb361380c4.tar.gz
org.eclipse.ecf-41dec86b52fe10c473010a85f2d2c2bb361380c4.tar.xz
org.eclipse.ecf-41dec86b52fe10c473010a85f2d2c2bb361380c4.zip
Fixed server mode problems and logging. See:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=395693
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/DiscoveryActivator.java240
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DefaultDiscoveryConfig.java15
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DiscoverdService.java31
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/IDiscoveryConfig.java2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/ZooDiscoveryContainer.java123
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeReader.java3
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/node/internal/NodeWriter.java9
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/Logger.java37
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/PrettyPrinter.java38
9 files changed, 241 insertions, 257 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/DiscoveryActivator.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/DiscoveryActivator.java
index 637d963a0..d17e89a8f 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/DiscoveryActivator.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/DiscoveryActivator.java
@@ -1,121 +1,119 @@
-/*******************************************************************************
- * Copyright (c)2010 REMAIN B.V. The Netherlands. (http://www.remainsoftware.com).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wim Jongman - initial API and implementation
- * Ahmed Aadel - initial API and implementation
- *******************************************************************************/
-package org.eclipse.ecf.provider.zookeeper;
-
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
-import org.eclipse.ecf.discovery.IDiscoveryLocator;
-import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer;
-import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainerInstantiator;
-import org.eclipse.ecf.provider.zookeeper.core.internal.BundleStoppingListener;
-import org.eclipse.ecf.provider.zookeeper.util.Logger;
-import org.eclipse.ecf.provider.zookeeper.util.PrettyPrinter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class DiscoveryActivator implements BundleActivator {
-
- private static BundleContext context;
- private ServiceRegistration discoveryRegistration;
- private static Set<BundleStoppingListener> stopListeners = new HashSet<BundleStoppingListener>();
- private ServiceTracker confTracker, logServiceTracker;
-
- public void start(final BundleContext ctxt) {
- context = ctxt;
-
- final Properties props = new Properties();
- props.put(IDiscoveryLocator.CONTAINER_NAME,
- ZooDiscoveryContainerInstantiator.NAME);
- props.put(IDiscoveryAdvertiser.CONTAINER_NAME,
- ZooDiscoveryContainerInstantiator.NAME);
- // register ourselves using a service factory
- discoveryRegistration = ctxt.registerService(new String[] {
- IDiscoveryLocator.class.getName(),
- IDiscoveryAdvertiser.class.getName() }, new ServiceFactory() {
- private volatile ZooDiscoveryContainer zdc;
-
- public Object getService(Bundle bundle,
- ServiceRegistration registration) {
- if (zdc == null) {
- zdc = ZooDiscoveryContainer.getSingleton();
- zdc.setDiscoveryProperties(props);
- }
- return zdc;
- }
-
- public void ungetService(Bundle bundle,
- ServiceRegistration registration, Object service) {
- //TODO-slewis we later might want to dispose zoodiscovery when the last!!! consumer ungets the service
- //Though don't forget about the (ECF) Container which might still be in use
- }}, (Dictionary) props);
-
- // setup and open log service tracker
- logServiceTracker = new ServiceTracker(ctxt,
- org.osgi.service.log.LogService.class.getName(), null) {
- public Object addingService(ServiceReference reference) {
- Logger.bindLogService((LogService) context
- .getService(reference));
- return super.addingService(reference);
- }
-
- public void removedService(ServiceReference reference,
- Object service) {
- Logger.unbindLogService((LogService) service);
- super.removedService(reference, service);
- }
- };
- logServiceTracker.open(true);
- }
-
- public void stop(BundleContext c) throws Exception {
- dispose();
- // prompt we'r gone!
- PrettyPrinter.prompt(PrettyPrinter.DEACTIVATED, null);
- }
-
- private void dispose() {
- for (BundleStoppingListener l : stopListeners) {
- l.bundleStopping();
- }
- stopListeners.clear();
- ZooDiscoveryContainer.getSingleton().shutdown();
- if (this.discoveryRegistration != null) {
- this.discoveryRegistration.unregister();
- }
- if (this.confTracker != null) {
- this.confTracker.close();
- }
- // Initiates an orderly shutdown of all our cached threads
- ZooDiscoveryContainer.CACHED_THREAD_POOL.shutdown();
-
- }
-
- public static BundleContext getContext() {
- return context;
- }
-
- public static void registerBundleStoppingListner(BundleStoppingListener l) {
- stopListeners.add(l);
- }
-
-}
-
+/*******************************************************************************
+ * Copyright (c)2010 REMAIN B.V. The Netherlands. (http://www.remainsoftware.com).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wim Jongman - initial API and implementation
+ * Ahmed Aadel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.provider.zookeeper;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
+import org.eclipse.ecf.discovery.IDiscoveryLocator;
+import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer;
+import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainerInstantiator;
+import org.eclipse.ecf.provider.zookeeper.core.internal.BundleStoppingListener;
+import org.eclipse.ecf.provider.zookeeper.util.Logger;
+import org.eclipse.ecf.provider.zookeeper.util.PrettyPrinter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class DiscoveryActivator implements BundleActivator {
+
+ private static BundleContext context;
+ private ServiceRegistration discoveryRegistration;
+ private static Set<BundleStoppingListener> stopListeners = new HashSet<BundleStoppingListener>();
+ private ServiceTracker confTracker, logServiceTracker;
+
+ public void start(final BundleContext ctxt) {
+ context = ctxt;
+
+ final Properties props = new Properties();
+ props.put(IDiscoveryLocator.CONTAINER_NAME, ZooDiscoveryContainerInstantiator.NAME);
+ props.put(IDiscoveryAdvertiser.CONTAINER_NAME, ZooDiscoveryContainerInstantiator.NAME);
+ // register ourselves using a service factory
+ discoveryRegistration = ctxt.registerService(
+ new String[] { IDiscoveryLocator.class.getName(), IDiscoveryAdvertiser.class.getName() }, new ServiceFactory() {
+ private volatile ZooDiscoveryContainer zdc;
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ if (zdc == null) {
+ zdc = ZooDiscoveryContainer.getSingleton();
+ zdc.setDiscoveryProperties(props);
+ }
+ return zdc;
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+
+ }
+ }, (Dictionary) props);
+
+ // setup and open log service tracker
+ logServiceTracker = new ServiceTracker(ctxt, org.osgi.service.log.LogService.class.getName(), null) {
+ public Object addingService(ServiceReference reference) {
+ Logger.bindLogService((LogService) context.getService(reference));
+ return super.addingService(reference);
+ }
+
+ public void removedService(ServiceReference reference, Object service) {
+ Logger.unbindLogService((LogService) service);
+ super.removedService(reference, service);
+ }
+ };
+
+ logServiceTracker.open(true);
+
+ // Autostart by consuming our own service
+ if (ZooDiscoveryContainer.autoStart()) {
+ ctxt.getService(discoveryRegistration.getReference());
+ }
+
+ }
+
+ public void stop(BundleContext c) throws Exception {
+ dispose();
+ Logger.log(LogService.LOG_INFO, PrettyPrinter.prompt(PrettyPrinter.DEACTIVATED, null), null);
+ }
+
+ private void dispose() {
+ for (BundleStoppingListener l : stopListeners) {
+ l.bundleStopping();
+ }
+ stopListeners.clear();
+ ZooDiscoveryContainer.getSingleton().shutdown();
+ if (this.discoveryRegistration != null) {
+ this.discoveryRegistration.unregister();
+ }
+ if (this.confTracker != null) {
+ this.confTracker.close();
+ }
+ // Initiates an orderly shutdown of all our cached threads
+ ZooDiscoveryContainer.CACHED_THREAD_POOL.shutdown();
+
+ }
+
+ public static BundleContext getContext() {
+ return context;
+ }
+
+ public static void registerBundleStoppingListner(BundleStoppingListener l) {
+ stopListeners.add(l);
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DefaultDiscoveryConfig.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DefaultDiscoveryConfig.java
index 81d571d8f..724a885b1 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DefaultDiscoveryConfig.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/DefaultDiscoveryConfig.java
@@ -185,6 +185,7 @@ public class DefaultDiscoveryConfig implements IDiscoveryConfig {
defaultConfigProperties.put("preAllocSize", 1); //$NON-NLS-1$
+ defaultConfigProperties.put(ZOODISCOVERY_CONSOLELOG, System.getProperty(ZOODISCOVERY_PREFIX + ZOODISCOVERY_CONSOLELOG, null));
}
public DefaultDiscoveryConfig() {
@@ -202,4 +203,18 @@ public class DefaultDiscoveryConfig implements IDiscoveryConfig {
return f;
}
+
+ /**
+ *
+ * @return true if consoleLogging was specified.
+ */
+ public static boolean getConsoleLog() {
+ Map<String, Object> props = new DefaultDiscoveryConfig().getConfigProperties();
+ Object f = props.get(ZOODISCOVERY_CONSOLELOG);
+ if (f == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
}
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 77a45ce90..5205e3594 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
@@ -17,6 +17,7 @@ import java.util.UUID;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.Namespace;
+import org.eclipse.ecf.core.util.SystemLogService;
import org.eclipse.ecf.discovery.IServiceProperties;
import org.eclipse.ecf.discovery.ServiceInfo;
import org.eclipse.ecf.discovery.identity.IServiceTypeID;
@@ -26,6 +27,7 @@ import org.eclipse.ecf.provider.zookeeper.core.internal.Localizer;
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.Logger;
import org.eclipse.ecf.provider.zookeeper.util.PrettyPrinter;
public class DiscoverdService extends ServiceInfo implements IService, INode {
@@ -42,27 +44,20 @@ public class DiscoverdService extends ServiceInfo implements IService, INode {
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);
+ 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[]) serviceData
- .remove(INode.NODE_PROPERTY_NAME_SCOPE);
- this.serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(
- ZooDiscoveryContainer.getSingleton().getConnectNamespace(),
+ String[] protocols = (String[]) serviceData.remove(INode.NODE_PROPERTY_NAME_PROTOCOLS);
+ String[] scopes = (String[]) serviceData.remove(INode.NODE_PROPERTY_NAME_SCOPE);
+ this.serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(ZooDiscoveryContainer.getSingleton().getConnectNamespace(),
services, scopes, protocols, na);
- super.serviceID = new ZooDiscoveryServiceID(ZooDiscoveryContainer
- .getSingleton().getConnectNamespace(), this, serviceTypeID,
+ super.serviceID = new ZooDiscoveryServiceID(ZooDiscoveryContainer.getSingleton().getConnectNamespace(), this, serviceTypeID,
this.location);
}
public void dispose() {
- PrettyPrinter.prompt(PrettyPrinter.REMOTE_UNAVAILABLE, this);
- Localizer.getSingleton().localize(
- new Notification(this, Notification.UNAVAILABLE));
+ Logger.log(SystemLogService.LOG_DEBUG, PrettyPrinter.prompt(PrettyPrinter.REMOTE_UNAVAILABLE, this), null);
+ Localizer.getSingleton().localize(new Notification(this, Notification.UNAVAILABLE));
}
public String getNodeId() {
@@ -86,10 +81,8 @@ 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());
+ Assert.isTrue(o != null && o instanceof DiscoverdService, "incompatible types for compare"); //$NON-NLS-1$
+ return this.getServiceID().getName().compareTo(((DiscoverdService) o).getServiceID().getName());
}
public byte[] getPropertiesAsBytes() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/IDiscoveryConfig.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/IDiscoveryConfig.java
index b6b393fa9..e48e00ead 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/IDiscoveryConfig.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/IDiscoveryConfig.java
@@ -38,6 +38,8 @@ public interface IDiscoveryConfig {
String ZOODISCOVERY_FLAVOR_CENTRALIZED = "zoodiscovery.flavor.centralized"; //$NON-NLS-1$
String ZOODISCOVERY_FLAVOR_REPLICATED = "zoodiscovery.flavor.replicated"; //$NON-NLS-1$
+ String ZOODISCOVERY_CONSOLELOG = "consoleLog"; //$NON-NLS-1$
+
/** The number of milliseconds of each tick. OPTIONAL **/
String ZOOKEEPER_TICKTIME = "tickTime"; //$NON-NLS-1$
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 b65c3cf2a..29716543a 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
@@ -55,13 +55,12 @@ import org.osgi.service.log.LogService;
public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
private static ZooDiscoveryContainer discovery;
- public static ExecutorService CACHED_THREAD_POOL = Executors
- .newCachedThreadPool();
+ public static ExecutorService CACHED_THREAD_POOL = Executors.newCachedThreadPool();
private QuorumPeer quorumPeer;
private Properties DiscoveryProperties;
protected Advertiser advertiser;
protected Localizer localizer;
- private ZooKeeperServer zooKeeperServer;
+ private static ZooKeeperServer zooKeeperServer;
private ID targetId;
protected boolean isQuorumPeerReady;
private ZooDiscoveryNamespace namespace;
@@ -86,22 +85,32 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
}
private ZooDiscoveryContainer() {
+
super(ZooDiscoveryNamespace.NAME, Configurator.INSTANCE);
+
+ CACHED_THREAD_POOL=Executors.newCachedThreadPool();
DiscoveryProperties = new Properties();
this.namespace = new ZooDiscoveryNamespace();
- if (System.getProperty(DefaultDiscoveryConfig.ZOODISCOVERY_PREFIX
- + DefaultDiscoveryConfig.ZOOKEEPER_AUTOSTART) != null) {
+
+ if (autoStart()) {
try {
- this.targetId = this.getConnectNamespace().createInstance(
- new String[] { DefaultDiscoveryConfig
- .getDefaultTarget() });
+ this.targetId = this.getConnectNamespace().createInstance(new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
init(targetId);
} catch (Exception e) {
Logger.log(LogService.LOG_ERROR, e.getMessage(), e);
}
}
- PrettyPrinter.prompt(PrettyPrinter.ACTIVATED, null);
+
+ Logger.log(LogService.LOG_INFO, PrettyPrinter.prompt(PrettyPrinter.ACTIVATED, null), null);
+
+ }
+
+ /**
+ * @return true if the service is in autoStart mode.
+ */
+ public static boolean autoStart() {
+ return System.getProperty(DefaultDiscoveryConfig.ZOODISCOVERY_PREFIX + DefaultDiscoveryConfig.ZOOKEEPER_AUTOSTART) != null;
}
public synchronized static ZooDiscoveryContainer getSingleton() {
@@ -113,14 +122,12 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
}
public void init(ServiceReference reference) {
- Configuration conf = Configurator.INSTANCE.createConfig(reference)
- .configure();
+ Configuration conf = Configurator.INSTANCE.createConfig(reference).configure();
doStart(conf);
}
private void init(ID targetID) {
- Configuration conf = Configurator.INSTANCE.createConfig(targetID)
- .configure();
+ Configuration conf = Configurator.INSTANCE.createConfig(targetID).configure();
doStart(conf);
}
@@ -177,33 +184,24 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
if (this.zooKeeperServer != null && this.zooKeeperServer.isRunning())
return;
- else if (this.zooKeeperServer != null
- && !this.zooKeeperServer.isRunning())
+ else if (this.zooKeeperServer != null && !this.zooKeeperServer.isRunning())
try {
this.zooKeeperServer.startup();
return;
} catch (Exception e) {
- Logger.log(LogService.LOG_DEBUG,
- "Zookeeper server cannot be started! ", e);//$NON-NLS-1$
+ Logger.log(LogService.LOG_DEBUG, "Zookeeper server cannot be started! ", e);//$NON-NLS-1$
}
try {
ZooDiscoveryContainer.this.zooKeeperServer = new ZooKeeperServer();
- FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(conf
- .getZookeeperDataFile(), conf.getZookeeperDataFile());
- ZooDiscoveryContainer.this.zooKeeperServer
- .setTxnLogFactory(fileTxnSnapLog);
- ZooDiscoveryContainer.this.zooKeeperServer.setTickTime(conf
- .getTickTime());
- Factory cnxnFactory = new NIOServerCnxn.Factory(
- new InetSocketAddress(conf.getClientPort()));
+ FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(conf.getZookeeperDataFile(), conf.getZookeeperDataFile());
+ ZooDiscoveryContainer.this.zooKeeperServer.setTxnLogFactory(fileTxnSnapLog);
+ ZooDiscoveryContainer.this.zooKeeperServer.setTickTime(conf.getTickTime());
+ Factory cnxnFactory = new NIOServerCnxn.Factory(new InetSocketAddress(conf.getClientPort()));
cnxnFactory.startup(ZooDiscoveryContainer.this.zooKeeperServer);
} catch (Exception e) {
- Logger
- .log(
- LogService.LOG_ERROR,
- "Zookeeper server cannot be started! Possibly another instance is already running on the same port. ",
- e);
+ Logger.log(LogService.LOG_ERROR,
+ "Zookeeper server cannot be started! Possibly another instance is already running on the same port. ", e);
}
}
@@ -226,27 +224,19 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
final QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
quorumPeerConfig.parse(conf.getConfFile());
QuorumPeer.Factory qpFactory = new QuorumPeer.Factory() {
- public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory)
- throws IOException {
+ public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory) throws IOException {
ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(quorumPeerConfig);
- QuorumPeer peer = new QuorumPeer(quorumPeerConfig
- .getServers(), new File(serverConfig.getDataDir()),
- new File(serverConfig.getDataLogDir()),
- quorumPeerConfig.getElectionAlg(), quorumPeerConfig
- .getServerId(), quorumPeerConfig
- .getTickTime(), quorumPeerConfig
- .getInitLimit(), quorumPeerConfig
- .getSyncLimit(), cnxnFactory,
+ QuorumPeer peer = new QuorumPeer(quorumPeerConfig.getServers(), new File(serverConfig.getDataDir()), new File(
+ serverConfig.getDataLogDir()), quorumPeerConfig.getElectionAlg(), quorumPeerConfig.getServerId(),
+ quorumPeerConfig.getTickTime(), quorumPeerConfig.getInitLimit(), quorumPeerConfig.getSyncLimit(), cnxnFactory,
quorumPeerConfig.getQuorumVerifier());
ZooDiscoveryContainer.this.quorumPeer = peer;
return peer;
}
- public NIOServerCnxn.Factory createConnectionFactory()
- throws IOException {
- return new NIOServerCnxn.Factory(quorumPeerConfig
- .getClientPortAddress());
+ public NIOServerCnxn.Factory createConnectionFactory() throws IOException {
+ return new NIOServerCnxn.Factory(quorumPeerConfig.getClientPortAddress());
}
};
quorumPeer = qpFactory.create(qpFactory.createConnectionFactory());
@@ -254,8 +244,7 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
quorumPeer.setDaemon(true);
isQuorumPeerReady = true;
} catch (Exception e) {
- Logger.log(LogService.LOG_ERROR,
- "Zookeeper quorum cannot be started! ", e); //$NON-NLS-1$
+ Logger.log(LogService.LOG_ERROR, "Zookeeper quorum cannot be started! ", e); //$NON-NLS-1$
isQuorumPeerReady = false;
}
}
@@ -282,15 +271,13 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
}
if (this.zooKeeperServer != null) {
// purge snaps and logs. Keep only last three of each
- PurgeTxnLog.purge(this.zooKeeperServer.getTxnLogFactory()
- .getDataDir(), this.zooKeeperServer.getTxnLogFactory()
+ PurgeTxnLog.purge(this.zooKeeperServer.getTxnLogFactory().getDataDir(), this.zooKeeperServer.getTxnLogFactory()
.getSnapDir(), 3);
this.zooKeeperServer.shutdown();
}
if (this.quorumPeer != null) {
// purge snaps and logs. Keep only last three of each
- PurgeTxnLog.purge(this.quorumPeer.getTxnFactory().getDataDir(),
- this.quorumPeer.getTxnFactory().getSnapDir(), 3);
+ PurgeTxnLog.purge(this.quorumPeer.getTxnFactory().getDataDir(), this.quorumPeer.getTxnFactory().getSnapDir(), 3);
// shut down server
if (this.quorumPeer.isAlive()) {
this.quorumPeer.shutdown();
@@ -306,22 +293,21 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
targetId = null;
isConnected = false;
isDisposed = true;
+ discovery = null;
}
public ZooKeeperServer getLocalServer() {
return this.zooKeeperServer;
}
- public void connect(ID id, IConnectContext connectContext)
- throws ContainerConnectException {
+ public void connect(ID id, IConnectContext connectContext) throws ContainerConnectException {
if (isDisposed)
throw new ContainerConnectException("Container already disposed!");
if (this.isConnected)
throw new ContainerConnectException("Container already connected!");
this.targetId = id;
if (this.targetId == null) {
- this.targetId = this.getConnectNamespace().createInstance(
- new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
+ this.targetId = this.getConnectNamespace().createInstance(new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
}
init(this.targetId);
isConnected = true;
@@ -364,8 +350,7 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
if (watchManager == null) {
return new IServiceInfo[0];
}
- return watchManager.getAllKnownServices().values().toArray(
- new IServiceInfo[watchManager.getAllKnownServices().size()]);
+ return watchManager.getAllKnownServices().values().toArray(new IServiceInfo[watchManager.getAllKnownServices().size()]);
}
public IServiceInfo[] getServices(IServiceTypeID type) {
@@ -375,8 +360,7 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
}
List<IServiceInfo> services = new ArrayList<IServiceInfo>();
for (IServiceInfo sinfo : watchManager.getAllKnownServices().values()) {
- if (sinfo.getServiceID().getServiceTypeID().getInternal() == type
- .getInternal())
+ if (sinfo.getServiceID().getServiceTypeID().getInternal() == type.getInternal())
services.add(sinfo);
}
return services.toArray(new IServiceInfo[services.size()]);
@@ -389,8 +373,7 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
public synchronized void registerService(IServiceInfo serviceInfo) {
Assert.isNotNull(serviceInfo);
if (targetId == null) {
- this.targetId = this.getConnectNamespace().createInstance(
- new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
+ this.targetId = this.getConnectNamespace().createInstance(new String[] { DefaultDiscoveryConfig.getDefaultTarget() });
init(this.targetId);
}
@@ -399,8 +382,7 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
} else {
watchManager.publish(new AdvertisedService(serviceInfo));
}
- Localizer.getSingleton().localize(
- new Notification(serviceInfo, Notification.AVAILABLE));
+ Localizer.getSingleton().localize(new Notification(serviceInfo, Notification.AVAILABLE));
}
@@ -410,19 +392,16 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
public void unregisterService(IServiceInfo serviceInfo) {
Assert.isNotNull(serviceInfo);
- watchManager.unpublish(serviceInfo.getServiceID().getServiceTypeID()
- .getInternal());
+ watchManager.unpublish(serviceInfo.getServiceID().getServiceTypeID().getInternal());
- Localizer.getSingleton().localize(
- new Notification(serviceInfo, Notification.UNAVAILABLE));
+ Localizer.getSingleton().localize(new Notification(serviceInfo, Notification.UNAVAILABLE));
}
public Collection<IServiceListener> getAllServiceListeners() {
return super.allServiceListeners;
}
- public Collection<IServiceListener> getServiceListenersForType(
- IServiceTypeID type) {
+ public Collection<IServiceListener> getServiceListenersForType(IServiceTypeID type) {
return super.getListeners(type);
}
@@ -443,8 +422,12 @@ public class ZooDiscoveryContainer extends AbstractDiscoveryContainerAdapter {
return this.isDisposed;
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter#getContainerName()
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ecf.discovery.AbstractDiscoveryContainerAdapter#getContainerName
+ * ()
*/
public String getContainerName() {
return ZooDiscoveryContainerInstantiator.NAME;
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 33dc97056..4eea86d58 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
@@ -88,8 +88,7 @@ public class NodeReader implements Watcher,
readRoot.getDiscoverdServices()
.put(this.discovered.getServiceID().getServiceTypeID()
.getName(), this.discovered);
- PrettyPrinter.prompt(PrettyPrinter.REMOTE_AVAILABLE,
- this.discovered);
+ Logger.log(LogService.LOG_DEBUG, PrettyPrinter.prompt(PrettyPrinter.REMOTE_AVAILABLE, this.discovered), null);
Localizer.getSingleton().localize(
new Notification(this.discovered, Notification.AVAILABLE));
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 75d63f67a..c2c8b05ce 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
@@ -61,8 +61,7 @@ public class NodeWriter {
.getPropertiesAsBytes(),
Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
}
- PrettyPrinter.prompt(PrettyPrinter.PUBLISHED, this.getNode()
- .getWrappedService());
+ Logger.log(LogService.LOG_INFO, PrettyPrinter.prompt(PrettyPrinter.PUBLISHED, this.getNode().getWrappedService()), null);
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.CONNECTIONLOSS) {
Logger.log(LogService.LOG_ERROR, "Can't connect to server! "
@@ -88,8 +87,7 @@ public class NodeWriter {
Localizer.getSingleton().localize(
new Notification(this.getNode().getWrappedService(),
Notification.UNAVAILABLE));
- PrettyPrinter.prompt(PrettyPrinter.UNPUBLISHED, this.getNode()
- .getWrappedService());
+ Logger.log(LogService.LOG_INFO, PrettyPrinter.prompt(PrettyPrinter.UNPUBLISHED, this.getNode().getWrappedService()), null);
} catch (KeeperException e) {
// ignore
@@ -102,8 +100,7 @@ public class NodeWriter {
* connection lost to the central ZooDiscovery where our services
* are published to.
*/
- PrettyPrinter.prompt(PrettyPrinter.UNPUBLISHED, this.getNode()
- .getWrappedService());
+ Logger.log(LogService.LOG_INFO, PrettyPrinter.prompt(PrettyPrinter.UNPUBLISHED, this.getNode().getWrappedService()), null);
}
}
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 e447fc3dd..66ffaee22 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
@@ -16,13 +16,13 @@ import java.util.Set;
import org.eclipse.ecf.core.util.SystemLogService;
import org.eclipse.ecf.provider.zookeeper.DiscoveryActivator;
+import org.eclipse.ecf.provider.zookeeper.core.DefaultDiscoveryConfig;
import org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer;
import org.osgi.service.log.LogService;
public class Logger {
- private static SystemLogService nativeLogger = new SystemLogService(
- "org.eclipse.ecf.provider.zookeeper");
+ private static SystemLogService nativeLogger = new SystemLogService("org.eclipse.ecf.provider.zookeeper");
private static Set<LogService> logServices = new HashSet<LogService>();
@@ -35,36 +35,35 @@ public class Logger {
}
public static void log(int level, String message, Exception e) {
- if (logServices.isEmpty()) {
- if (e == null)
- nativeLogger.log(level, message);
- else
- nativeLogger.log(level, message, e);
+ nativeLog(level, message, e);
- return;
- }
for (LogService ls : logServices) {
if (ls == null) {
- nativeLogger.log(level, message, e);
+ nativeLog(level, message, e);
continue;
}
- ls.log(DiscoveryActivator.getContext().getServiceReference(
- ZooDiscoveryContainer.class.getName()), level, message, e);
+ ls.log(DiscoveryActivator.getContext().getServiceReference(ZooDiscoveryContainer.class.getName()), level, message, e);
}
}
- public static void log(int level, String message, Throwable t) {
- if (logServices.isEmpty()) {
- nativeLogger.log(level, message, t);
- return;
+ private static void nativeLog(int level, String message, Throwable e) {
+
+ if (DefaultDiscoveryConfig.getConsoleLog()) {
+ if (e == null) {
+ nativeLogger.log(level, message);
+ } else {
+ nativeLogger.log(level, message, e);
+ }
}
+ }
+
+ public static void log(int level, String message, Throwable t) {
+ nativeLog(level, message, t);
for (LogService ls : logServices) {
if (ls == null) {
- nativeLogger.log(level, message, t);
continue;
}
- ls.log(DiscoveryActivator.getContext().getServiceReference(
- ZooDiscoveryContainer.class.getName()), level, message, t);
+ ls.log(DiscoveryActivator.getContext().getServiceReference(ZooDiscoveryContainer.class.getName()), level, message, t);
}
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/PrettyPrinter.java b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/PrettyPrinter.java
index 8285605b1..7e8bd23c7 100644
--- a/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/PrettyPrinter.java
+++ b/providers/bundles/org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/util/PrettyPrinter.java
@@ -17,7 +17,8 @@ import java.util.Calendar;
import org.eclipse.ecf.discovery.IServiceInfo;
public class PrettyPrinter {
- private static final String prompt = "ZooDiscovery> ";//$NON-NLS-1$
+// private static final String prompt = "ZooDiscovery> ";//$NON-NLS-1$
+ private static final String prompt = "";//$NON-NLS-1$
public static final int PUBLISHED = 1;
public static final int UNPUBLISHED = 2;
@@ -28,48 +29,45 @@ public class PrettyPrinter {
public static final int PUBLISH_DELAYED = 7;
public static final int UNPUBLISH_DELAYED = 8;
- public static void prompt(int type, IServiceInfo serviceInfo) {
+ public static String prompt(int type, IServiceInfo serviceInfo) {
String token = ""; //$NON-NLS-1$
- String time = DateFormat.getDateTimeInstance().format(
- Calendar.getInstance().getTime())
- + ". ";//$NON-NLS-1$
+// String time = DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()) + ". ";//$NON-NLS-1$
+ String time = "";
switch (type) {
case PUBLISHED:
- token = "Service Published: ";//$NON-NLS-1$
+ token = "Service Published: ";
break;
case UNPUBLISHED:
- token = "Service Unpublished: ";//$NON-NLS-1$
+ token = "Service Unpublished: ";
break;
case ACTIVATED:
- token = "Discovery Service Activated. ";//$NON-NLS-1$
+ token = "Discovery Service Activated. ";
break;
case DEACTIVATED:
- token = "Discovery Service Deactivated.";//$NON-NLS-1$
+ token = "Discovery Service Deactivated.";
break;
case PUBLISH_DELAYED:
- token = "Service Publication Delayed: ";//$NON-NLS-1$
+ token = "Service Publication Delayed: ";
break;
case UNPUBLISH_DELAYED:
- token = "Service Unpublication Delayed: ";//$NON-NLS-1$
+ token = "Service Unpublication Delayed: ";
break;
case REMOTE_AVAILABLE:
- token = "Service Discovered: ";//$NON-NLS-1$
+ token = "Service Discovered: ";
break;
case REMOTE_UNAVAILABLE:
- token = "Service Undiscovered: ";//$NON-NLS-1$
+ token = "Service Undiscovered: ";
break;
}
- System.out.println(prompt + token + time
- + ((serviceInfo != null) ? serviceInfo : ""));//$NON-NLS-1$
+ return (prompt + token + time + ((serviceInfo != null) ? serviceInfo : ""));//$NON-NLS-1$
}
- public static void attemptingConnectionTo(String ip) {
- System.out.println(prompt
- + "INFO - Attempting connection to server: /" + ip);//$NON-NLS-1$
+ public static String attemptingConnectionTo(String ip) {
+ return (prompt + "INFO - Attempting connection to server: /" + ip);
}
- public static void connectionLost(String ip) {
- System.out.println(prompt + "INFO - Connection Lost: /" + ip);//$NON-NLS-1$
+ public static String connectionLost(String ip) {
+ return (prompt + "INFO - Connection Lost: /" + ip);
}
}

Back to the top