You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/12/11 21:43:40 UTC
svn commit: r1420394 - in /cxf/dosgi/trunk/discovery/distributed:
zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/
zookeeper-server/
zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/se...
Author: dkulp
Date: Tue Dec 11 20:43:37 2012
New Revision: 1420394
URL: http://svn.apache.org/viewvc?rev=1420394&view=rev
Log:
zookeeper server cleanup
Modified:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.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/Activator.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java?rev=1420394&r1=1420393&r2=1420394&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java Tue Dec 11 20:43:37 2012
@@ -1,24 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
+ * 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.config;
import java.io.IOException;
import java.net.ServerSocket;
+import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
@@ -38,7 +40,7 @@ public class Activator implements Bundle
private ServiceTracker st;
public void start(BundleContext context) throws Exception {
- synchronized(Activator.class) {
+ synchronized (Activator.class) {
// Only one thread gets to set the port number
if (System.getProperty(ZOOKEEPER_PORT) == null) {
String port = getFreePort();
@@ -55,7 +57,7 @@ public class Activator implements Bundle
try {
ConfigurationAdmin cadmin = (ConfigurationAdmin) svc;
Configuration cfg = cadmin.getConfiguration(PID, null);
- Hashtable<String, Object> props = new Hashtable<String, Object>();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
String zp = System.getProperty(ZOOKEEPER_PORT);
props.put("clientPort", zp);
cfg.update(props);
@@ -73,16 +75,17 @@ public class Activator implements Bundle
ServiceReference[] refs = context.getServiceReferences(ManagedService.class.getName(),
"(service.pid=org.apache.cxf.dosgi.discovery.zookeeper)");
if (refs == null || refs.length == 0) {
- throw new RuntimeException("This bundle must be started after the bundle with the Zookeeper Discovery Managed Service was started.");
+ throw new RuntimeException("This bundle must be started after the bundle with the Zookeeper "
+ + "Discovery Managed Service was started.");
}
Object svc = context.getService(refs[0]);
ManagedService ms = (ManagedService) svc;
- Hashtable<String, Object> props = new Hashtable<String, Object>();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("zookeeper.host", "127.0.0.1");
props.put("zookeeper.port", System.getProperty(ZOOKEEPER_PORT));
ms.updated(props);
LOG.debug("Passed the zookeeper.host property to the Zookeeper Client managed service.");
- }
+ }
private String getFreePort() {
try {
@@ -96,7 +99,7 @@ public class Activator implements Bundle
}
}
- public void stop(BundleContext context) throws Exception {
- st.close();
- }
+ public void stop(BundleContext context) throws Exception {
+ st.close();
+ }
}
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=1420394&r1=1420393&r2=1420394&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml Tue Dec 11 20:43:37 2012
@@ -67,7 +67,7 @@
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
-
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java?rev=1420394&r1=1420393&r2=1420394&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java Tue Dec 11 20:43:37 2012
@@ -1,19 +1,20 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
+ * 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;
@@ -31,12 +32,12 @@ public class Activator implements Bundle
zkStarter = new ZookeeperStarter(context);
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper.server");
- context.registerService(org.osgi.service.cm.ManagedService.class.getName(), zkStarter, props );
- }
+ context.registerService(org.osgi.service.cm.ManagedService.class.getName(), zkStarter, props);
+ }
- public void stop(BundleContext context) throws Exception {
- if (zkStarter != null) {
- zkStarter.shutdown();
- }
- }
+ public void stop(BundleContext context) throws Exception {
+ if (zkStarter != null) {
+ zkStarter.shutdown();
+ }
+ }
}
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=1420394&r1=1420393&r2=1420394&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 Dec 11 20:43:37 2012
@@ -1,19 +1,20 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
+ * 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;
@@ -36,10 +37,10 @@ import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
public class ZookeeperStarter implements org.osgi.service.cm.ManagedService {
- private static final Logger LOG = Logger.getLogger(ZookeeperStarter.class);
+ private static final Logger LOG = Logger.getLogger(ZookeeperStarter.class); //NOPMD - using log4j here
- private final BundleContext bundleContext;
protected ZookeeperServer main;
+ private final BundleContext bundleContext;
private Thread zkMainThread;
public ZookeeperStarter(BundleContext ctx) {
@@ -82,7 +83,7 @@ public class ZookeeperStarter implements
while (keys.hasMoreElements()) {
String key = keys.nextElement();
Object value = dict.get(key);
- if (value != null && value instanceof String && "".equals(value)) {
+ if (value instanceof String && "".equals(value)) {
keysToRemove.add(key);
}
}
@@ -146,8 +147,8 @@ public class ZookeeperStarter implements
}
interface ZookeeperServer {
- void startup() throws IOException;
- void shutdown();
+ void startup() throws IOException;
+ void shutdown();
}
static class MyQuorumPeerMain extends QuorumPeerMain implements ZookeeperServer {
@@ -178,7 +179,7 @@ public class ZookeeperStarter implements
public void startup() throws IOException {
ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(config);
- runFromConfig(serverConfig );
+ runFromConfig(serverConfig);
}
public void shutdown() {
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java?rev=1420394&r1=1420393&r2=1420394&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java Tue Dec 11 20:43:37 2012
@@ -1,28 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
+ * 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;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.replay;
-import static org.easymock.classextension.EasyMock.verify;
-
import java.io.File;
import java.io.IOException;
+import java.util.Dictionary;
import java.util.Hashtable;
import junit.framework.TestCase;
@@ -33,6 +31,11 @@ import org.easymock.classextension.EasyM
import org.easymock.classextension.IMocksControl;
import org.osgi.framework.BundleContext;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+
public class ZookeeperStarterTest extends TestCase {
public void testUpdateConfig() throws Exception {
final File tempDir = new File("target");
@@ -55,7 +58,7 @@ public class ZookeeperStarterTest extend
}
};
- Hashtable<String, Object> props = new Hashtable<String, Object>();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("clientPort", "1234");
starter.updated(props);
assertNotNull(starter.main);