You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2015/09/14 21:08:36 UTC
svn commit: r1703031 - in
/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl:
ScrCommand.java manager/DependencyManager.java
Author: pderop
Date: Mon Sep 14 19:08:36 2015
New Revision: 1703031
URL: http://svn.apache.org/r1703031
Log:
Adapted to latest scr version from felix-trunk.
Modified:
felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/ScrCommand.java
felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java
Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/ScrCommand.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/ScrCommand.java?rev=1703031&r1=1703030&r2=1703031&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/ScrCommand.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/ScrCommand.java Mon Sep 14 19:08:36 2015
@@ -56,6 +56,41 @@ import org.osgi.service.component.runtim
public class ScrCommand implements ScrInfo
{
+ private static final Comparator<ComponentDescriptionDTO> DESCRIPTION_COMP = new Comparator<ComponentDescriptionDTO>()
+ {
+ public int compare(final ComponentDescriptionDTO c1, final ComponentDescriptionDTO c2)
+ {
+ final long bundleId1 = c1.bundle.id;
+ final long bundleId2 = c2.bundle.id;
+ int result = Long.signum(bundleId1 - bundleId2);
+ if ( result == 0)
+ {
+ // sanity check
+ if ( c1.name == null )
+ {
+ result = ( c2.name == null ? 0 : -1);
+ }
+ else if ( c2.name == null )
+ {
+ result = 1;
+ }
+ else
+ {
+ result = c1.name.compareTo(c2.name);
+ }
+ }
+ return result;
+ }
+ };
+
+ private static final Comparator<ComponentConfigurationDTO> CONFIGURATION_COMP = new Comparator<ComponentConfigurationDTO>()
+ {
+ public int compare(final ComponentConfigurationDTO c1, final ComponentConfigurationDTO c2)
+ {
+ return Long.signum(c1.id - c2.id);
+ }
+ };
+
private final BundleContext bundleContext;
private final ServiceComponentRuntime scrService;
private final ScrConfiguration scrConfiguration;
@@ -85,27 +120,17 @@ public class ScrCommand implements ScrIn
{
/*
* Register the Gogo Command as a service of its own class.
- * Due to a race condition during project building (this class is
- * compiled for Java 1.3 compatibility before the required
- * ScrGogoCommand class compiled for Java 5 compatibility) this uses
- * reflection to load and instantiate the class. Any failure during this
- * process is just ignored.
*/
try
{
- final String scrGogoCommandClassName = "org.apache.felix.scr.impl.ScrGogoCommand";
- final Class<?> scrGogoCommandClass = scrService.getClass().getClassLoader().loadClass(scrGogoCommandClassName);
- final Constructor c = scrGogoCommandClass.getConstructor(new Class[]
- { ScrCommand.class });
- final Object gogoCmd = c.newInstance(new Object[]
- { this });
+ final ScrGogoCommand gogoCmd = new ScrGogoCommand(this);
final Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("osgi.command.scope", "scr");
props.put("osgi.command.function", new String[]
{ "config", "disable", "enable", "info", "list" });
props.put(Constants.SERVICE_DESCRIPTION, "SCR Gogo Shell Support");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
- gogoReg = bundleContext.registerService(scrGogoCommandClassName, gogoCmd, props);
+ gogoReg = bundleContext.registerService(ScrGogoCommand.class, gogoCmd, props);
}
catch (Throwable t)
{
@@ -175,7 +200,7 @@ public class ScrCommand implements ScrIn
*/
public void list(final String bundleIdentifier, final PrintWriter out)
{
- List<ComponentConfigurationDTO> components;
+ final List<ComponentDescriptionDTO> descriptions = new ArrayList<ComponentDescriptionDTO>();
if (bundleIdentifier != null)
{
@@ -205,12 +230,8 @@ public class ScrCommand implements ScrIn
}
if (ComponentRegistry.isBundleActive(bundle))
{
- components = new ArrayList<ComponentConfigurationDTO>();
- for(final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs(bundle))
- {
- components.addAll(scrService.getComponentConfigurationDTOs(cmp));
- }
- if (components.isEmpty())
+ descriptions.addAll(scrService.getComponentDescriptionDTOs(bundle));
+ if (descriptions.isEmpty())
{
out.println("Bundle " + bundleIdentifier + " declares no components");
return;
@@ -224,32 +245,41 @@ public class ScrCommand implements ScrIn
}
else
{
- components = new ArrayList<ComponentConfigurationDTO>();
- for(final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs())
- {
- components.addAll(scrService.getComponentConfigurationDTOs(cmp));
- }
- if (components.isEmpty())
+ descriptions.addAll(scrService.getComponentDescriptionDTOs());
+ if (descriptions.isEmpty())
{
out.println("No components registered");
return;
}
}
- Collections.sort( components, new Comparator<ComponentConfigurationDTO>()
- {
-
- public int compare(final ComponentConfigurationDTO c1, final ComponentConfigurationDTO c2)
- {
- return Long.signum(c1.id - c2.id);
- }
-
- });
+ Collections.sort( descriptions, DESCRIPTION_COMP);
- out.println(" Id State BundleId Name");
- for ( final ComponentConfigurationDTO component : components )
- {
- out.println( String.format( "[%1$4d] [%2$s] [%3$4d] %4$s", component.id, toStateString( component.state ), component.description.bundle.id, component.description.name ) );
+ out.println(" BundleId Component Name Default State");
+ out.println(" Component Id State PIDs (Factory PID)");
+ for(final ComponentDescriptionDTO desc : descriptions)
+ {
+ out.println( String.format( " [%1$4d] %2$s %3$s", desc.bundle.id, desc.name, desc.defaultEnabled ? "enabled" : "disabled" ) );
+ final List<ComponentConfigurationDTO> configs = new ArrayList<ComponentConfigurationDTO>(this.scrService.getComponentConfigurationDTOs(desc));
+ Collections.sort( configs, CONFIGURATION_COMP);
+ for ( final ComponentConfigurationDTO component : configs )
+ {
+ final Object servicePid = component.properties.get(Constants.SERVICE_PID);
+ final String factoryPid = (String)component.properties.get("service.factoryPid");
+
+ final StringBuilder pid = new StringBuilder();
+ if ( servicePid != null ) {
+ pid.append(servicePid);
+ }
+ if ( factoryPid != null ) {
+ pid.append(" (");
+ pid.append(factoryPid);
+ pid.append(" )");
+ }
+ out.println( String.format( " [%1$4d] [%2$s] %3$s", component.id,
+ toStateString( component.state ),
+ pid.toString()) );
+ }
}
out.flush();
}
@@ -265,22 +295,7 @@ public class ScrCommand implements ScrIn
return;
}
- Collections.sort( new ArrayList<ComponentDescriptionDTO>(result.components), new Comparator<ComponentDescriptionDTO>()
- {
-
- public int compare(final ComponentDescriptionDTO c1, final ComponentDescriptionDTO c2)
- {
- final long bundleId1 = c1.bundle.id;
- final long bundleId2 = c2.bundle.id;
- int result = Long.signum(bundleId1 - bundleId2);
- if ( result == 0)
- {
- result = c1.name.compareTo(c2.name);
- }
- return result;
- }
-
- });
+ Collections.sort( result.components, DESCRIPTION_COMP );
long bundleId = -1;
@@ -291,7 +306,6 @@ public class ScrCommand implements ScrIn
if ( bundleId != -1 )
{
out.println();
- out.println();
}
bundleId = component.bundle.id;
out.println(String.format("*** Bundle: %1$s (%2$d)", component.bundle.symbolicName, bundleId));
@@ -337,7 +351,7 @@ public class ScrCommand implements ScrIn
String[] services = component.serviceInterfaces;
if ( services != null )
{
- out.print( " Services: " );
+ out.println( " Services: " );
for ( String service: services )
{
out.print( " " );
@@ -386,6 +400,7 @@ public class ScrCommand implements ScrIn
info(cc, out);
}
}
+ out.println();
}
out.flush();
@@ -442,7 +457,7 @@ public class ScrCommand implements ScrIn
out.print( " Target: " );
out.println( ref.target );
ServiceReferenceDTO[] serviceRefs = ref.boundServices;
- if ( serviceRefs != null )
+ if ( serviceRefs.length > 0 )
{
out.print( " Bound to:" );
for ( ServiceReferenceDTO sr: serviceRefs )
@@ -465,7 +480,7 @@ public class ScrCommand implements ScrIn
out.print( " Target: " );
out.println( ref.target );
ServiceReferenceDTO[] serviceRefs = ref.targetServices;
- if ( serviceRefs != null )
+ if ( serviceRefs.length > 0 )
{
out.print( " Target services:" );
for ( ServiceReferenceDTO sr: serviceRefs )
@@ -476,7 +491,7 @@ public class ScrCommand implements ScrIn
}
else
{
- out.println( " (unbound)" );
+ out.println( " (no target services)" );
}
}
@@ -558,7 +573,7 @@ public class ScrCommand implements ScrIn
}
private static final class Result {
- public Collection<ComponentDescriptionDTO> components = new ArrayList<ComponentDescriptionDTO>();
+ public List<ComponentDescriptionDTO> components = new ArrayList<ComponentDescriptionDTO>();
public ComponentConfigurationDTO configuration;
}
Modified: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=1703031&r1=1703030&r2=1703031&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java (original)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/src/org/apache/felix/scr/impl/manager/DependencyManager.java Mon Sep 14 19:08:36 2015
@@ -383,6 +383,7 @@ public class DependencyManager<S, T> imp
int serviceCount = 0;
AtomicInteger trackingCount = new AtomicInteger( );
SortedMap<ServiceReference<T>, RefPair<S, T>> tracked = getTracker().getTracked( true, trackingCount );
+ List<RefPair<S,T>> failed = new ArrayList<RefPair<S, T>>();
for (RefPair<S, T> refPair: tracked.values())
{
if (getServiceObject( key, m_bindMethods.getBind(), refPair ))
@@ -391,10 +392,18 @@ public class DependencyManager<S, T> imp
}
else
{
- m_componentManager.registerMissingDependency( DependencyManager.this, refPair.getRef(), trackingCount.get() );
+ failed.add(refPair);
}
}
- return cardinalitySatisfied( serviceCount );
+ if ( cardinalitySatisfied( serviceCount ) )
+ {
+ for ( RefPair<S, T> refPair: failed)
+ {
+ m_componentManager.registerMissingDependency( DependencyManager.this, refPair.getRef(), trackingCount.get() );
+ }
+ return true;
+ }
+ return false;
}
public void close()
@@ -522,11 +531,6 @@ public class DependencyManager<S, T> imp
{
serviceCount++;
}
- else
- {
- m_componentManager.registerMissingDependency( DependencyManager.this, refPair.getRef(),
- trackingCount.get() );
- }
}
return cardinalitySatisfied( serviceCount );
}
@@ -734,7 +738,7 @@ public class DependencyManager<S, T> imp
closeRefPair();
}
}
- else
+ else if ( cardinalitySatisfied( 0 ) )
{
m_componentManager.registerMissingDependency( DependencyManager.this, serviceReference,
trackingCount );
@@ -866,7 +870,7 @@ public class DependencyManager<S, T> imp
if (refPair != null)
{
success |= getServiceObject( key, m_bindMethods.getBind(), refPair );
- if ( refPair.isFailed() )
+ if ( refPair.isFailed() && cardinalitySatisfied( 0 ))
{
m_componentManager.registerMissingDependency( DependencyManager.this, refPair.getRef(),
trackingCount.get() );
@@ -1561,6 +1565,9 @@ public class DependencyManager<S, T> imp
}
//TODO dynamic reluctant
RefPair<S, T> refPair = m_tracker.getService( ref );
+ if (refPair == null) {
+ return; // The service is no longer available, probably because the tracker has been closed
+ }
//TODO this check is no longer correct, fix it!
// if (refPair.getServiceObject(key) != null)
// {