Author: cschneider
Date: Mon Jan 9 12:18:00 2012
New Revision: 1229107
URL: http://svn.apache.org/viewvc?rev=1229107&view=rev
Log:
CXF-4014 Adding compatibility for old workqueue configs in one file
Added:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java
(with props)
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java
(with props)
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/org.apache.cxf.workqueues.cfg
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java
cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java?rev=1229107&r1=1229106&r2=1229107&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFActivator.java
Mon Jan 9 12:18:00 2012
@@ -30,6 +30,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.cm.ManagedServiceFactory;
import org.osgi.util.tracker.ServiceTracker;
@@ -46,6 +47,7 @@ public class CXFActivator implements Bun
private ServiceTracker configAdminTracker;
private CXFExtensionBundleListener cxfBundleListener;
private ServiceRegistration workQueueServiceRegistration;
+ private ServiceRegistration wqSingleConfigRegistratin;
/** {@inheritDoc}*/
public void start(BundleContext context) throws Exception {
@@ -56,20 +58,28 @@ public class CXFActivator implements Bun
configAdminTracker = new ServiceTracker(context,
ConfigurationAdmin.class.getName(), null);
configAdminTracker.open();
workQueues.setConfigAdminTracker(configAdminTracker);
- workQueueServiceRegistration = registerManagedServiceFactory(context,
workQueues,
+ workQueueServiceRegistration = registerManagedServiceFactory(context,
ManagedServiceFactory.class,
+
workQueues,
ManagedWorkQueueList.FACTORY_PID);
+
+ WorkQueueSingleConfig wqSingleConfig = new
WorkQueueSingleConfig(workQueues);
+ wqSingleConfigRegistratin = registerManagedServiceFactory(context,
ManagedService.class,
+
wqSingleConfig,
+
WorkQueueSingleConfig.SERVICE_PID);
+
extensions = new ArrayList<Extension>();
extensions.add(createOsgiBusListenerExtension(context));
extensions.add(createManagedWorkQueueListExtension(workQueues));
ExtensionRegistry.addExtensions(extensions);
}
- private ServiceRegistration registerManagedServiceFactory(BundleContext
context,
+ private ServiceRegistration registerManagedServiceFactory(BundleContext
context,
+ Class
serviceClass,
Object service,
String
servicePid) {
Properties props = new Properties();
props.put(Constants.SERVICE_PID, servicePid);
- return context.registerService(ManagedServiceFactory.class.getName(),
workQueues, props);
+ return context.registerService(serviceClass.getName(), workQueues,
props);
}
private Extension createOsgiBusListenerExtension(BundleContext context) {
@@ -96,6 +106,7 @@ public class CXFActivator implements Bun
cxfBundleListener.shutdown();
workQueues.shutDown();
workQueueServiceRegistration.unregister();
+ wqSingleConfigRegistratin.unregister();
configAdminTracker.close();
ExtensionRegistry.removeExtensions(extensions);
}
Added:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java?rev=1229107&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java
(added)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java
Mon Jan 9 12:18:00 2012
@@ -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.bus.osgi;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+/**
+ * Use the ManagedWorkQueueList config style instead
+ */
+@Deprecated
+public class WorkQueueSingleConfig implements ManagedService {
+ public static final String SERVICE_PID = "org.apache.cxf.workqueue";
+ public static final String PROPERTY_PREFIX = "org.apache.cxf.workqueue";
+ ManagedWorkQueueList workQueueList;
+
+ public WorkQueueSingleConfig(ManagedWorkQueueList workQueueList) {
+ this.workQueueList = workQueueList;
+ }
+
+ public void updated(Dictionary properties) throws ConfigurationException {
+ String names = (String)properties.get(PROPERTY_PREFIX + ".names");
+ String[] nameAr = names.split(",");
+ for (String name : nameAr) {
+ updateQueue(name.trim(), properties);
+ }
+ }
+
+ private void updateQueue(String name, Dictionary properties)
+ throws ConfigurationException {
+ Dictionary<String, String> queueProperties = new Hashtable<String,
String>();
+ Enumeration it = properties.keys();
+ while (it.hasMoreElements()) {
+ String key = (String)it.nextElement();
+ String prefix = PROPERTY_PREFIX + "." + name + ".";
+ if (key.startsWith(prefix)) {
+ String newKey = (String)key.substring(prefix.length());
+ queueProperties.put(newKey, (String)properties.get(key));
+ }
+ }
+ queueProperties.put(AutomaticWorkQueueImpl.PROPERTY_NAME, name);
+ workQueueList.updated(name, queueProperties);
+ }
+
+
+}
Propchange:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java?rev=1229107&r1=1229106&r2=1229107&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
Mon Jan 9 12:18:00 2012
@@ -498,6 +498,10 @@ public class AutomaticWorkQueueImpl impl
int lwm = executor == null ? lowWaterMark : executor.getCorePoolSize();
return lwm == Integer.MAX_VALUE ? -1 : lwm;
}
+
+ public int getInitialSize() {
+ return this.initialThreads;
+ }
public void setHighWaterMark(int hwm) {
highWaterMark = hwm < 0 ? Integer.MAX_VALUE : hwm;
Added:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java?rev=1229107&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java
(added)
+++
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java
Mon Jan 9 12:18:00 2012
@@ -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.bus.osgi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
+import org.apache.cxf.workqueue.WorkQueueManager;
+import org.apache.cxf.workqueue.WorkQueueManagerImpl;
+import org.junit.Test;
+import org.osgi.service.cm.ConfigurationException;
+
+@Deprecated
+public class WorkQueueSingleConfigTest {
+ @Test
+ public void testReadConfig() throws IOException, ConfigurationException {
+ WorkQueueManager wqm = new WorkQueueManagerImpl();
+ Assert.assertNull(wqm.getNamedWorkQueue("default"));
+ ManagedWorkQueueList workQueueList = new ManagedWorkQueueList();
+ WorkQueueSingleConfig wqlSingleConfig =
+ new WorkQueueSingleConfig(workQueueList);
+ InputStream is =
this.getClass().getResourceAsStream("org.apache.cxf.workqueues.cfg");
+ Properties properties = new Properties();
+ properties.load(is);
+ wqlSingleConfig.updated(properties);
+ workQueueList.addAllToWorkQueueManager(wqm);
+ checkDefaultQueue(wqm);
+ }
+
+ private void checkDefaultQueue(WorkQueueManager wqm) {
+ AutomaticWorkQueueImpl queue =
(AutomaticWorkQueueImpl)wqm.getNamedWorkQueue("default");
+ Assert.assertEquals(50, queue.getHighWaterMark());
+ Assert.assertEquals(5, queue.getLowWaterMark());
+ Assert.assertEquals(5, queue.getInitialSize());
+ }
+}
Propchange:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/WorkQueueSingleConfigTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/org.apache.cxf.workqueues.cfg
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/org.apache.cxf.workqueues.cfg?rev=1229107&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/org.apache.cxf.workqueues.cfg
(added)
+++
cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/osgi/org.apache.cxf.workqueues.cfg
Mon Jan 9 12:18:00 2012
@@ -0,0 +1,4 @@
+org.apache.cxf.workqueue.names=default
+org.apache.cxf.workqueue.default.highWaterMark=50
+org.apache.cxf.workqueue.default.lowWaterMark=5
+org.apache.cxf.workqueue.default.initialSize=5