Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FELIX-3708 use java 5-isms in DS

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1415461 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 2053bfbb3d3f78648ee123bda4ca145498924594 1 parent 9656847
David Jencks authored
Showing with 458 additions and 530 deletions.
  1. +10 −11 scr/src/main/java/org/apache/felix/scr/impl/Activator.java
  2. +21 −23 scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
  3. +35 −31 scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
  4. +97 −98 scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
  5. +1 −1  scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
  6. +3 −3 scr/src/main/java/org/apache/felix/scr/impl/helper/MethodResult.java
  7. +64 −109 scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
  8. +28 −29 scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
  9. +5 −5 scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java
  10. +1 −7 scr/src/main/java/org/apache/felix/scr/impl/manager/DelayedComponentManager.java
  11. +90 −92 scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
  12. +55 −66 scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
  13. +7 −7 scr/src/main/java/org/apache/felix/scr/impl/manager/RefPair.java
  14. +24 −31 scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
  15. +10 −10 scr/src/main/java/org/apache/felix/scr/impl/metadata/ComponentMetadata.java
  16. +2 −2 scr/src/main/java/org/apache/felix/scr/impl/metadata/PropertyMetadata.java
  17. +2 −2 scr/src/main/java/org/apache/felix/scr/impl/metadata/ServiceMetadata.java
  18. +1 −1  scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java
  19. +2 −2 scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
View
21 scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -61,7 +61,7 @@
private static ServiceTracker m_packageAdmin;
// map of BundleComponentActivator instances per Bundle indexed by Bundle id
- private Map m_componentBundles;
+ private Map<Long, BundleComponentActivator> m_componentBundles;
// registry of managed component
private ComponentRegistry m_componentRegistry;
@@ -85,7 +85,7 @@ public void start( BundleContext context ) throws Exception
m_logService.open();
// prepare component registry
- m_componentBundles = new HashMap();
+ m_componentBundles = new HashMap<Long, BundleComponentActivator>();
m_componentRegistry = new ComponentRegistry( context );
// get the configuration
@@ -191,9 +191,8 @@ else if ( event.getType() == BundleEvent.STOPPING )
private void loadAllComponents( BundleContext context )
{
Bundle[] bundles = context.getBundles();
- for ( int i = 0; i < bundles.length; i++ )
+ for ( Bundle bundle : bundles )
{
- Bundle bundle = bundles[i];
if ( ComponentRegistry.isBundleActive( bundle ) )
{
loadComponents( bundle );
@@ -234,7 +233,7 @@ private void loadComponents( Bundle bundle )
// FELIX-2231 Mark bundle loaded early to prevent concurrent loading
// if LAZY_ACTIVATION and STARTED event are fired at the same time
final boolean loaded;
- final Long bundleId = new Long( bundle.getBundleId() );
+ final Long bundleId = bundle.getBundleId();
synchronized ( m_componentBundles )
{
if ( m_componentBundles.containsKey( bundleId ) )
@@ -243,7 +242,7 @@ private void loadComponents( Bundle bundle )
}
else
{
- m_componentBundles.put( bundleId, bundleId );
+ m_componentBundles.put( bundleId, null );
loaded = false;
}
}
@@ -306,7 +305,7 @@ private void disposeComponents( Bundle bundle )
final Object ga;
synchronized ( m_componentBundles )
{
- ga = m_componentBundles.remove( new Long( bundle.getBundleId() ) );
+ ga = m_componentBundles.remove( bundle.getBundleId() );
}
if ( ga instanceof BundleComponentActivator )
@@ -334,11 +333,11 @@ private void disposeAllComponents()
m_componentBundles.clear();
}
- for ( int i = 0; i < activators.length; i++ )
+ for ( Object activator : activators )
{
- if ( activators[i] instanceof BundleComponentActivator )
+ if ( activator instanceof BundleComponentActivator )
{
- final BundleComponentActivator ga = ( BundleComponentActivator ) activators[i];
+ final BundleComponentActivator ga = ( BundleComponentActivator ) activator;
try
{
final Bundle bundle = ga.getBundleContext().getBundle();
@@ -349,7 +348,7 @@ private void disposeAllComponents()
catch ( Exception e )
{
log( LogService.LOG_ERROR, m_context.getBundle(), "Error while disposing components of bundle "
- + bundle.getSymbolicName() + "/" + bundle.getBundleId(), e );
+ + bundle.getSymbolicName() + "/" + bundle.getBundleId(), e );
}
}
catch ( IllegalStateException e )
View
44 scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
@@ -61,7 +61,7 @@
private BundleContext m_context = null;
// This is a list of component instance managers that belong to a particular bundle
- private List m_managers = new ArrayList();
+ private List<ComponentHolder> m_managers = new ArrayList<ComponentHolder>();
// The Configuration Admin tracker providing configuration for components
private ServiceTracker m_logService;
@@ -144,16 +144,15 @@ private void initialize( String descriptorLocations )
}
// load from the descriptors
- for ( int i = 0; i < descriptorURLs.length; i++ )
+ for ( URL descriptorURL : descriptorURLs )
{
- loadDescriptor( descriptorURLs[i] );
+ loadDescriptor( descriptorURL );
}
}
//enable all the enabled components
- for (Iterator it = m_managers.iterator(); it.hasNext();)
+ for ( ComponentHolder componentHolder : m_managers )
{
- ComponentHolder componentHolder = ( ComponentHolder ) it.next();
- if (componentHolder.getComponentMetadata().isEnabled())
+ if ( componentHolder.getComponentMetadata().isEnabled() )
{
componentHolder.enableComponents( false );
}
@@ -191,19 +190,19 @@ private void initialize( String descriptorLocations )
}
// find the entries
- final Enumeration entries = bundle.findEntries( path, filePattern, false );
+ final Enumeration<URL> entries = bundle.findEntries( path, filePattern, false );
if ( entries == null || !entries.hasMoreElements() )
{
return new URL[0];
}
// create the result list
- List urls = new ArrayList();
+ List<URL> urls = new ArrayList<URL>();
while ( entries.hasMoreElements() )
{
urls.add( entries.nextElement() );
}
- return ( URL[] ) urls.toArray( new URL[urls.size()] );
+ return urls.toArray( new URL[urls.size()] );
}
@@ -227,10 +226,9 @@ private void loadDescriptor( final URL descriptorURL )
// 112.4.2 Component descriptors may contain a single, root component element
// or one or more component elements embedded in a larger document
- Iterator i = handler.getComponentMetadataList().iterator();
- while ( i.hasNext() )
+ for ( Object o : handler.getComponentMetadataList() )
{
- ComponentMetadata metadata = ( ComponentMetadata ) i.next();
+ ComponentMetadata metadata = ( ComponentMetadata ) o;
ComponentRegistryKey key = null;
try
{
@@ -313,7 +311,7 @@ void dispose( int reason )
while ( m_managers.size() != 0 )
{
- ComponentHolder holder = ( ComponentHolder ) m_managers.get( 0 );
+ ComponentHolder holder = m_managers.get( 0 );
try
{
m_managers.remove( holder );
@@ -333,7 +331,7 @@ void dispose( int reason )
}
log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED", new Object[]
- { new Long( m_context.getBundle().getBundleId() ) }, null, null );
+ {m_context.getBundle().getBundleId()}, null, null );
if (m_logService != null) {
m_logService.close();
@@ -393,16 +391,16 @@ public void enableComponent( final String name )
return;
}
- for ( int i = 0; i < holder.length; i++ )
+ for ( ComponentHolder aHolder : holder )
{
try
{
- log( LogService.LOG_DEBUG, "Enabling Component", holder[i].getComponentMetadata(), null );
- holder[i].enableComponents( true );
+ log( LogService.LOG_DEBUG, "Enabling Component", aHolder.getComponentMetadata(), null );
+ aHolder.enableComponents( true );
}
catch ( Throwable t )
{
- log( LogService.LOG_ERROR, "Cannot enable component", holder[i].getComponentMetadata(), t );
+ log( LogService.LOG_ERROR, "Cannot enable component", aHolder.getComponentMetadata(), t );
}
}
}
@@ -425,16 +423,16 @@ public void disableComponent( final String name )
return;
}
- for ( int i = 0; i < holder.length; i++ )
+ for ( ComponentHolder aHolder : holder )
{
try
{
- log( LogService.LOG_DEBUG, "Disabling Component", holder[i].getComponentMetadata(), null );
- holder[i].disableComponents( true );
+ log( LogService.LOG_DEBUG, "Disabling Component", aHolder.getComponentMetadata(), null );
+ aHolder.disableComponents( true );
}
catch ( Throwable t )
{
- log( LogService.LOG_ERROR, "Cannot disable component", holder[i].getComponentMetadata(), t );
+ log( LogService.LOG_ERROR, "Cannot disable component", aHolder.getComponentMetadata(), t );
}
}
}
@@ -460,7 +458,7 @@ public void disableComponent( final String name )
// if all components are selected
if ( name == null )
{
- return ( ComponentHolder[] ) m_managers.toArray( new ComponentHolder[m_managers.size()] );
+ return m_managers.toArray( new ComponentHolder[m_managers.size()] );
}
ComponentHolder componentHolder = m_componentRegistry.getComponentHolder( m_context.getBundle(), name );
View
66 scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
@@ -19,6 +19,7 @@
package org.apache.felix.scr.impl;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
@@ -82,7 +83,7 @@
* @see #registerComponentHolder(String, ComponentHolder)
* @see #unregisterComponentHolder(String)
*/
- private final Map /* <ComponentRegistryKey, Object> */ m_componentHoldersByName;
+ private final Map<ComponentRegistryKey, ComponentHolder> m_componentHoldersByName;
/**
* The map of known components indexed by component configuration pid. The values are
@@ -101,7 +102,7 @@
* @see #unregisterComponentHolder(String)
* @see ConfigurationSupport#configurationEvent(org.osgi.service.cm.ConfigurationEvent)
*/
- private final Map m_componentHoldersByPid;
+ private final Map<String, Set<ComponentHolder>> m_componentHoldersByPid;
/**
* Map of components by component ID. This map indexed by the component
@@ -111,7 +112,7 @@
* @see #registerComponentId(AbstractComponentManager)
* @see #unregisterComponentId(long)
*/
- private final Map m_componentsById;
+ private final Map<Long, AbstractComponentManager> m_componentsById;
/**
* Counter to setup the component IDs as issued by the
@@ -130,7 +131,7 @@
// the ConfigurationAdmin service
private ConfigurationSupport configurationSupport;
- private final Map m_missingDependencies = new HashMap( );
+ private final Map<ServiceReference<?>, List<DependencyManager>> m_missingDependencies = new HashMap<ServiceReference<?>, List<DependencyManager>>( );
protected ComponentRegistry( BundleContext context )
{
@@ -333,27 +334,31 @@ final ComponentRegistryKey checkComponentName( final Bundle bundle, final String
{
// register the name if no registration for that name exists already
final ComponentRegistryKey key = new ComponentRegistryKey( bundle, name );
- final Object existingRegistration;
+ ComponentHolder existingRegistration = null;
+ boolean present;
synchronized ( m_componentHoldersByName )
{
- existingRegistration = m_componentHoldersByName.get( key );
- if ( existingRegistration == null )
+ present = m_componentHoldersByName.containsKey( key );
+ if ( !present )
{
- m_componentHoldersByName.put( key, key );
+ m_componentHoldersByName.put( key, null );
+ }
+ else
+ {
+ existingRegistration = m_componentHoldersByName.get( key );
}
}
// there was a registration already, throw an exception and use the
// existing registration to provide more information if possible
- if ( existingRegistration != null )
+ if ( present )
{
String message = "The component name '" + name + "' has already been registered";
- if ( existingRegistration instanceof ComponentHolder )
+ if ( existingRegistration != null )
{
- ComponentHolder c = ( ComponentHolder ) existingRegistration;
- Bundle cBundle = c.getActivator().getBundleContext().getBundle();
- ComponentMetadata cMeta = c.getComponentMetadata();
+ Bundle cBundle = existingRegistration.getActivator().getBundleContext().getBundle();
+ ComponentMetadata cMeta = existingRegistration.getComponentMetadata();
StringBuffer buf = new StringBuffer( message );
buf.append( " by Bundle " ).append( cBundle.getBundleId() );
@@ -388,7 +393,7 @@ final void registerComponentHolder( final ComponentRegistryKey key, ComponentHol
synchronized ( m_componentHoldersByName )
{
// only register the component if there is a m_registration for it !
- if ( !key.equals( m_componentHoldersByName.get( key ) ) )
+ if ( m_componentHoldersByName.get( key ) != null )
{
// this is not expected if all works ok
throw new ComponentException( "The component name '" + component.getComponentMetadata().getName()
@@ -406,10 +411,10 @@ final void registerComponentHolder( final ComponentRegistryKey key, ComponentHol
// Since several components may refer to the same configuration pid, we have to
// store the component holder in a Set, in order to be able to lookup every
// components from a given pid.
- Set set = (Set) m_componentHoldersByPid.get(configurationPid);
+ Set<ComponentHolder> set = m_componentHoldersByPid.get(configurationPid);
if (set == null)
{
- set = new HashSet();
+ set = new HashSet<ComponentHolder>();
m_componentHoldersByPid.put(configurationPid, set);
}
set.add(component);
@@ -422,7 +427,7 @@ final void registerComponentHolder( final ComponentRegistryKey key, ComponentHol
*/
public final ComponentHolder getComponentHolder( final Bundle bundle, final String name )
{
- Object entry;
+ ComponentHolder entry;
synchronized ( m_componentHoldersByName )
{
entry = m_componentHoldersByName.get( new ComponentRegistryKey( bundle, name ) );
@@ -444,12 +449,12 @@ public final ComponentHolder getComponentHolder( final Bundle bundle, final Stri
* @return a iterator of ComponentHolder, or an empty iterator if no ComponentHolders
* are found
*/
- public final Iterator getComponentHoldersByPid(String pid)
+ public final Iterator<ComponentHolder> getComponentHoldersByPid(String pid)
{
- Set componentHoldersUsingPid = new HashSet();
+ Set<ComponentHolder> componentHoldersUsingPid = new HashSet<ComponentHolder>();
synchronized (m_componentHoldersByPid)
{
- Set set = (Set) m_componentHoldersByPid.get(pid);
+ Set<ComponentHolder> set = m_componentHoldersByPid.get(pid);
// only return the entry if non-null and not a reservation
if (set != null)
{
@@ -465,11 +470,11 @@ public final Iterator getComponentHoldersByPid(String pid)
* name reservations or {@link ComponentHolder} instances for actual
* holders of components.
*/
- private Object[] getComponentHolders()
+ private ComponentHolder[] getComponentHolders()
{
synchronized ( m_componentHoldersByName )
{
- return m_componentHoldersByName.values().toArray();
+ return m_componentHoldersByName.values().toArray( new ComponentHolder[ m_componentHoldersByName.size() ]);
}
}
@@ -494,17 +499,17 @@ final void unregisterComponentHolder( final Bundle bundle, final String name )
*/
final void unregisterComponentHolder( final ComponentRegistryKey key )
{
- Object component;
+ ComponentHolder component;
synchronized ( m_componentHoldersByName )
{
component = m_componentHoldersByName.remove( key );
}
- if (component instanceof ComponentHolder) {
+ if (component != null) {
synchronized (m_componentHoldersByPid)
{
- String configurationPid = ((ComponentHolder) component).getComponentMetadata().getConfigurationPid();
- Set componentsForPid = (Set) m_componentHoldersByPid.get(configurationPid);
+ String configurationPid = component.getComponentMetadata().getConfigurationPid();
+ Set<ComponentHolder> componentsForPid = m_componentHoldersByPid.get(configurationPid);
if (componentsForPid != null)
{
componentsForPid.remove(component);
@@ -655,7 +660,7 @@ private void disposeConfigurationSupport()
public void missingServicePresent( final ServiceReference serviceReference, ComponentActorThread actor )
{
- final List dependencyManagers = ( List ) m_missingDependencies.remove( serviceReference );
+ final List<DependencyManager> dependencyManagers = m_missingDependencies.remove( serviceReference );
if ( dependencyManagers != null )
{
actor.schedule( new Runnable()
@@ -663,9 +668,8 @@ public void missingServicePresent( final ServiceReference serviceReference, Comp
public void run()
{
- for ( Iterator i = dependencyManagers.iterator(); i.hasNext(); )
+ for ( DependencyManager dm : dependencyManagers )
{
- DependencyManager dm = ( DependencyManager ) i.next();
dm.invokeBindMethodLate( serviceReference );
}
}
@@ -680,10 +684,10 @@ public synchronized void registerMissingDependency( DependencyManager dependency
{
return;
}
- List dependencyManagers = ( List ) m_missingDependencies.get( serviceReference );
+ List<DependencyManager> dependencyManagers = m_missingDependencies.get( serviceReference );
if ( dependencyManagers == null )
{
- dependencyManagers = new ArrayList();
+ dependencyManagers = new ArrayList<DependencyManager>();
m_missingDependencies.put( serviceReference, dependencyManagers );
}
dependencyManagers.add( dependencyManager );
View
195 scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
@@ -167,14 +167,14 @@ void list(final String bundleIdentifier, final PrintStream out, final PrintStrea
}
out.println(" Id State Name");
- for (int i = 0; i < components.length; i++)
+ for ( Component component : components )
{
- out.print('[');
- out.print(pad(String.valueOf(components[i].getId()), -4));
- out.print("] [");
- out.print(pad(toStateString(components[i].getState()), 13));
- out.print("] ");
- out.print(components[i].getName());
+ out.print( '[' );
+ out.print( pad( String.valueOf( component.getId() ), -4 ) );
+ out.print( "] [" );
+ out.print( pad( toStateString( component.getState() ), 13 ) );
+ out.print( "] " );
+ out.print( component.getName() );
out.println();
}
}
@@ -187,131 +187,131 @@ void info(final String componentId, PrintStream out, PrintStream err)
return;
}
- for (int j = 0; j < components.length; j++)
+ for ( Component component : components )
{
- Component component = components[j];
- out.print("ID: ");
- out.println(component.getId());
- out.print("Name: ");
- out.println(component.getName());
- out.print("Bundle: ");
- out.println(component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId() + ")");
- out.print("State: ");
- out.println(toStateString(component.getState()));
- out.print("Default State: ");
- out.println(component.isDefaultEnabled() ? "enabled" : "disabled");
- out.print("Activation: ");
- out.println(component.isImmediate() ? "immediate" : "delayed");
+ out.print( "ID: " );
+ out.println( component.getId() );
+ out.print( "Name: " );
+ out.println( component.getName() );
+ out.print( "Bundle: " );
+ out.println( component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId() + ")" );
+ out.print( "State: " );
+ out.println( toStateString( component.getState() ) );
+ out.print( "Default State: " );
+ out.println( component.isDefaultEnabled() ? "enabled" : "disabled" );
+ out.print( "Activation: " );
+ out.println( component.isImmediate() ? "immediate" : "delayed" );
// DS 1.1 new features
- out.print("Configuration Policy: ");
- out.println(component.getConfigurationPolicy());
- out.print("Activate Method: ");
- out.print(component.getActivate());
- if (component.isActivateDeclared())
+ out.print( "Configuration Policy: " );
+ out.println( component.getConfigurationPolicy() );
+ out.print( "Activate Method: " );
+ out.print( component.getActivate() );
+ if ( component.isActivateDeclared() )
{
- out.print(" (declared in the descriptor)");
+ out.print( " (declared in the descriptor)" );
}
out.println();
- out.print("Deactivate Method: ");
- out.print(component.getDeactivate());
- if (component.isDeactivateDeclared())
+ out.print( "Deactivate Method: " );
+ out.print( component.getDeactivate() );
+ if ( component.isDeactivateDeclared() )
{
- out.print(" (declared in the descriptor)");
+ out.print( " (declared in the descriptor)" );
}
out.println();
- out.print("Modified Method: ");
- if (component.getModified() != null)
+ out.print( "Modified Method: " );
+ if ( component.getModified() != null )
{
- out.print(component.getModified());
+ out.print( component.getModified() );
}
else
{
- out.print("-");
+ out.print( "-" );
}
out.println();
- out.print("Configuration Pid: ");
- out.print(component.getConfigurationPid());
- if (component.isConfigurationPidDeclared())
+ out.print( "Configuration Pid: " );
+ out.print( component.getConfigurationPid() );
+ if ( component.isConfigurationPidDeclared() )
{
- out.print(" (declared in the descriptor)");
+ out.print( " (declared in the descriptor)" );
}
out.println();
- if (component.getFactory() != null)
+ if ( component.getFactory() != null )
{
- out.print("Factory: ");
- out.println(component.getFactory());
+ out.print( "Factory: " );
+ out.println( component.getFactory() );
}
String[] services = component.getServices();
- if (services != null)
+ if ( services != null )
{
- out.print("Services: ");
- out.println(services[0]);
- for (int i = 1; i < services.length; i++)
+ out.print( "Services: " );
+ out.println( services[0] );
+ for ( int i = 1; i < services.length; i++ )
{
- out.print(" ");
- out.println(services[i]);
+ out.print( " " );
+ out.println( services[i] );
}
- out.print("Service Type: ");
- out.println(component.isServiceFactory() ? "service factory" : "service");
+ out.print( "Service Type: " );
+ out.println( component.isServiceFactory() ? "service factory" : "service" );
}
Reference[] refs = component.getReferences();
- if (refs != null)
+ if ( refs != null )
{
- for (int i = 0; i < refs.length; i++)
+ for ( Reference ref : refs )
{
- out.print("Reference: ");
- out.println(refs[i].getName());
- out.print(" Satisfied: ");
- out.println(refs[i].isSatisfied() ? "satisfied" : "unsatisfied");
- out.print(" Service Name: ");
- out.println(refs[i].getServiceName());
- if (refs[i].getTarget() != null)
+ out.print( "Reference: " );
+ out.println( ref.getName() );
+ out.print( " Satisfied: " );
+ out.println( ref.isSatisfied() ? "satisfied" : "unsatisfied" );
+ out.print( " Service Name: " );
+ out.println( ref.getServiceName() );
+ if ( ref.getTarget() != null )
{
- out.print(" Target Filter: ");
- out.println(refs[i].getTarget());
+ out.print( " Target Filter: " );
+ out.println( ref.getTarget() );
}
- out.print(" Multiple: ");
- out.println(refs[i].isMultiple() ? "multiple" : "single");
- out.print(" Optional: ");
- out.println(refs[i].isOptional() ? "optional" : "mandatory");
- out.print(" Policy: ");
- out.println(refs[i].isStatic() ? "static" : "dynamic");
- out.print(" Policy option: ");
- out.println(refs[i].isReluctant() ? "reluctant" : "greedy");
- ServiceReference[] serviceRefs = refs[i].getBoundServiceReferences();
- if (serviceRefs != null) {
- out.print(" Bound to:");
- for (int k = 0; k< serviceRefs.length; k++) {
- out.print(" " );
- out.println(serviceRefs[k]);
+ out.print( " Multiple: " );
+ out.println( ref.isMultiple() ? "multiple" : "single" );
+ out.print( " Optional: " );
+ out.println( ref.isOptional() ? "optional" : "mandatory" );
+ out.print( " Policy: " );
+ out.println( ref.isStatic() ? "static" : "dynamic" );
+ out.print( " Policy option: " );
+ out.println( ref.isReluctant() ? "reluctant" : "greedy" );
+ ServiceReference[] serviceRefs = ref.getBoundServiceReferences();
+ if ( serviceRefs != null )
+ {
+ out.print( " Bound to:" );
+ for ( int k = 0; k < serviceRefs.length; k++ )
+ {
+ out.print( " " );
+ out.println( serviceRefs[k] );
}
}
}
}
Dictionary props = component.getProperties();
- if (props != null)
+ if ( props != null )
{
- out.println("Properties:");
- TreeSet keys = new TreeSet(Collections.list(props.keys()));
- for (Iterator ki = keys.iterator(); ki.hasNext();)
+ out.println( "Properties:" );
+ TreeSet keys = new TreeSet( Collections.list( props.keys() ) );
+ for ( Object key : keys )
{
- Object key = ki.next();
- out.print(" ");
- out.print(key);
- out.print(" = ");
+ out.print( " " );
+ out.print( key );
+ out.print( " = " );
- Object prop = props.get(key);
- if (prop.getClass().isArray())
+ Object prop = props.get( key );
+ if ( prop.getClass().isArray() )
{
- prop = Arrays.asList((Object[]) prop);
+ prop = Arrays.asList( ( Object[] ) prop );
}
- out.print(prop);
+ out.print( prop );
out.println();
}
@@ -327,35 +327,34 @@ void change(final String componentIdentifier, PrintStream out, PrintStream err,
return;
}
- for (int i = 0; i < components.length; i++)
+ for ( Component component : components )
{
- Component component = components[i];
- if (component.getState() == Component.STATE_DISPOSED)
+ if ( component.getState() == Component.STATE_DISPOSED )
{
- err.println("Component " + component.getName() + " already disposed, cannot change state");
+ err.println( "Component " + component.getName() + " already disposed, cannot change state" );
}
- else if (enable)
+ else if ( enable )
{
- if (component.getState() == Component.STATE_DISABLED)
+ if ( component.getState() == Component.STATE_DISABLED )
{
component.enable();
- out.println("Component " + component.getName() + " enabled");
+ out.println( "Component " + component.getName() + " enabled" );
}
else
{
- out.println("Component " + component.getName() + " already enabled");
+ out.println( "Component " + component.getName() + " already enabled" );
}
}
else
{
- if (component.getState() != Component.STATE_DISABLED)
+ if ( component.getState() != Component.STATE_DISABLED )
{
component.disable();
- out.println("Component " + component.getName() + " disabled");
+ out.println( "Component " + component.getName() + " disabled" );
}
else
{
- out.println("Component " + component.getName() + " already disabled");
+ out.println( "Component " + component.getName() + " already disabled" );
}
}
}
View
2  scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
@@ -68,7 +68,7 @@
*
* @param pid The PID of the configuration used to configure the component
*/
- void configurationUpdated( String pid, Dictionary props );
+ void configurationUpdated( String pid, Dictionary<String, Object> props );
/**
* Returns all <code>Component</code> instances held by this holder.
View
6 scr/src/main/java/org/apache/felix/scr/impl/helper/MethodResult.java
@@ -41,11 +41,11 @@
/**
* The actual result from the method, which may be <code>null</code>.
*/
- private final Map result;
+ private final Map<String, Object> result;
private final boolean hasResult;
- MethodResult(final boolean hasResult, final Map result)
+ MethodResult(final boolean hasResult, final Map<String, Object> result)
{
this.hasResult = hasResult;
this.result = result;
@@ -56,7 +56,7 @@ public boolean hasResult()
return hasResult;
}
- public Map getResult()
+ public Map<String, Object> getResult()
{
return result;
}
View
173 scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -35,6 +35,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
+import com.sun.xml.internal.rngom.binary.DataExceptPattern;
import org.apache.felix.scr.Component;
import org.apache.felix.scr.Reference;
import org.apache.felix.scr.impl.BundleComponentActivator;
@@ -59,7 +60,7 @@
* implementation object's lifecycle.
*
*/
-public abstract class AbstractComponentManager implements Component, SimpleLogger
+public abstract class AbstractComponentManager<S> implements Component, SimpleLogger
{
// the ID of this component
@@ -76,27 +77,22 @@
private final ComponentMethods m_componentMethods;
// The dependency managers that manage every dependency
- private final List m_dependencyManagers;
+ private final List<DependencyManager> m_dependencyManagers;
private boolean m_dependencyManagersInitialized;
- //<Map<DependencyManager, Map<ServiceReference, RefPair>>>
- private final AtomicReference m_dependencies_map;
+ private final AtomicReference<Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>>> m_dependencies_map;
// A reference to the BundleComponentActivator
private BundleComponentActivator m_activator;
// The ServiceRegistration
- private final AtomicReference m_serviceRegistration;
+ private final AtomicReference<ServiceRegistration<S>> m_serviceRegistration;
private final ReentrantLock m_stateLock;
private long m_timeout = 5000;
-// private Thread lockingThread;
-// private Throwable lockingStackTrace;
-// private ArrayList lockingActivity = new ArrayList( );
-
protected volatile boolean enabled;
protected volatile CountDownLatch enabledLatch;
private final Object enabledLatchLock = new Object();
@@ -125,8 +121,8 @@ protected AbstractComponentManager( BundleComponentActivator activator, Componen
m_dependencyManagers = loadDependencyManagers( metadata );
m_stateLock = new ReentrantLock( true );
- m_dependencies_map = new AtomicReference();
- m_serviceRegistration = new AtomicReference();
+ m_dependencies_map = new AtomicReference<Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>>>();
+ m_serviceRegistration = new AtomicReference<ServiceRegistration<S>>();
// dump component details
if ( isLogEnabled( LogService.LOG_DEBUG ) )
@@ -158,19 +154,12 @@ protected AbstractComponentManager( BundleComponentActivator activator, Componen
final void obtainWriteLock( String source )
{
-// if ( isLogEnabled( LogService.LOG_DEBUG ) )
-// {
-// lockingActivity.add( "obtainWriteLock from: " + source + " readLocks: " + m_stateLock.getReadHoldCount() + " writeLocks: " + m_stateLock.getWriteHoldCount() + " thread: " + Thread.currentThread() + " time: " + System.currentTimeMillis());
-// }
try
{
if (!m_stateLock.tryLock( m_timeout, TimeUnit.MILLISECONDS ) )
{
-// lockingActivity.add( "obtainWriteLock failure from: " + source + " readLocks: " + m_stateLock.getReadHoldCount() + " writeLocks: " + m_stateLock.getWriteHoldCount() + " thread: " + Thread.currentThread() + " time: " + System.currentTimeMillis() + " Could not obtain write lock.");
throw new IllegalStateException( "Could not obtain lock" );
}
-// lockingThread = Thread.currentThread();
-// lockingStackTrace = new Exception("Write lock stack trace for thread: " + lockingThread);
}
catch ( InterruptedException e )
{
@@ -181,13 +170,7 @@ final void obtainWriteLock( String source )
final void releaseWriteLock( String source )
{
-// if ( isLogEnabled( LogService.LOG_DEBUG ) )
-// {
-// lockingActivity.add( "deescalateLock from: " + source + " readLocks: " + m_stateLock.getReadHoldCount() + " writeLocks: " + m_stateLock.getWriteHoldCount() + " thread: " + Thread.currentThread() + " time: " + System.currentTimeMillis());
-// }
m_stateLock.unlock();
-// lockingThread = null;
-// lockingStackTrace = null;
}
final boolean isWriteLocked()
@@ -649,13 +632,13 @@ protected void registerService( String[] provides )
{
synchronized ( m_serviceRegistration )
{
- ServiceRegistration existing = ( ServiceRegistration ) m_serviceRegistration.get();
+ ServiceRegistration existing = m_serviceRegistration.get();
if ( existing == null )
{
log( LogService.LOG_DEBUG, "registering services", null );
// get a copy of the component properties as service properties
- final Dictionary serviceProperties = getServiceProperties();
+ final Dictionary<String, Object> serviceProperties = getServiceProperties();
ServiceRegistration newRegistration = getActivator().getBundleContext().registerService(
provides,
@@ -694,7 +677,7 @@ final void unregisterComponentService()
{
synchronized ( m_serviceRegistration )
{
- ServiceRegistration sr = ( ServiceRegistration ) m_serviceRegistration.get();
+ ServiceRegistration sr = m_serviceRegistration.get();
if ( sr != null && m_serviceRegistration.compareAndSet( sr, null ) )
{
@@ -719,7 +702,7 @@ boolean initDependencyManagers()
{
return true;
}
- Class implementationObjectClass;
+ Class<?> implementationObjectClass;
try
{
implementationObjectClass = getActivator().getBundleContext().getBundle().loadClass(
@@ -732,10 +715,8 @@ boolean initDependencyManagers()
}
m_componentMethods.initComponentMethods( this, m_componentMetadata, implementationObjectClass );
- for (Iterator it = m_dependencyManagers.iterator(); it.hasNext(); )
+ for ( DependencyManager dependencyManager : m_dependencyManagers )
{
- DependencyManager dependencyManager = ( DependencyManager ) it.next();
-
dependencyManager.initBindingMethods( m_componentMethods.getBindMethods( dependencyManager.getName() ) );
}
m_dependencyManagersInitialized = true;
@@ -753,19 +734,17 @@ boolean initDependencyManagers()
*/
protected boolean collectDependencies() throws IllegalStateException
{
- Map old = ( Map ) m_dependencies_map.get();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> old = m_dependencies_map.get();
if ( old != null)
{
log( LogService.LOG_DEBUG, "dependency map already present, do not collect dependencies", null );
return false;
}
initDependencyManagers();
- Map newDeps = new HashMap( );//<DependencyManager, Map<ServiceReference, RefPair>
- for (Iterator it = m_dependencyManagers.iterator(); it.hasNext(); )
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> newDeps = new HashMap<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>>( );
+ for ( DependencyManager dependencyManager : m_dependencyManagers )
{
- DependencyManager dependencyManager = ( DependencyManager ) it.next();
-
- if (!dependencyManager.prebind( newDeps) )
+ if ( !dependencyManager.prebind( newDeps ) )
{
//not actually satisfied any longer
returnServices( newDeps );
@@ -784,7 +763,7 @@ protected boolean collectDependencies() throws IllegalStateException
return true;
}
- protected boolean setDependencyMap( Map old, Map newDeps )
+ protected boolean setDependencyMap( Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> old, Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> newDeps )
{
return m_dependencies_map.compareAndSet( old, newDeps );
}
@@ -794,35 +773,33 @@ protected void unsetDependencyMap()
m_dependencies_map.set( null );
}
- private void returnServices( Map deps )
+ private void returnServices( Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> deps )
{
- for (Iterator it = deps.values().iterator(); it.hasNext(); )
- {
- Map refs = ( Map ) it.next();
- if ( refs != null )
- {
- for (Iterator ri = refs.entrySet().iterator(); ri.hasNext(); )
- {
- Map.Entry entry = ( Map.Entry ) ri.next();
- RefPair args = ( RefPair ) entry.getValue();
- if ( args.getServiceObject() != null )
- {
- getActivator().getBundleContext().ungetService( (ServiceReference) entry.getKey() );
- }
- }
- }
- }
+ for ( Map<ServiceReference<?>, RefPair<?>> refs : deps.values() )
+ {
+ if ( refs != null )
+ {
+ for ( Map.Entry<ServiceReference<?>, RefPair<?>> serviceReferenceRefPairEntry : refs.entrySet() )
+ {
+ RefPair<?> args = serviceReferenceRefPairEntry.getValue();
+ if ( args.getServiceObject() != null )
+ {
+ getActivator().getBundleContext().ungetService( serviceReferenceRefPairEntry.getKey() );
+ }
+ }
+ }
+ }
}
- abstract void update( DependencyManager dependencyManager, ServiceReference ref );
+ abstract <T> void update( DependencyManager<S, T> dependencyManager, ServiceReference<T> ref );
- abstract void invokeBindMethod( DependencyManager dependencyManager, ServiceReference reference );
+ abstract <T> void invokeBindMethod( DependencyManager<S, T> dependencyManager, ServiceReference<T> reference );
- abstract void invokeUnbindMethod( DependencyManager dependencyManager, ServiceReference oldRef );
+ abstract <T> void invokeUnbindMethod( DependencyManager<S, T> dependencyManager, ServiceReference<T> oldRef );
- Map getDependencyMap()
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> getDependencyMap()
{
- return ( Map ) m_dependencies_map.get();
+ return m_dependencies_map.get();
}
//**********************************************************************************************************
@@ -839,9 +816,9 @@ boolean isActivatorActive()
}
- final ServiceRegistration getServiceRegistration()
+ final ServiceRegistration<?> getServiceRegistration()
{
- return ( ServiceRegistration ) m_serviceRegistration.get();
+ return m_serviceRegistration.get();
}
@@ -857,13 +834,6 @@ void clear()
m_dependencyManagers.clear();
}
- //<DependencyManager, Map<ServiceReference, RefPair>>
- protected Map getParameterMap()
- {
- return ( Map ) m_dependencies_map.get();
- }
-
-
/**
* Returns <code>true</code> if logging for the given level is enabled.
*/
@@ -917,13 +887,13 @@ private boolean hasServiceRegistrationPermissions()
if ( services != null && services.length > 0 )
{
final Bundle bundle = getBundle();
- for ( int i = 0; i < services.length; i++ )
+ for ( String service : services )
{
- final Permission perm = new ServicePermission( services[i], ServicePermission.REGISTER );
+ final Permission perm = new ServicePermission( service, ServicePermission.REGISTER );
if ( !bundle.hasPermission( perm ) )
{
log( LogService.LOG_DEBUG, "Permission to register service {0} is denied", new Object[]
- { services[i] }, null );
+ {service}, null );
allowed = false;
}
}
@@ -936,19 +906,15 @@ private boolean hasServiceRegistrationPermissions()
}
- private List loadDependencyManagers( ComponentMetadata metadata )
+ private List<DependencyManager> loadDependencyManagers( ComponentMetadata metadata )
{
- List depMgrList = new ArrayList(metadata.getDependencies().size());
+ List<DependencyManager> depMgrList = new ArrayList<DependencyManager>(metadata.getDependencies().size());
// If this component has got dependencies, create dependency managers for each one of them.
if ( metadata.getDependencies().size() != 0 )
{
- Iterator dependencyit = metadata.getDependencies().iterator();
-
- while ( dependencyit.hasNext() )
+ for ( ReferenceMetadata currentdependency: metadata.getDependencies() )
{
- ReferenceMetadata currentdependency = (ReferenceMetadata) dependencyit.next();
-
DependencyManager depmanager = new DependencyManager( this, currentdependency );
depMgrList.add( depmanager );
@@ -962,10 +928,8 @@ private void enableDependencyManagers() throws InvalidSyntaxException
{
if ( !m_componentMetadata.isConfigurationRequired() )
{
- Iterator it = getDependencyManagers();
- while ( it.hasNext() )
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dm = (DependencyManager) it.next();
dm.enable();
}
}
@@ -973,10 +937,9 @@ private void enableDependencyManagers() throws InvalidSyntaxException
protected void updateTargets(Dictionary properties)
{
- for (Object o: m_dependencyManagers)
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dependencyManager = ( DependencyManager ) o;
- dependencyManager.setTargetFilter( properties );
+ dm.setTargetFilter( properties );
}
}
@@ -985,10 +948,8 @@ protected boolean verifyDependencyManagers( Dictionary properties )
// indicates whether all dependencies are satisfied
boolean satisfied = true;
- Iterator it = getDependencyManagers();
- while ( it.hasNext() )
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dm = ( DependencyManager ) it.next();
if ( !dm.hasGetPermission() )
{
@@ -1023,29 +984,27 @@ else if ( !dm.isSatisfied() )
* Returns an iterator over the {@link DependencyManager} objects
* representing the declared references in declaration order
*/
- Iterator getDependencyManagers()
+ List<DependencyManager> getDependencyManagers()
{
- return m_dependencyManagers.iterator();
+ return m_dependencyManagers;
}
/**
* Returns an iterator over the {@link DependencyManager} objects
* representing the declared references in reversed declaration order
*/
- Iterator getReversedDependencyManagers()
+ List<DependencyManager> getReversedDependencyManagers()
{
List list = new ArrayList( m_dependencyManagers );
Collections.reverse( list );
- return list.iterator();
+ return list;
}
DependencyManager getDependencyManager(String name)
{
- Iterator it = getDependencyManagers();
- while ( it.hasNext() )
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dm = (DependencyManager) it.next();
if ( name.equals(dm.getName()) )
{
return dm;
@@ -1058,29 +1017,25 @@ DependencyManager getDependencyManager(String name)
private void deactivateDependencyManagers()
{
- Iterator it = getDependencyManagers();
- while ( it.hasNext() )
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dm = (DependencyManager) it.next();
dm.deactivate();
}
}
private void disableDependencyManagers()
{
- Iterator it = getDependencyManagers();
- while ( it.hasNext() )
+ for ( DependencyManager dm: getDependencyManagers() )
{
- DependencyManager dm = (DependencyManager) it.next();
dm.unregisterServiceListener();
}
}
public abstract boolean hasConfiguration();
- public abstract Dictionary getProperties();
+ public abstract Dictionary<String, Object> getProperties();
- public abstract void setServiceProperties( Dictionary serviceProperties );
+ public abstract void setServiceProperties( Dictionary<String, Object> serviceProperties );
/**
* Returns the subset of component properties to be used as service
@@ -1088,7 +1043,7 @@ private void disableDependencyManagers()
* name does not start with dot (.), properties which are considered
* private.
*/
- public Dictionary getServiceProperties()
+ public Dictionary<String, Object> getServiceProperties()
{
return copyTo( null, getProperties(), false );
}
@@ -1107,7 +1062,7 @@ public Dictionary getServiceProperties()
* <code>source</code> is <code>null</code> or empty and
* <code>target</code> was <code>null</code>.
*/
- protected static Dictionary copyTo( Dictionary target, Dictionary source )
+ protected static Dictionary<String, Object> copyTo( Dictionary<String, Object> target, Dictionary<String, Object> source )
{
return copyTo( target, source, true );
}
@@ -1131,11 +1086,11 @@ protected static Dictionary copyTo( Dictionary target, Dictionary source )
* <code>target</code> was <code>null</code> or all properties are
* private and had not to be copied
*/
- protected static Dictionary copyTo( Dictionary target, final Dictionary source, final boolean allProps )
+ protected static Dictionary<String, Object> copyTo( Dictionary<String, Object> target, final Dictionary<String, Object> source, final boolean allProps )
{
if ( target == null )
{
- target = new Hashtable();
+ target = new Hashtable<String, Object>();
}
if ( source != null && !source.isEmpty() )
@@ -1187,7 +1142,7 @@ public void setServiceProperties( MethodResult methodResult )
{
if ( methodResult.hasResult() )
{
- Dictionary serviceProps = ( methodResult.getResult() == null) ? null : new Hashtable( methodResult.getResult() );
+ Dictionary<String, Object> serviceProps = ( methodResult.getResult() == null) ? null : new Hashtable<String, Object>( methodResult.getResult() );
setServiceProperties(serviceProps );
}
}
@@ -1239,7 +1194,7 @@ int getState()
}
- ServiceReference getServiceReference( AbstractComponentManager acm )
+ ServiceReference<?> getServiceReference( AbstractComponentManager acm )
{
throw new IllegalStateException("getServiceReference" + this);
}
View
57 scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
@@ -58,7 +58,7 @@
* with earlier releases of the Apache Felix Declarative Services implementation.
* But keep in mind, that this is non-standard behaviour.
*/
-public class ComponentFactoryImpl extends AbstractComponentManager implements ComponentFactory, ComponentHolder
+public class ComponentFactoryImpl<S> extends AbstractComponentManager<S> implements ComponentFactory, ComponentHolder
{
/**
@@ -71,14 +71,14 @@
* entry is the same as the entry's key.
* This is an IdentityHashMap for speed, thus not a Set.
*/
- private final Map m_componentInstances;
+ private final Map<ImmediateComponentManager, ImmediateComponentManager> m_componentInstances;
/**
* The configuration for the component factory. This configuration is
* supplied as the base configuration for each component instance created
* by the {@link #newInstance(Dictionary)} method.
*/
- private volatile Dictionary m_configuration;
+ private volatile Dictionary<String, Object> m_configuration;
/**
* Flag telling if our component factory is configured from config admin.
@@ -90,8 +90,8 @@
public ComponentFactoryImpl( BundleComponentActivator activator, ComponentMetadata metadata )
{
super( activator, metadata, new ComponentMethods() );
- m_componentInstances = new IdentityHashMap();
- m_configuration = new Hashtable();
+ m_componentInstances = new IdentityHashMap<ImmediateComponentManager, ImmediateComponentManager>();
+ m_configuration = new Hashtable<String, Object>();
}
@@ -204,15 +204,14 @@ public boolean hasConfiguration()
}
- public Dictionary getProperties()
+ public Dictionary<String, Object> getProperties()
{
- Dictionary props = getServiceProperties();
+ Dictionary<String, Object> props = getServiceProperties();
// add target properties of references
- List depMetaData = getComponentMetadata().getDependencies();
- for ( Iterator di = depMetaData.iterator(); di.hasNext(); )
+ List<ReferenceMetadata> depMetaData = getComponentMetadata().getDependencies();
+ for ( ReferenceMetadata rm : depMetaData )
{
- ReferenceMetadata rm = ( ReferenceMetadata ) di.next();
if ( rm.getTarget() != null )
{
props.put( rm.getTargetPropertyName(), rm.getTarget() );
@@ -220,9 +219,9 @@ public Dictionary getProperties()
}
// add target properties from configuration (if we have one)
- for ( Object key : Collections.list( m_configuration.keys() ) )
+ for ( String key : Collections.list( m_configuration.keys() ) )
{
- if ( key.toString().endsWith( ".target" ) )
+ if ( key.endsWith( ".target" ) )
{
props.put( key, m_configuration.get( key ) );
}
@@ -237,9 +236,9 @@ public void setServiceProperties( Dictionary serviceProperties )
}
- public Dictionary getServiceProperties()
+ public Dictionary<String, Object> getServiceProperties()
{
- Dictionary props = new Hashtable();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
// 112.5.5 The Component Factory service must register with the following properties
props.put( ComponentConstants.COMPONENT_NAME, getComponentMetadata().getName() );
@@ -268,28 +267,28 @@ State getActiveState()
protected boolean collectDependencies()
{
- Map old = getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> old = getDependencyMap();
if ( old == null )
{
- Map dependenciesMap = new HashMap();
- for (Iterator i = getDependencyManagers(); i.hasNext(); )
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependenciesMap = new HashMap<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>>();
+ for (DependencyManager dm: getDependencyManagers() )
{
- dependenciesMap.put( i.next(), Collections.EMPTY_MAP );
+ dependenciesMap.put( dm, Collections.EMPTY_MAP );
}
setDependencyMap( old, dependenciesMap );
}
return true;
}
- void update( DependencyManager dependencyManager, ServiceReference ref )
+ <T> void update( DependencyManager<S, T> dependencyManager, ServiceReference<T> ref )
{
}
- void invokeBindMethod( DependencyManager dependencyManager, ServiceReference reference )
+ <T> void invokeBindMethod( DependencyManager<S, T> dependencyManager, ServiceReference<T> reference )
{
}
- void invokeUnbindMethod( DependencyManager dependencyManager, ServiceReference oldRef )
+ <T> void invokeUnbindMethod( DependencyManager<S, T> dependencyManager, ServiceReference<T> oldRef )
{
}
@@ -340,7 +339,7 @@ public void configurationDeleted( String pid )
}
- public void configurationUpdated( String pid, Dictionary configuration )
+ public void configurationUpdated( String pid, Dictionary<String, Object> configuration )
{
if ( pid.equals( getComponentMetadata().getConfigurationPid() ) )
{
@@ -399,13 +398,13 @@ public void configurationUpdated( String pid, Dictionary configuration )
public Component[] getComponents()
{
- List cms = getComponentList();
- return (Component[]) cms.toArray( new Component[ cms.size() ] );
+ List<AbstractComponentManager> cms = getComponentList();
+ return cms.toArray( new Component[ cms.size() ] );
}
- protected List getComponentList()
+ protected List<AbstractComponentManager> getComponentList()
{
- List cms = new ArrayList( );
+ List<AbstractComponentManager> cms = new ArrayList<AbstractComponentManager>( );
cms.add( this );
getComponentManagers( m_componentInstances, cms );
return cms;
@@ -440,11 +439,11 @@ public void disableComponents( boolean async )
*/
public void disposeComponents( int reason )
{
- List cms = new ArrayList( );
+ List<AbstractComponentManager> cms = new ArrayList<AbstractComponentManager>( );
getComponentManagers( m_componentInstances, cms );
- for ( Iterator i = cms.iterator(); i.hasNext(); )
+ for ( AbstractComponentManager acm: cms )
{
- ((AbstractComponentManager)i.next()).dispose( reason );
+ acm.dispose( reason );
}
synchronized ( m_componentInstances )
View
10 scr/src/main/java/org/apache/felix/scr/impl/manager/ConfigurationComponentFactoryImpl.java
@@ -48,7 +48,7 @@
* with earlier releases of the Apache Felix Declarative Services implementation.
* But keep in mind, that this is non-standard behaviour.
*/
-public class ConfigurationComponentFactoryImpl extends ComponentFactoryImpl implements ComponentHolder
+public class ConfigurationComponentFactoryImpl<S> extends ComponentFactoryImpl<S> implements ComponentHolder
{
/**
@@ -132,7 +132,7 @@ public void configurationDeleted( String pid )
}
- public void configurationUpdated( String pid, Dictionary configuration )
+ public void configurationUpdated( String pid, Dictionary<String, Object> configuration )
{
if ( pid.equals( getComponentMetadata().getConfigurationPid() ) )
{
@@ -199,11 +199,11 @@ public void disposeComponents( int reason )
{
super.disposeComponents( reason );
- List cms = new ArrayList( );
+ List<AbstractComponentManager> cms = new ArrayList<AbstractComponentManager>( );
getComponentManagers( m_configuredServices, cms );
- for ( Iterator i = cms.iterator(); i.hasNext(); )
+ for ( AbstractComponentManager acm: cms )
{
- ((AbstractComponentManager)i.next()).dispose( reason );
+ acm.dispose( reason );
}
m_configuredServices = null;
View
8 scr/src/main/java/org/apache/felix/scr/impl/manager/DelayedComponentManager.java
@@ -26,7 +26,7 @@
/**
- * The <code>DelayedComponentManager</code> TODO
+ * The <code>DelayedComponentManager</code> marker class. Needed?
*/
public class DelayedComponentManager extends ImmediateComponentManager
{
@@ -42,10 +42,4 @@ public DelayedComponentManager( BundleComponentActivator activator, ComponentHol
super( activator, componentHolder, metadata, componentMethods );
}
-
-// State getSatisfiedState()
-// {
-// return Registered.getInstance();
-// }
-
}
View
182 scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
@@ -53,14 +53,14 @@
* declared by a single <code>&lt;reference&gt;</code element in component
* descriptor.
*/
-public class DependencyManager implements ServiceListener, Reference
+public class DependencyManager<S, T> implements ServiceListener, Reference
{
// mask of states ok to send events
private static final int STATE_MASK = //Component.STATE_UNSATISFIED |
Component.STATE_ACTIVE | Component.STATE_REGISTERED | Component.STATE_FACTORY;
// the component to which this dependency belongs
- private final AbstractComponentManager m_componentManager;
+ private final AbstractComponentManager<S> m_componentManager;
// Reference to the metadata
private final ReferenceMetadata m_dependencyMetadata;
@@ -77,8 +77,8 @@
private volatile Filter m_targetFilter;
private final Object enableLock = new Object();
- private final Collection<ServiceReference> added = new ArrayList<ServiceReference>();
- private final Collection<ServiceReference> removed = new ArrayList<ServiceReference>();
+ private final Collection<ServiceReference<T>> added = new ArrayList<ServiceReference<T>>();
+ private final Collection<ServiceReference<T>> removed = new ArrayList<ServiceReference<T>>();
private boolean registered;
@@ -88,7 +88,7 @@
*
* @param dependency An object that contains data about the dependency
*/
- DependencyManager( AbstractComponentManager componentManager, ReferenceMetadata dependency )
+ DependencyManager( AbstractComponentManager<S> componentManager, ReferenceMetadata dependency )
{
m_componentManager = componentManager;
m_dependencyMetadata = dependency;
@@ -124,10 +124,10 @@ void initBindingMethods(BindMethods bindMethods)
*/
public void serviceChanged( ServiceEvent event )
{
- final ServiceReference ref = event.getServiceReference();
+ final ServiceReference<T> ref = ( ServiceReference<T> ) event.getServiceReference();
final String serviceString = "Service " + m_dependencyMetadata.getInterface() + "/"
+ ref.getProperty( Constants.SERVICE_ID );
- Collection<ServiceReference> changes = null;
+ Collection<ServiceReference<T>> changes = null;
try
{
switch ( event.getType() )
@@ -318,7 +318,7 @@ else if ( !targetFilterMatch( ref ) )
* @param reference The reference to the service newly registered or
* modified.
*/
- private void serviceAdded( ServiceReference reference )
+ private void serviceAdded( ServiceReference<T> reference )
{
// if the component is currently unsatisfied, it may become satisfied
// by adding this service, try to activate (also schedule activation
@@ -337,10 +337,10 @@ private void serviceAdded( ServiceReference reference )
"Dependency Manager: Service {0} activation did not occur on this thread", new Object[]
{ m_dependencyMetadata.getName() }, null );
- Map dependenciesMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependenciesMap = m_componentManager.getDependencyMap();
if (dependenciesMap != null) {
//someone else has managed to activate
- Map references = ( Map ) dependenciesMap.get( this );
+ Map<ServiceReference<T>, RefPair<T>> references = (Map)dependenciesMap.get( this );
if (references == null )
{
throw new IllegalStateException( "Allegedly active but dependency manager not represented: " + this );
@@ -380,10 +380,10 @@ private void serviceAdded( ServiceReference reference )
}
else
{
- Map dependenciesMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependenciesMap = m_componentManager.getDependencyMap();
if ( dependenciesMap != null )
{
- Map bound = ( Map ) dependenciesMap.get( this );
+ Map<ServiceReference<T>, RefPair<T>> bound = (Map)dependenciesMap.get( this );
if ( m_dependencyMetadata.isMultiple() ||
bound.isEmpty() ||
reference.compareTo( bound.keySet().iterator().next() ) > 0 )
@@ -408,11 +408,11 @@ else if ( m_dependencyMetadata.getBind() != null )
else if ( !isReluctant() )
{
//dynamic greedy single: bind then unbind
- Map dependenciesMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependenciesMap = m_componentManager.getDependencyMap();
if ( dependenciesMap != null )
{
- Map bound = ( Map ) dependenciesMap.get( this );
- ServiceReference oldRef = ( ServiceReference ) bound.keySet().iterator().next();
+ Map<ServiceReference<T>, RefPair<T>> bound = (Map)dependenciesMap.get( this );
+ ServiceReference oldRef = bound.keySet().iterator().next();
if ( reference.compareTo( oldRef ) > 0 )
{
m_componentManager.invokeBindMethod( this, reference );
@@ -444,7 +444,7 @@ else if ( !isReluctant() )
* @param reference The reference to the service unregistering or being
* modified.
*/
- private void serviceRemoved( ServiceReference reference )
+ private void serviceRemoved( ServiceReference<T> reference )
{
// if the dependency is not satisfied anymore, we have to
// deactivate the component
@@ -470,11 +470,11 @@ private void serviceRemoved( ServiceReference reference )
// otherwise check whether the component is in a state to handle the event
else if ( handleServiceEvent() || (m_componentManager.getState() & (Component.STATE_DISABLED | Component.STATE_DISPOSED)) != 0 )
{
- Map dependencyMap = m_componentManager.getDependencyMap();
- Map referenceMap = null;
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependencyMap = m_componentManager.getDependencyMap();
+ Map<ServiceReference<T>, RefPair<T>> referenceMap = null;
if (dependencyMap != null)
{
- referenceMap = ( Map ) dependencyMap.get( this );
+ referenceMap = (Map)dependencyMap.get( this );
}
// if the dependency is static, we have to deactivate the component
// to "remove" the dependency
@@ -511,7 +511,7 @@ else if ( handleServiceEvent() || (m_componentManager.getState() & (Component.ST
// if the dependency is mandatory and no replacement is
// available, bind returns false and we deactivate
// bind best matching service
- ServiceReference ref = getFrameworkServiceReference();
+ ServiceReference<T> ref = getFrameworkServiceReference();
if ( ref == null )
{
@@ -652,12 +652,12 @@ void deactivate()
// unget all services we once got
if ( m_componentManager.getDependencyMap() != null )
{
- ServiceReference[] boundRefs = getBoundServiceReferences();
+ ServiceReference<T>[] boundRefs = getBoundServiceReferences();
if ( boundRefs != null )
{
- for ( int i = 0; i < boundRefs.length; i++ )
+ for ( ServiceReference<T> ref: boundRefs )
{
- ungetService( boundRefs[i] );
+ ungetService( ref );
}
}
}
@@ -691,13 +691,13 @@ int size()
* This method always directly accesses the framework's service registry
* and ignores the services bound by this dependency manager.
*/
- ServiceReference[] getFrameworkServiceReferences()
+ ServiceReference<T>[] getFrameworkServiceReferences()
{
return getFrameworkServiceReferences( getTarget() );
}
- private ServiceReference[] getFrameworkServiceReferences( String targetFilter )
+ private ServiceReference<T>[] getFrameworkServiceReferences( String targetFilter )
{
if ( hasGetPermission() )
{
@@ -717,7 +717,7 @@ int size()
try
{
- return bc.getServiceReferences(
+ return ( ServiceReference<T>[] ) bc.getServiceReferences(
m_dependencyMetadata.getInterface(), targetFilter );
}
catch ( IllegalStateException ise )
@@ -738,7 +738,7 @@ int size()
private int getServiceReferenceCount()
{
- ServiceReference[] refs = getFrameworkServiceReferences();
+ ServiceReference<T>[] refs = getFrameworkServiceReferences();
return refs == null? 0: refs.length;
}
@@ -757,10 +757,10 @@ private int getServiceReferenceCount()
* This method always directly accesses the framework's service registry
* and ignores the services bound by this dependency manager.
*/
- ServiceReference getFrameworkServiceReference()
+ ServiceReference<T> getFrameworkServiceReference()
{
// get the framework registered services and short cut
- ServiceReference[] refs = getFrameworkServiceReferences();
+ ServiceReference<T>[] refs = getFrameworkServiceReferences();
if ( refs == null )
{
return null;
@@ -772,10 +772,10 @@ else if ( refs.length == 1 )
// find the service with the highest ranking
- ServiceReference selectedRef = refs[0];
+ ServiceReference<T> selectedRef = refs[0];
for ( int i = 1; i < refs.length; i++ )
{
- ServiceReference ref = refs[i];
+ ServiceReference<T> ref = refs[i];
if ( ref.compareTo( selectedRef ) > 0 )
{
selectedRef = ref;
@@ -792,9 +792,9 @@ else if ( refs.length == 1 )
* non-<code>null</code> service instance the service is then considered
* bound to this instance.
*/
- Object getService()
+ T getService()
{
- ServiceReference sr = getFrameworkServiceReference();
+ ServiceReference<T> sr = getFrameworkServiceReference();
return ( sr != null ) ? getService( sr ) : null;
}
@@ -806,25 +806,25 @@ Object getService()
* returned. All services returned by this method will be considered bound
* after this method returns.
*/
- Object[] getServices()
+ T[] getServices()
{
- ServiceReference[] sr = getFrameworkServiceReferences();
+ ServiceReference<T>[] sr = getFrameworkServiceReferences();
if ( sr == null || sr.length == 0 )
{
return null;
}
- List services = new ArrayList();
- for ( int i = 0; i < sr.length; i++ )
+ List<Object> services = new ArrayList<Object>();
+ for ( ServiceReference<T> ref: sr )
{
- Object service = getService( sr[i] );
+ Object service = getService( ref );
if ( service != null )
{
services.add( service );
}
}
- return ( services.size() > 0 ) ? services.toArray() : null;
+ return ( services.size() > 0 ) ? services.toArray((T[])new Object[services.size()]) : null;
}
@@ -835,20 +835,20 @@ Object getService()
* services this instance is bound to or <code>null</code> if no services
* are actually bound.
*/
- public ServiceReference[] getBoundServiceReferences()
+ public ServiceReference<T>[] getBoundServiceReferences()
{
- Map dependencyMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependencyMap = m_componentManager.getDependencyMap();
if ( dependencyMap == null )
{
return null;
}
- Map bound = ( Map ) dependencyMap.get( this );
+ Map<ServiceReference<T>, RefPair<T>> bound = (Map)dependencyMap.get( this );
if ( bound.isEmpty() )
{
return null;
}
- return ( ServiceReference[] ) bound.keySet().toArray( new ServiceReference[bound.size()] );
+ return bound.keySet().toArray( new ServiceReference[bound.size()] );
}
@@ -857,12 +857,12 @@ Object getService()
*/
private boolean isBound()
{
- Map dependencyMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependencyMap = m_componentManager.getDependencyMap();
if (dependencyMap == null )
{
return false;
}
- Map bound = ( Map ) dependencyMap.get( this );
+ Map<ServiceReference<T>, RefPair<T>> bound = (Map)dependencyMap.get( this );
return !bound.isEmpty();
}
@@ -878,14 +878,14 @@ private boolean isBound()
* if the service is bound or <code>null</code> if the service is not
* bound.
*/
- private RefPair getBoundService( ServiceReference serviceReference )
+ private RefPair getBoundService( ServiceReference<T> serviceReference )
{
- Map dependencyMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependencyMap = m_componentManager.getDependencyMap();
if (dependencyMap == null)
{
return null;
}
- return ( RefPair ) (( Map ) dependencyMap.get( this )).get(serviceReference);
+ return dependencyMap.get( this ).get( serviceReference );
}
@@ -900,15 +900,15 @@ private RefPair getBoundService( ServiceReference serviceReference )
* @return The requested service or <code>null</code> if no service is
* registered for the service reference (any more).
*/
- Object getService( ServiceReference serviceReference )
+ T getService( ServiceReference<T> serviceReference )
{
// check whether we already have the service and return that one
RefPair refPair = getBoundService( serviceReference );
if ( refPair != null && refPair.getServiceObject() != null )
{
- return refPair.getServiceObject();
+ return (T)refPair.getServiceObject();
}
- Object serviceObject = null;
+ T serviceObject = null;
// otherwise acquire the service
try
{
@@ -936,7 +936,7 @@ Object getService( ServiceReference serviceReference )
{
refPair = new RefPair( serviceReference );
refPair.setServiceObject( serviceObject );
- ((Map)m_componentManager.getDependencyMap().get( this )).put( serviceReference, refPair );
+ m_componentManager.getDependencyMap().get( this ).put( serviceReference, refPair );
}
}
@@ -949,13 +949,13 @@ Object getService( ServiceReference serviceReference )
* Ungets the service described by the ServiceReference and removes it from
* the list of bound services.
*/
- void ungetService( ServiceReference serviceReference )
+ void ungetService( ServiceReference<T> serviceReference )
{
// check we really have this service, do nothing if not
- Map dependencyMap = m_componentManager.getDependencyMap();
+ Map<DependencyManager<S, ?>, Map<ServiceReference<?>, RefPair<?>>> dependencyMap = m_componentManager.getDependencyMap();
if ( dependencyMap != null )
{
- RefPair refPair = ( RefPair ) ((Map ) dependencyMap.get( this )).get( serviceReference );
+ RefPair refPair = dependencyMap.get( this ).get( serviceReference );
if ( refPair != null && refPair.getServiceObject() != null )
{
BundleComponentActivator activator = m_componentManager.getActivator();
@@ -1023,9 +1023,9 @@ public boolean hasGetPermission()
}
- boolean open( Object componentInstance, Map parameters )
+ boolean open( S componentInstance, Map<ServiceReference<?>, RefPair<?>> parameters )
{
- return bind( componentInstance, parameters);
+ return bind( componentInstance, (Map)parameters);
}
@@ -1034,13 +1034,12 @@ boolean open( Object componentInstance, Map parameters )
* try to complete all that it can
* @param componentInstance
*/
- void close( Object componentInstance )
+ void close( S componentInstance )
{
unbind( componentInstance, getBoundServiceReferences() );
}
- //returns Map<ServiceReference, RefPair>
- boolean prebind( Map dependencyMap)
+ boolean prebind( Map<DependencyManager<S, T>, Map<ServiceReference<T>, RefPair<T>>> dependencyMap)
{
// If no references were received, we have to check if the dependency
// is optional, if it is not then the dependency is invalid
@@ -1053,11 +1052,11 @@ boolean prebind( Map dependencyMap)
// we have nothing to do and just signal success
if ( m_dependencyMetadata.getBind() == null )
{
- dependencyMap.put( this, new HashMap( ) );
+ dependencyMap.put( this, new HashMap<ServiceReference<T>, RefPair<T>>( ) );
return true;
}
- Map result = new HashMap(); //<ServiceReference, RefPair>
+ Map<ServiceReference<T>, RefPair<T>> result = new HashMap<ServiceReference<T>, RefPair<T>>();
// assume success to begin with: if the dependency is optional,
// we don't care, whether we can bind a service. Otherwise, we
// require at least one service to be bound, thus we require
@@ -1068,22 +1067,22 @@ boolean prebind( Map dependencyMap)
if ( m_dependencyMetadata.isMultiple() )
{
// bind all registered services
- ServiceReference[] refs = getFrameworkServiceReferences();
+ ServiceReference<T>[] refs = getFrameworkServiceReferences();
if ( refs != null )
{
- for ( int index = 0; index < refs.length; index++ )
+ for ( ServiceReference<T> ref : refs )
{
- RefPair refPair = new RefPair( refs[index] );
+ RefPair refPair = new RefPair( ref );
// success is if we have the minimal required number of services bound
if ( m_bindMethods.getBind().getServiceObject( refPair, m_componentManager.getActivator().getBundleContext() ) )
{
- result.put( refs[index], refPair );
+ result.put( ref, refPair );
// of course, we have success if the service is bound
success = true;
}
else
{
- m_componentManager.getActivator().registerMissingDependency(this, refs[index]);
+ m_componentManager.getActivator().registerMissingDependency( this, ref );
}
}
}
@@ -1123,7 +1122,7 @@ else if ( isOptional() )
* @return true if the dependency is satisfied and at least the minimum
* number of services could be bound. Otherwise false is returned.
*/
- private boolean bind( Object componentInstance, Map parameters )
+ private boolean bind( S componentInstance, Map<ServiceReference<T>, RefPair<T>> parameters )
{
// If no references were received, we have to check if the dependency
// is optional, if it is not then the dependency is invalid
@@ -1150,11 +1149,10 @@ private boolean bind( Object componentInstance, Map parameters )
m_componentManager.log( LogService.LOG_DEBUG,
"For dependency {0}, optional: {1}; to bind: {2}",
- new Object[]{ m_dependencyMetadata.getName(), new Boolean( success ), parameters }, null );
- for ( Iterator i = parameters.entrySet().iterator(); i.hasNext(); )
+ new Object[]{ m_dependencyMetadata.getName(), success, parameters }, null );
+ for ( Map.Entry<ServiceReference<T>, RefPair<T>> entry : parameters.entrySet() )
{
- Map.Entry entry = ( Map.Entry ) i.next();
- if ( !invokeBindMethod( componentInstance, ( RefPair ) entry.getValue() ) )
+ if ( !invokeBindMethod( componentInstance, entry.getValue() ) )
{
m_componentManager.log( LogService.LOG_DEBUG,
"For dependency {0}, failed to invoke bind method on object {1}",
@@ -1177,7 +1175,7 @@ private boolean bind( Object componentInstance, Map parameters )
* @param componentInstance
* @param ref The <code>ServiceReference</code> representing the updated
*/
- void update( Object componentInstance, final ServiceReference ref )
+ void update( S componentInstance, final ServiceReference<T> ref )
{
if ( m_dependencyMetadata.getUpdated() != null )
{
@@ -1190,7 +1188,7 @@ void update( Object componentInstance, final ServiceReference ref )
* Revoke the given bindings. This method cannot throw an exception since
* it must try to complete all that it can
*/
- private void unbind( Object componentInstance, ServiceReference[] boundRefs )
+ private void unbind( S componentInstance, ServiceReference<T>[] boundRefs )
{
if ( boundRefs != null )
{
@@ -1198,28 +1196,28 @@ private void unbind( Object componentInstance, ServiceReference[] boundRefs )
// in the delayed component situation) and the unbind method is declared.
boolean doUnbind = componentInstance != null && m_dependencyMetadata.getUnbind() != null;