FELIX-3511 - Use java.concurrent from Java 6
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1597712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/eventadmin/impl/changelog.txt b/eventadmin/impl/changelog.txt
index 6bfa5ce..fe8532d 100644
--- a/eventadmin/impl/changelog.txt
+++ b/eventadmin/impl/changelog.txt
@@ -1,6 +1,18 @@
+Changes from 1.3.2 to 1.3.4
+---------------------------
+** Improvement
+ * [FELIX-3511] - Use java.concurrent from Java 6
+ * [FELIX-4316] - Packages imported dynamically should also be imported statically with an optional flag
+
+
+Changes from 1.3.0 to 1.3.2
+---------------------------
+** Bug
+ * [FELIX-3689] - Event admin requires org.osgi.util.tracker in version 1.5
+
+
Changes from 1.2.14 to 1.3.0
----------------------------
-
** Bug
* [FELIX-3121] - Add back the manifest header indicating the provided service
* [FELIX-3451] - EventAdmin ignoring filters for handler which are registered for all (*) topics
@@ -13,7 +25,6 @@
Changes from 1.2.12 to 1.2.14
-----------------------------
-
** Bug
* [FELIX-2997] - java.lang.NullPointerException during shutdown while sending events
* [FELIX-3002] - Embed the OBR specific information for the EventAdmin bundle in the manifest
@@ -26,14 +37,12 @@
Changes from 1.2.10 to 1.2.12
-----------------------------
-
** Bug
* [FELIX-2915] - Potential deadlock on shutdown
Changes from 1.2.8 to 1.2.10
----------------------------
-
** Bug
* [FELIX-2836] - Async threads should be daemon threads
@@ -43,21 +52,18 @@
Changes from 1.2.6 to 1.2.8
---------------------------
-
** Improvement
* [FELIX-2655] - allow event admin log level to be configurable
Changes from 1.2.4 to 1.2.6
---------------------------
-
** Bug
* [FELIX-2608] - Threads should be daemon threads
Changes from 1.2.2 to 1.2.4
---------------------------
-
** Bug
* [FELIX-2582] - Event admin requires config admin packages
* [FELIX-2431] - EventAdmin service unregistered but not registered again on ConfigAdmin startup
@@ -69,7 +75,6 @@
Changes from 1.0.0 to 1.2.2
---------------------------
-
** Bug
* [FELIX-2089] - IllegalStateException thrown by LogWrapper if logging after bundle stop
diff --git a/eventadmin/impl/pom.xml b/eventadmin/impl/pom.xml
index 4686f55..c972e67 100644
--- a/eventadmin/impl/pom.xml
+++ b/eventadmin/impl/pom.xml
@@ -40,19 +40,13 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- <version>4.0.0</version>
+ <version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
- <version>4.3.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>concurrent</groupId>
- <artifactId>concurrent</artifactId>
- <version>1.3.4</version>
+ <version>5.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -64,9 +58,17 @@
</resources>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.7</version>
+ <version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
@@ -81,6 +83,7 @@
org.osgi.service.log;version="[1.3,2)"
</DynamicImport-Package>
<Import-Package>
+ org.osgi.framework;version="[1.3,2)",
<!--
Configuration Admin is optional and if it is
present, version 1.2 (from R4.0) is enough
@@ -111,10 +114,8 @@
<Export-Service>
org.osgi.service.event.EventAdmin
</Export-Service>
- <!-- Include concurrent lib but not sub packages -->
<Embed-Dependency>
- concurrent;inline="EDU/oswego/cs/dl/util/concurrent/[A-Z]*",
- org.osgi.compendium;inline="org/osgi/util/tracker/*"
+ org.osgi.core;inline="org/osgi/util/tracker/*"
</Embed-Dependency>
</instructions>
</configuration>
diff --git a/eventadmin/impl/src/main/appended-resources/META-INF/DEPENDENCIES b/eventadmin/impl/src/main/appended-resources/META-INF/DEPENDENCIES
index e667661..5bb65da 100644
--- a/eventadmin/impl/src/main/appended-resources/META-INF/DEPENDENCIES
+++ b/eventadmin/impl/src/main/appended-resources/META-INF/DEPENDENCIES
@@ -5,11 +5,6 @@
Copyright (c) OSGi Alliance (2000, 2012).
Licensed under the Apache License 2.0.
-This product includes software developed at
-Sun Microsystems, Inc.
-Copyright (c) 1994-2000.
-Licensed under a BSD license.
-
II. Used Third-Party Software
This product uses software developed at
@@ -19,4 +14,3 @@
III. License Summary
- Apache License 2.0
-- BSD License
diff --git a/eventadmin/impl/src/main/appended-resources/META-INF/LICENSE b/eventadmin/impl/src/main/appended-resources/META-INF/LICENSE
deleted file mode 100644
index 904d93f..0000000
--- a/eventadmin/impl/src/main/appended-resources/META-INF/LICENSE
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-APACHE FELIX EVENT ADMIN SUBCOMPONENTS:
-
-The Apache Felix Event Admin includes a number of subcomponents with
-separate copyright notices and license terms. Your use of the source
-code for the these subcomponents is subject to the terms and
-conditions of the following licenses.
-
-
-For Dough Lea's util.concurrent package:
-
-TECHNOLOGY LICENSE FROM SUN MICROSYSTEMS, INC. TO DOUG LEA
-
-Whereas Doug Lea desires to utlized certain Java Software technologies
-in the util.concurrent technology; and
-
-Whereas Sun Microsystems, Inc. (“Sun”) desires that Doug Lea utilize
-certain Java Software technologies in the util.concurrent technology;
-
-Therefore the parties agree as follows, effective May 31, 2002:
-
-"Java Software technologies" means
- classes/java/util/ArrayList.java, and
- classes/java/util/HashMap.java.
-
-The Java Software technologies are Copyright (c) 1994-2000 Sun Microsystems,
-Inc. All rights reserved.
-
-Sun hereby grants Doug Lea a non-exclusive, worldwide, non-transferrable
-license to use, reproduce, create derivate works of, and distribute the
-Java Software and derivative works thereof in source and binary forms as
-part of a larger work, and to sublicense the right to use, reproduce and
-distribute the Java Software and Doug Lea's derivative works as the part
-of larger works through multiple tiers of sublicensees provided that the
-following conditions are met:
-
--Neither the name of or trademarks of Sun may be used to endorse or promote
-products including or derived from the Java Software technology without
-specific prior written permission; and
--Redistributions of source or binary code must contain the above copyright
-notice, this notice and and the following disclaimers:
-
-This software is provided "AS IS," without a warranty of any kind. ALL
-EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
-ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
-OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. AND ITS
-LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
-RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES.
-IN NO EVENT WILL SUN MICROSYSTEMS, INC. OR ITS LICENSORS BE LIABLE FOR ANY
-LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
-INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
-OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
-IF SUN MICROSYSTEMS, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-You acknowledge that Software is not designed,licensed or intended for use
-in the design, construction, operation or maintenance of any nuclear facility.
diff --git a/eventadmin/impl/src/main/appended-resources/META-INF/NOTICE b/eventadmin/impl/src/main/appended-resources/META-INF/NOTICE
deleted file mode 100644
index 8b4b009..0000000
--- a/eventadmin/impl/src/main/appended-resources/META-INF/NOTICE
+++ /dev/null
@@ -1,4 +0,0 @@
-This product includes software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2012).
-Licensed under the Apache License 2.0.
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
index ee95279..8661aea 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
@@ -19,14 +19,22 @@
package org.apache.felix.eventadmin.impl;
-import java.util.*;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
-import org.apache.felix.eventadmin.impl.adapter.*;
+import org.apache.felix.eventadmin.impl.adapter.AbstractAdapter;
+import org.apache.felix.eventadmin.impl.adapter.BundleEventAdapter;
+import org.apache.felix.eventadmin.impl.adapter.FrameworkEventAdapter;
+import org.apache.felix.eventadmin.impl.adapter.LogEventAdapter;
+import org.apache.felix.eventadmin.impl.adapter.ServiceEventAdapter;
import org.apache.felix.eventadmin.impl.handler.EventAdminImpl;
import org.apache.felix.eventadmin.impl.security.SecureEventAdminFactory;
import org.apache.felix.eventadmin.impl.tasks.DefaultThreadPool;
import org.apache.felix.eventadmin.impl.util.LogWrapper;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.event.EventAdmin;
@@ -159,7 +167,7 @@
interfaceNames = new String[] {ManagedService.class.getName(), MetaTypeProvider.class.getName()};
service = enhancedService;
}
- Dictionary props = new Hashtable();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put( Constants.SERVICE_PID, PID );
m_managedServiceReg = m_bundleContext.registerService( interfaceNames, service, props );
}
@@ -170,13 +178,14 @@
}
}
- void updateFromConfigAdmin(final Dictionary config)
+ void updateFromConfigAdmin(final Dictionary<String, ?> config)
{
// do this in the background as we don't want to stop
// the config admin
new Thread()
{
+ @Override
public void run()
{
synchronized ( Configuration.this )
@@ -193,7 +202,7 @@
/**
* Configures this instance.
*/
- void configure( Dictionary config )
+ void configure( Dictionary<String, ?> config )
{
if ( config == null )
{
@@ -412,7 +421,8 @@
{
return new ManagedService()
{
- public void updated( Dictionary properties ) throws ConfigurationException
+ @Override
+ public void updated( Dictionary<String, ?> properties ) throws ConfigurationException
{
updateFromConfigAdmin(properties);
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/MetaTypeProviderImpl.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/MetaTypeProviderImpl.java
index c5dbf72..5b6f939 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/MetaTypeProviderImpl.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/MetaTypeProviderImpl.java
@@ -24,7 +24,9 @@
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
-import org.osgi.service.metatype.*;
+import org.osgi.service.metatype.AttributeDefinition;
+import org.osgi.service.metatype.MetaTypeProvider;
+import org.osgi.service.metatype.ObjectClassDefinition;
/**
* The optional meta type provider for the event admin config.
@@ -58,7 +60,8 @@
/**
* @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
*/
- public void updated(Dictionary properties) throws ConfigurationException
+ @Override
+ public void updated(Dictionary<String, ?> properties) throws ConfigurationException
{
m_delegatee.updated(properties);
}
@@ -66,6 +69,7 @@
/**
* @see org.osgi.service.metatype.MetaTypeProvider#getLocales()
*/
+ @Override
public String[] getLocales()
{
return null;
@@ -74,6 +78,7 @@
/**
* @see org.osgi.service.metatype.MetaTypeProvider#getObjectClassDefinition(java.lang.String, java.lang.String)
*/
+ @Override
public ObjectClassDefinition getObjectClassDefinition( String id, String locale )
{
if ( !Configuration.PID.equals( id ) )
@@ -83,7 +88,7 @@
if ( ocd == null )
{
- final ArrayList adList = new ArrayList();
+ final ArrayList<AttributeDefinition> adList = new ArrayList<AttributeDefinition>();
adList.add( new AttributeDefinitionImpl( Configuration.PROP_THREAD_POOL_SIZE, "Thread Pool Size",
"The size of the thread pool. The default value is 10. Increase in case of a large amount " +
@@ -119,28 +124,32 @@
ocd = new ObjectClassDefinition()
{
- private final AttributeDefinition[] attrs = ( AttributeDefinition[] ) adList
+ private final AttributeDefinition[] attrs = adList
.toArray( new AttributeDefinition[adList.size()] );
+ @Override
public String getName()
{
return "Apache Felix Event Admin Implementation";
}
+ @Override
public InputStream getIcon( int arg0 )
{
return null;
}
+ @Override
public String getID()
{
return Configuration.PID;
}
+ @Override
public String getDescription()
{
return "Configuration for the Apache Felix Event Admin Implementation." +
@@ -148,6 +157,7 @@
}
+ @Override
public AttributeDefinition[] getAttributeDefinitions( int filter )
{
return ( filter == OPTIONAL ) ? null : attrs;
@@ -198,54 +208,63 @@
}
+ @Override
public int getCardinality()
{
return cardinality;
}
+ @Override
public String[] getDefaultValue()
{
return defaultValues;
}
+ @Override
public String getDescription()
{
return description;
}
+ @Override
public String getID()
{
return id;
}
+ @Override
public String getName()
{
return name;
}
+ @Override
public String[] getOptionLabels()
{
return optionLabels;
}
+ @Override
public String[] getOptionValues()
{
return optionValues;
}
+ @Override
public int getType()
{
return type;
}
+ @Override
public String validate( String arg0 )
{
return null;
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/BundleEventAdapter.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/BundleEventAdapter.java
index c636e06..58106c8 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/BundleEventAdapter.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/BundleEventAdapter.java
@@ -50,6 +50,7 @@
context.addBundleListener(this);
}
+ @Override
public void destroy(BundleContext context) {
context.removeBundleListener(this);
}
@@ -60,9 +61,10 @@
*
* @param event The event to adapt.
*/
+ @Override
public void bundleChanged(final BundleEvent event)
{
- final Dictionary properties = new Hashtable();
+ final Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT, event);
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/FrameworkEventAdapter.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/FrameworkEventAdapter.java
index 90d8da5..a5a55f4 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/FrameworkEventAdapter.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/FrameworkEventAdapter.java
@@ -52,6 +52,7 @@
context.addFrameworkListener(this);
}
+ @Override
public void destroy(BundleContext context) {
context.removeFrameworkListener(this);
}
@@ -62,9 +63,10 @@
*
* @param event The event to adapt.
*/
+ @Override
public void frameworkEvent(final FrameworkEvent event)
{
- final Dictionary properties = new Hashtable();
+ final Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT, event);
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/LogEventAdapter.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/LogEventAdapter.java
index 1c48586..31df557 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/LogEventAdapter.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/LogEventAdapter.java
@@ -101,6 +101,7 @@
}
}
+ @Override
public void destroy(BundleContext context) {
context.removeServiceListener(this);
}
@@ -113,6 +114,7 @@
*
* @param event The event to adapt.
*/
+ @Override
public void serviceChanged(final ServiceEvent event)
{
if (ServiceEvent.REGISTERED == event.getType())
@@ -146,13 +148,14 @@
m_logListener = new org.osgi.service.log.LogListener()
{
+ @Override
public void logged(final org.osgi.service.log.LogEntry entry)
{
// This is where the assembly as specified in 133.6.6 OSGi R4
// compendium is taking place (i.e., the log entry is adapted to
// an event and posted via the EventAdmin)
- final Dictionary properties = new Hashtable();
+ final Dictionary<String, Object> properties = new Hashtable<String, Object>();
final Bundle bundle = entry.getBundle();
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/ServiceEventAdapter.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/ServiceEventAdapter.java
index 7482e13..cf55b8b 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/ServiceEventAdapter.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/adapter/ServiceEventAdapter.java
@@ -53,6 +53,7 @@
context.addServiceListener(this);
}
+ @Override
public void destroy(BundleContext context) {
context.removeServiceListener(this);
}
@@ -63,9 +64,10 @@
*
* @param event The event to adapt.
*/
+ @Override
public void serviceChanged(final ServiceEvent event)
{
- final Dictionary properties = new Hashtable();
+ final Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT, event);
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
index d2be473..158f9b9 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
@@ -123,11 +123,12 @@
}
else if (topicObj instanceof Collection)
{
- final Collection col = (Collection)topicObj;
+ @SuppressWarnings("unchecked")
+ final Collection<Object> col = (Collection<Object>)topicObj;
final String[] values = new String[col.size()];
int index = 0;
// check if one value matches '*'
- final Iterator i = col.iterator();
+ final Iterator<Object> i = col.iterator();
boolean matchAll = false;
while ( i.hasNext() )
{
@@ -212,7 +213,9 @@
Object delivery = reference.getProperty(EventConstants.EVENT_DELIVERY);
if ( delivery instanceof Collection )
{
- delivery = ((Collection)delivery).toArray(new String[((Collection)delivery).size()]);
+ @SuppressWarnings("unchecked")
+ final Collection<String> col = (Collection<String>)delivery;
+ delivery = col.toArray(new String[col.size()]);
}
if ( delivery instanceof String )
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
index 5babd1a..be3e674 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
@@ -18,7 +18,14 @@
*/
package org.apache.felix.eventadmin.impl.handler;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -31,20 +38,20 @@
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class EventHandlerTracker extends ServiceTracker {
+public class EventHandlerTracker extends ServiceTracker<EventHandler, EventHandlerProxy> {
/** The proxies in this list match all events. */
- private volatile List matchingAllEvents;
+ private volatile List<EventHandlerProxy> matchingAllEvents;
/** This is a map for exact topic matches. The key is the topic,
* the value is a list of proxies.
*/
- private volatile Map matchingTopic;
+ private volatile Map<String, List<EventHandlerProxy>> matchingTopic;
/** This is a map for wildcard topics. The key is the prefix of the topic,
* the value is a list of proxies
*/
- private volatile Map matchingPrefixTopic;
+ private volatile Map<String, List<EventHandlerProxy>> matchingPrefixTopic;
/** The context for the proxies. */
@@ -54,9 +61,9 @@
super(context, EventHandler.class.getName(), null);
// we start with empty collections
- this.matchingAllEvents = new ArrayList();
- this.matchingTopic = new HashMap();
- this.matchingPrefixTopic = new HashMap();
+ this.matchingAllEvents = new ArrayList<EventHandlerProxy>();
+ this.matchingTopic = new HashMap<String, List<EventHandlerProxy>>();
+ this.matchingPrefixTopic = new HashMap<String, List<EventHandlerProxy>>();
}
/**
@@ -102,7 +109,8 @@
/**
* @see org.osgi.util.tracker.ServiceTracker#addingService(org.osgi.framework.ServiceReference)
*/
- public Object addingService(final ServiceReference reference) {
+ @Override
+ public EventHandlerProxy addingService(final ServiceReference reference) {
final EventHandlerProxy proxy = new EventHandlerProxy(this.handlerContext, reference);
if ( proxy.update() ) {
this.put(proxy);
@@ -113,8 +121,8 @@
/**
* @see org.osgi.util.tracker.ServiceTracker#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- public void modifiedService(final ServiceReference reference, final Object service) {
- final EventHandlerProxy proxy = (EventHandlerProxy)service;
+ @Override
+ public void modifiedService(final ServiceReference reference, final EventHandlerProxy proxy) {
this.remove(proxy);
if ( proxy.update() ) {
this.put(proxy);
@@ -124,22 +132,22 @@
/**
* @see org.osgi.util.tracker.ServiceTracker#removedService(org.osgi.framework.ServiceReference, java.lang.Object)
*/
- public void removedService(ServiceReference reference, Object service) {
- final EventHandlerProxy proxy = (EventHandlerProxy)service;
+ @Override
+ public void removedService(final ServiceReference reference, final EventHandlerProxy proxy) {
this.remove(proxy);
proxy.dispose();
}
- private void updateMap(final Map proxyListMap, final String key, final EventHandlerProxy proxy, final boolean add) {
- List proxies = (List)proxyListMap.get(key);
+ private void updateMap(final Map<String, List<EventHandlerProxy>> proxyListMap, final String key, final EventHandlerProxy proxy, final boolean add) {
+ List<EventHandlerProxy> proxies = proxyListMap.get(key);
if (proxies == null) {
if ( !add )
{
return;
}
- proxies = new ArrayList();
+ proxies = new ArrayList<EventHandlerProxy>();
} else {
- proxies = new ArrayList(proxies);
+ proxies = new ArrayList<EventHandlerProxy>(proxies);
}
if ( add )
{
@@ -169,14 +177,14 @@
final String[] topics = proxy.getTopics();
if ( topics == null )
{
- final List newMatchingAllEvents = new ArrayList(this.matchingAllEvents);
+ final List<EventHandlerProxy> newMatchingAllEvents = new ArrayList<EventHandlerProxy>(this.matchingAllEvents);
newMatchingAllEvents.add(proxy);
this.matchingAllEvents = newMatchingAllEvents;
}
else
{
- Map newMatchingTopic = null;
- Map newMatchingPrefixTopic = null;
+ Map<String, List<EventHandlerProxy>> newMatchingTopic = null;
+ Map<String, List<EventHandlerProxy>> newMatchingPrefixTopic = null;
for(int i = 0; i < topics.length; i++) {
final String topic = topics[i];
@@ -185,7 +193,7 @@
// prefix topic: we remove the /*
if ( newMatchingPrefixTopic == null )
{
- newMatchingPrefixTopic = new HashMap(this.matchingPrefixTopic);
+ newMatchingPrefixTopic = new HashMap<String, List<EventHandlerProxy>>(this.matchingPrefixTopic);
}
final String prefix = topic.substring(0, topic.length() - 2);
@@ -196,7 +204,7 @@
// exact match
if ( newMatchingTopic == null )
{
- newMatchingTopic = new HashMap(this.matchingTopic);
+ newMatchingTopic = new HashMap<String, List<EventHandlerProxy>>(this.matchingTopic);
}
this.updateMap(newMatchingTopic, topic, proxy, true);
@@ -223,12 +231,12 @@
final String[] topics = proxy.getTopics();
if ( topics == null )
{
- final List newMatchingAllEvents = new ArrayList(this.matchingAllEvents);
+ final List<EventHandlerProxy> newMatchingAllEvents = new ArrayList<EventHandlerProxy>(this.matchingAllEvents);
newMatchingAllEvents.remove(proxy);
this.matchingAllEvents = newMatchingAllEvents;
} else {
- Map newMatchingTopic = null;
- Map newMatchingPrefixTopic = null;
+ Map<String, List<EventHandlerProxy>> newMatchingTopic = null;
+ Map<String, List<EventHandlerProxy>> newMatchingPrefixTopic = null;
for(int i = 0; i < topics.length; i++) {
final String topic = topics[i];
@@ -237,7 +245,7 @@
// prefix topic: we remove the /*
if ( newMatchingPrefixTopic == null )
{
- newMatchingPrefixTopic = new HashMap(this.matchingPrefixTopic);
+ newMatchingPrefixTopic = new HashMap<String, List<EventHandlerProxy>>(this.matchingPrefixTopic);
}
final String prefix = topic.substring(0, topic.length() - 2);
@@ -248,7 +256,7 @@
// exact match
if ( newMatchingTopic == null )
{
- newMatchingTopic = new HashMap(this.matchingTopic);
+ newMatchingTopic = new HashMap<String, List<EventHandlerProxy>>(this.matchingTopic);
}
this.updateMap(newMatchingTopic, topic, proxy, false);
@@ -271,10 +279,10 @@
* @param event The event topic
* @return All handlers for the event
*/
- public Collection getHandlers(final Event event) {
+ public Collection<EventHandlerProxy> getHandlers(final Event event) {
final String topic = event.getTopic();
- final Set handlers = new HashSet();
+ final Set<EventHandlerProxy> handlers = new HashSet<EventHandlerProxy>();
// Add all handlers matching everything
handlers.addAll(this.matchingAllEvents);
@@ -286,7 +294,7 @@
while (pos != -1)
{
final String prefix = topic.substring(0, pos);
- List proxies = (List)this.matchingPrefixTopic.get(prefix);
+ List<EventHandlerProxy> proxies = this.matchingPrefixTopic.get(prefix);
if (proxies != null)
{
handlers.addAll(proxies);
@@ -297,15 +305,15 @@
}
// Add the handlers for matching topic names
- List proxies = (List)this.matchingTopic.get(topic);
+ List<EventHandlerProxy> proxies = this.matchingTopic.get(topic);
if (proxies != null) {
handlers.addAll(proxies);
}
// now check permission and filters
- final Iterator i = handlers.iterator();
+ final Iterator<EventHandlerProxy> i = handlers.iterator();
while ( i.hasNext() ) {
- final EventHandlerProxy proxy = (EventHandlerProxy) i.next();
+ final EventHandlerProxy proxy = i.next();
if ( !proxy.canDeliver(event) ) {
i.remove();
}
@@ -332,6 +340,7 @@
{
m_packageName = name;
}
+ @Override
public boolean match(String className)
{
final int pos = className.lastIndexOf('.');
@@ -348,6 +357,7 @@
{
m_packageName = name + '.';
}
+ @Override
public boolean match(String className)
{
final int pos = className.lastIndexOf('.');
@@ -364,6 +374,7 @@
{
m_className = name;
}
+ @Override
public boolean match(String className)
{
return m_className.equals(className);
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
index a0b3545..465b2fa 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
@@ -19,11 +19,10 @@
package org.apache.felix.eventadmin.impl.tasks;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.felix.eventadmin.impl.handler.EventHandlerProxy;
import org.osgi.service.event.Event;
/**
@@ -43,7 +42,7 @@
private final SyncDeliverTasks m_deliver_task;
/** A map of running threads currently delivering async events. */
- private final Map m_running_threads = new HashMap();
+ private final Map<Long, TaskExecuter> m_running_threads = new ConcurrentHashMap<Long, TaskExecuter>();
/**
* The constructor of the class that will use the asynchronous.
@@ -65,7 +64,7 @@
* @param tasks The event handler dispatch tasks to execute
*
*/
- public void execute(final Collection tasks, final Event event)
+ public void execute(final Collection<EventHandlerProxy> tasks, final Event event)
{
/*
final Iterator i = tasks.iterator();
@@ -85,67 +84,94 @@
}
if ( hasOrdered )
{*/
- final Thread currentThread = Thread.currentThread();
- TaskExecuter executer = null;
- synchronized (m_running_threads )
+ final TaskInfo info = new TaskInfo(tasks, event);
+ final Long currentThreadId = Thread.currentThread().getId();
+ TaskExecuter executer = m_running_threads.get(currentThreadId);
+ if ( executer == null )
{
- final TaskExecuter runningExecutor = (TaskExecuter)m_running_threads.get(currentThread);
- if ( runningExecutor != null )
- {
- runningExecutor.add(tasks, event);
- }
- else
- {
- executer = new TaskExecuter( tasks, event, currentThread );
- m_running_threads.put(currentThread, executer);
- }
+ executer = new TaskExecuter();
+ m_running_threads.put(currentThreadId, executer);
}
- if ( executer != null )
+ synchronized ( executer )
{
- m_pool.executeTask(executer);
+ executer.add(info);
+ if ( !executer.isActive() )
+ {
+ executer.setSyncDeliverTasks(m_deliver_task);
+ m_pool.executeTask(executer);
+ }
}
//}
}
- private final class TaskExecuter implements Runnable
+ private final static class TaskInfo {
+ public final Collection<EventHandlerProxy> tasks;
+ public final Event event;
+
+ public TaskInfo next;
+
+ public TaskInfo(final Collection<EventHandlerProxy> tasks, final Event event) {
+ this.tasks = tasks;
+ this.event = event;
+ }
+ }
+
+ private final static class TaskExecuter implements Runnable
{
- private final List m_tasks = new LinkedList();
+ private volatile TaskInfo first;
+ private volatile TaskInfo last;
- private final Object m_key;
+ private volatile SyncDeliverTasks m_deliver_task;
- public TaskExecuter(final Collection tasks, final Event event, final Object key)
+ public boolean isActive()
{
- m_key = key;
- m_tasks.add(new Object[] {tasks, event});
+ return this.m_deliver_task != null;
}
+ public void setSyncDeliverTasks(final SyncDeliverTasks syncDeliverTasks)
+ {
+ this.m_deliver_task = syncDeliverTasks;
+ }
+
+ @Override
public void run()
{
boolean running;
do
{
- Object[] tasks = null;
- synchronized ( m_tasks )
+ TaskInfo info = null;
+ synchronized ( this )
{
- tasks = (Object[]) m_tasks.remove(0);
+ info = first;
+ first = info.next;
+ if ( first == null )
+ {
+ last = null;
+ }
}
- m_deliver_task.execute((Collection)tasks[0], (Event)tasks[1], true);
- synchronized ( m_running_threads )
+ m_deliver_task.execute(info.tasks, info.event, true);
+ synchronized ( this )
{
- running = m_tasks.size() > 0;
+ running = first != null;
if ( !running )
{
- m_running_threads.remove(m_key);
+ this.m_deliver_task = null;
}
}
} while ( running );
}
- public void add(final Collection tasks, final Event event)
+ public void add(final TaskInfo info)
{
- synchronized ( m_tasks )
+ if ( first == null )
{
- m_tasks.add(new Object[] {tasks, event});
+ first = info;
+ last = info;
+ }
+ else
+ {
+ last.next = info;
+ last = info;
}
}
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DefaultThreadPool.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DefaultThreadPool.java
index 7facee1..1b8d3b9 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DefaultThreadPool.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DefaultThreadPool.java
@@ -16,9 +16,12 @@
*/
package org.apache.felix.eventadmin.impl.tasks;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
import org.apache.felix.eventadmin.impl.util.LogWrapper;
-import EDU.oswego.cs.dl.util.concurrent.*;
/**
* A thread pool that allows to execute tasks using pooled threads in order
@@ -27,20 +30,25 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class DefaultThreadPool
- extends PooledExecutor
{
+ private ExecutorService executor;
+
+ private final ThreadFactory threadFactory;
+
+ private int oldSize = -1;
+
/**
* Create a new pool.
*/
public DefaultThreadPool(final int poolSize, final boolean syncThreads)
{
- super(new LinkedQueue());
- if ( syncThreads )
- {
- this.setThreadFactory(new ThreadFactory()
+ if ( syncThreads )
+ {
+ threadFactory = new ThreadFactory()
{
+ @Override
public Thread newThread( final Runnable command )
{
final Thread thread = new SyncThread( command );
@@ -49,13 +57,14 @@
return thread;
}
- });
- }
- else
- {
- this.setThreadFactory(new ThreadFactory()
+ };
+ }
+ else
+ {
+ threadFactory = new ThreadFactory()
{
+ @Override
public Thread newThread( final Runnable command )
{
final Thread thread = new Thread( command );
@@ -64,20 +73,26 @@
return thread;
}
- });
- }
+ };
+ }
configure(poolSize);
- setKeepAliveTime(60000);
- runWhenBlocked();
}
/**
* Configure a new pool size.
*/
- public void configure(final int poolSize)
+ public synchronized void configure(final int poolSize)
{
- setMinimumPoolSize(poolSize);
- setMaximumPoolSize(poolSize + 10);
+ if ( oldSize != poolSize)
+ {
+ oldSize = poolSize;
+ final ExecutorService oldService = this.executor;
+ this.executor = Executors.newFixedThreadPool(poolSize, threadFactory);
+ if ( oldService != null )
+ {
+ oldService.shutdown();
+ }
+ }
}
/**
@@ -86,8 +101,7 @@
*/
public void close()
{
- shutdownNow();
-
+ this.executor.shutdownNow();
}
/**
@@ -98,7 +112,7 @@
{
try
{
- super.execute(task);
+ this.executor.submit(task);
}
catch (final Throwable t)
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/Rendezvous.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/Rendezvous.java
index 3d95d4b..176d5f9 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/Rendezvous.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/Rendezvous.java
@@ -18,7 +18,11 @@
*/
package org.apache.felix.eventadmin.impl.tasks;
-import EDU.oswego.cs.dl.util.concurrent.*;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
/**
* This is a simplified version of the CyclicBarrier implementation.
@@ -52,7 +56,7 @@
}
try
{
- this.barrier();
+ this.await();
}
catch (BrokenBarrierException ignore1)
{
@@ -70,8 +74,8 @@
{
try
{
- this.attemptBarrier(timeout);
- this.restart();
+ this.await(timeout, TimeUnit.MILLISECONDS);
+ this.reset();
}
catch (BrokenBarrierException ignore1)
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
index 5e17362..c3dbbdc 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
@@ -20,11 +20,11 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.concurrent.TimeoutException;
import org.apache.felix.eventadmin.impl.handler.EventHandlerProxy;
import org.osgi.service.event.Event;
-import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
/**
* This class does the actual work of the synchronous event delivery.
@@ -101,15 +101,15 @@
* @param tasks The event handler dispatch tasks to execute
*
*/
- public void execute(final Collection tasks, final Event event, final boolean filterAsyncUnordered)
+ public void execute(final Collection<EventHandlerProxy> tasks, final Event event, final boolean filterAsyncUnordered)
{
final Thread sleepingThread = Thread.currentThread();
final SyncThread syncThread = sleepingThread instanceof SyncThread ? (SyncThread)sleepingThread : null;
- final Iterator i = tasks.iterator();
+ final Iterator<EventHandlerProxy> i = tasks.iterator();
while ( i.hasNext() )
{
- final EventHandlerProxy task = (EventHandlerProxy)i.next();
+ final EventHandlerProxy task = i.next();
// if ( !filterAsyncUnordered || task.isAsyncOrderedDelivery() )
// {
if ( !useTimeout(task) )
@@ -134,6 +134,7 @@
final Rendezvous timerBarrier = new Rendezvous();
this.pool.executeTask(new Runnable()
{
+ @Override
public void run()
{
try
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/util/LogWrapper.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/util/LogWrapper.java
index 7e7f0e8..1a94ae7 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/util/LogWrapper.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/util/LogWrapper.java
@@ -85,7 +85,7 @@
public static final int LOG_DEBUG = 4;
// A set containing the currently available LogServices. Furthermore used as lock
- private final Set m_loggerRefs = new HashSet();
+ private final Set<ServiceReference> m_loggerRefs = new HashSet<ServiceReference>();
// Only null while not set and m_loggerRefs is empty hence, only needs to be
// checked in case m_loggerRefs is empty otherwise it will not be null.
@@ -158,6 +158,7 @@
ServiceListener listener = new ServiceListener()
{
// Add a newly available LogService reference to the singleton.
+ @Override
public void serviceChanged( final ServiceEvent event )
{
if ( ServiceEvent.REGISTERED == event.getType() )
@@ -254,9 +255,9 @@
{
// There is at least one LogService available hence, we can use the
// class as well.
- for (Iterator iter = m_loggerRefs.iterator(); iter.hasNext();)
+ for (Iterator<ServiceReference> iter = m_loggerRefs.iterator(); iter.hasNext();)
{
- final ServiceReference next = (ServiceReference) iter.next();
+ final ServiceReference next = iter.next();
org.osgi.service.log.LogService logger =
(org.osgi.service.log.LogService) m_context.getService(next);
@@ -306,9 +307,9 @@
{
// There is at least one LogService available hence, we can use the
// class as well.
- for (Iterator iter = m_loggerRefs.iterator(); iter.hasNext();)
+ for (Iterator<ServiceReference> iter = m_loggerRefs.iterator(); iter.hasNext();)
{
- final ServiceReference next = (ServiceReference) iter.next();
+ final ServiceReference next = iter.next();
org.osgi.service.log.LogService logger =
(org.osgi.service.log.LogService) m_context.getService(next);
@@ -358,9 +359,9 @@
{
// There is at least one LogService available hence, we can use the
// class as well.
- for (Iterator iter = m_loggerRefs.iterator(); iter.hasNext();)
+ for (Iterator<ServiceReference> iter = m_loggerRefs.iterator(); iter.hasNext();)
{
- final ServiceReference next = (ServiceReference) iter.next();
+ final ServiceReference next = iter.next();
org.osgi.service.log.LogService logger =
(org.osgi.service.log.LogService) m_context.getService(next);
@@ -405,16 +406,16 @@
{
return; // don't log
}
-
+
final String logMsg = "EventAdmin: " + msg;
if (!m_loggerRefs.isEmpty())
{
// There is at least one LogService available hence, we can use the
// class as well.
- for (Iterator iter = m_loggerRefs.iterator(); iter.hasNext();)
+ for (Iterator<ServiceReference> iter = m_loggerRefs.iterator(); iter.hasNext();)
{
- final ServiceReference next = (ServiceReference) iter.next();
+ final ServiceReference next = iter.next();
org.osgi.service.log.LogService logger =
(org.osgi.service.log.LogService) m_context.getService(next);