You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by eg...@apache.org on 2007/05/18 18:23:38 UTC
svn commit: r539513 - in /incubator/cxf/trunk:
rt/core/src/main/java/org/apache/cxf/endpoint/
systests/src/test/java/org/apache/cxf/systest/lifecycle/
Author: eglynn
Date: Fri May 18 09:23:37 2007
New Revision: 539513
URL: http://svn.apache.org/viewvc?view=rev&rev=539513
Log:
Modified ServerLifeCycleManagerImpl to allow for further endpoints to be published/stopped in ServerLifeCycleListener.startServer()/stopServer() without raising a ConcurrentModificationException.
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java (with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java?view=diff&rev=539513&r1=539512&r2=539513
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerLifeCycleManagerImpl.java Fri May 18 09:23:37 2007
@@ -32,27 +32,35 @@
private List<ServerLifeCycleListener> listeners = new ArrayList<ServerLifeCycleListener>();
private Bus bus;
- public void registerListener(ServerLifeCycleListener listener) {
+ public synchronized void registerListener(ServerLifeCycleListener listener) {
listeners.add(listener);
}
public void startServer(Server server) {
- if (null != listeners) {
- for (ServerLifeCycleListener listener : listeners) {
- listener.startServer(server);
- }
+ List<ServerLifeCycleListener> listenersToNotify = null;
+ synchronized (this) {
+ listenersToNotify = new ArrayList<ServerLifeCycleListener>();
+ listenersToNotify.addAll(listeners);
+ }
+
+ for (ServerLifeCycleListener listener : listenersToNotify) {
+ listener.startServer(server);
}
}
public void stopServer(Server server) {
- if (null != listeners) {
- for (ServerLifeCycleListener listener : listeners) {
- listener.stopServer(server);
- }
- }
+ List<ServerLifeCycleListener> listenersToNotify = null;
+ synchronized (this) {
+ listenersToNotify = new ArrayList<ServerLifeCycleListener>();
+ listenersToNotify.addAll(listeners);
+ }
+
+ for (ServerLifeCycleListener listener : listenersToNotify) {
+ listener.stopServer(server);
+ }
}
- public void unRegisterListener(ServerLifeCycleListener listener) {
+ public synchronized void unRegisterListener(ServerLifeCycleListener listener) {
listeners.remove(listener);
}
@@ -71,5 +79,4 @@
bus.setExtension(this, ServerLifeCycleManager.class);
}
}
-
}
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java?view=auto&rev=539513
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java Fri May 18 09:23:37 2007
@@ -0,0 +1,102 @@
+/**
+ * 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.systest.lifecycle;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerLifeCycleListener;
+import org.apache.cxf.endpoint.ServerLifeCycleManager;
+import org.apache.cxf.systest.ws.addressing.GreeterImpl;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LifeCycleTest extends Assert {
+ private static final int RECURSIVE_LIMIT = 3;
+ private static final String[] ADDRESSES =
+ {"http://localhost:9056/SoapContext/SoapPort",
+ "http://localhost:9057/SoapContext/SoapPort",
+ "http://localhost:9058/SoapContext/SoapPort",
+ "http://localhost:9059/SoapContext/SoapPort"};
+
+ private Bus bus;
+ private ServerLifeCycleManager manager;
+ private int recursiveCount;
+ private Endpoint[] recursiveEndpoints;
+ private Map<String, Integer> startNotificationMap;
+ private Map<String, Integer> stopNotificationMap;
+
+ @Before
+ public void setUp() throws Exception {
+ bus = BusFactory.getDefaultBus();
+ manager = bus.getExtension(ServerLifeCycleManager.class);
+ recursiveCount = 0;
+ recursiveEndpoints = new Endpoint[RECURSIVE_LIMIT];
+ startNotificationMap = new HashMap<String, Integer>();
+ stopNotificationMap = new HashMap<String, Integer>();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bus.shutdown(true);
+ }
+
+ @Test
+ public void testRecursive() {
+ assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
+
+ manager.registerListener(new ServerLifeCycleListener() {
+ public void startServer(Server server) {
+ verifyNoPrior(startNotificationMap,
+ server.getEndpoint().getEndpointInfo().getAddress());
+ if (recursiveCount < RECURSIVE_LIMIT) {
+ recursiveEndpoints[recursiveCount++] =
+ Endpoint.publish(ADDRESSES[recursiveCount],
+ new GreeterImpl());
+ }
+ }
+ public void stopServer(Server server) {
+ verifyNoPrior(stopNotificationMap,
+ server.getEndpoint().getEndpointInfo().getAddress());
+ if (recursiveCount > 0) {
+ recursiveEndpoints[--recursiveCount].stop();
+ }
+ }
+ });
+
+ Endpoint.publish(ADDRESSES[0], new GreeterImpl()).stop();
+ }
+
+ private void verifyNoPrior(Map<String, Integer> notificationMap, String address) {
+ synchronized (notificationMap) {
+ assertFalse("unexpected prior notification for: " + address,
+ notificationMap.containsKey(address));
+ }
+ }
+
+}
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
------------------------------------------------------------------------------
svn:eol-style = native