You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/10/27 07:19:50 UTC
svn commit: r1813478 [2/2] - in /felix/trunk/osgi-r7/scr/src:
main/java/org/apache/felix/scr/impl/inject/
main/java/org/apache/felix/scr/impl/inject/field/
main/java/org/apache/felix/scr/impl/inject/methods/
main/java/org/apache/felix/scr/impl/logger/ ...
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java Fri Oct 27 07:19:49 2017
@@ -218,11 +218,10 @@ public abstract class AbstractComponentM
final long getLockTimeout()
{
- ComponentActivator activator = getActivator();
//for tests....
- if (activator != null && activator.getConfiguration() != null)
+ if (m_container.getActivator().getConfiguration() != null)
{
- return activator.getConfiguration().lockTimeout();
+ return m_container.getActivator().getConfiguration().lockTimeout();
}
return ScrConfiguration.DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
}
@@ -401,22 +400,14 @@ public abstract class AbstractComponentM
void registerComponentId()
{
- final ComponentActivator activator = getActivator();
- if (activator != null)
- {
- this.m_componentId = activator.registerComponentId(this);
- }
+ this.m_componentId = m_container.getActivator().registerComponentId(this);
}
void unregisterComponentId()
{
if (this.m_componentId >= 0)
{
- final ComponentActivator activator = getActivator();
- if (activator != null)
- {
- activator.unregisterComponentId(this);
- }
+ m_container.getActivator().unregisterComponentId(this);
this.m_componentId = -1;
}
}
@@ -446,7 +437,7 @@ public abstract class AbstractComponentM
if (async)
{
final Deferred<Void> latch = enableLatch;
- getActivator().schedule(new Runnable()
+ m_container.getActivator().schedule(new Runnable()
{
long count = taskCounter.incrementAndGet();
@@ -538,7 +529,7 @@ public abstract class AbstractComponentM
if (async)
{
final Deferred<Void> latch = enableLatch;
- getActivator().schedule(new Runnable()
+ m_container.getActivator().schedule(new Runnable()
{
long count = taskCounter.incrementAndGet();
@@ -589,11 +580,7 @@ public abstract class AbstractComponentM
<T> void registerMissingDependency(DependencyManager<S, T> dm, ServiceReference<T> ref, int trackingCount)
{
- ComponentActivator activator = getActivator();
- if (activator != null)
- {
- activator.registerMissingDependency(dm, ref, trackingCount);
- }
+ m_container.getActivator().registerMissingDependency(dm, ref, trackingCount);
}
//---------- Component interface ------------------------------------------
@@ -634,12 +621,7 @@ public abstract class AbstractComponentM
BundleContext getBundleContext()
{
- final ComponentActivator activator = getActivator();
- if (activator != null)
- {
- return activator.getBundleContext();
- }
- return null;
+ return m_container.getActivator().getBundleContext();
}
protected boolean isImmediate()
@@ -662,7 +644,7 @@ public abstract class AbstractComponentM
{
throw new IllegalStateException("enable: " + this);
}
- if (!isActivatorActive())
+ if (!m_container.getActivator().isActive())
{
log(LogService.LOG_DEBUG, "Bundle's component activator is not active; not enabling component", null);
return;
@@ -702,7 +684,7 @@ public abstract class AbstractComponentM
log(LogService.LOG_DEBUG, "Component is not enabled; not activating component", null);
return;
}
- if (!isActivatorActive())
+ if (!m_container.getActivator().isActive())
{
log(LogService.LOG_DEBUG, "Bundle's component activator is not active; not activating component", null);
return;
@@ -757,14 +739,14 @@ public abstract class AbstractComponentM
ServiceRegistration<S> serviceRegistration = registrationManager.getServiceRegistration();
if ( serviceRegistration != null )
{
- getActivator().enterCreate( serviceRegistration.getReference() );
+ m_container.getActivator().enterCreate( serviceRegistration.getReference() );
try
{
getServiceInternal( serviceRegistration );
}
finally
{
- getActivator().leaveCreate( serviceRegistration.getReference() );
+ m_container.getActivator().leaveCreate( serviceRegistration.getReference() );
}
}
else
@@ -983,7 +965,7 @@ public abstract class AbstractComponentM
return m_trackingCount;
}
- private void initDependencyManagers()
+ private void initDependencyManagers(final ComponentContextImpl<S> componentContext)
{
if (m_dependencyManagersInitialized)
{
@@ -1007,7 +989,7 @@ public abstract class AbstractComponentM
throw new IllegalStateException(
"Could not load implementation object class " + getComponentMetadata().getImplementationClassName());
}
- m_componentMethods.initComponentMethods(getComponentMetadata(), implementationObjectClass, this);
+ m_componentMethods.initComponentMethods(getComponentMetadata(), implementationObjectClass, componentContext.getLogger());
for (DependencyManager<S, ?> dependencyManager : m_dependencyManagers)
{
@@ -1025,7 +1007,7 @@ public abstract class AbstractComponentM
*/
protected boolean collectDependencies(ComponentContextImpl<S> componentContext)
{
- initDependencyManagers();
+ initDependencyManagers(componentContext);
for (DependencyManager<S, ?> dependencyManager : m_dependencyManagers)
{
if (!dependencyManager.prebind(componentContext))
@@ -1059,13 +1041,9 @@ public abstract class AbstractComponentM
if ( registrationManager.getServiceRegistration() != null )
{
//see if our service has been requested but returned null....
- ComponentActivator activator = getActivator();
log( LogService.LOG_DEBUG, "Notifying possible clients that service might be available with activator {0}",
- new Object[] { activator }, null );
- if ( activator != null )
- {
- activator.missingServicePresent( registrationManager.getServiceRegistration().getReference() );
- }
+ new Object[] { m_container.getActivator() }, null );
+ m_container.getActivator().missingServicePresent( registrationManager.getServiceRegistration().getReference() );
}
}
@@ -1076,19 +1054,9 @@ public abstract class AbstractComponentM
return m_container.getActivator();
}
- boolean isActivatorActive()
- {
- ComponentActivator activator = getActivator();
- return activator != null && activator.isActive();
- }
-
synchronized void clear()
{
- // for some testing, the activator may be null
- if (m_container.getActivator() != null)
- {
- m_container.getActivator().unregisterComponentId(this);
- }
+ m_container.getActivator().unregisterComponentId(this);
}
/**
@@ -1097,32 +1065,19 @@ public abstract class AbstractComponentM
@Override
public boolean isLogEnabled(int level)
{
- ComponentActivator activator = getActivator();
- if (activator != null)
- {
- return activator.isLogEnabled(level);
- }
- return false;
+ return m_container.getActivator().isLogEnabled(level);
}
@Override
public void log(int level, String message, Throwable ex)
{
- ComponentActivator activator = getActivator();
- if (activator != null)
- {
- activator.log(level, message, getComponentMetadata(), m_componentId, ex);
- }
+ m_container.getActivator().log(level, message, getComponentMetadata(), m_componentId, ex);
}
@Override
public void log(int level, String message, Object[] arguments, Throwable ex)
{
- ComponentActivator activator = getActivator();
- if (activator != null)
- {
- activator.log(level, message, arguments, getComponentMetadata(), m_componentId, ex);
- }
+ m_container.getActivator().log(level, message, arguments, getComponentMetadata(), m_componentId, ex);
}
@Override
@@ -1455,7 +1410,7 @@ public abstract class AbstractComponentM
{
this.failureReason = null;
}
- this.getActivator().updateChangeCount();
+ m_container.getActivator().updateChangeCount();
}
else
{
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentActivator.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentActivator.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentActivator.java Fri Oct 27 07:19:49 2017
@@ -23,6 +23,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationAdmin;
+
public interface ComponentActivator extends Logger, ExtendedServiceListenerContext<ExtendedServiceEvent> {
BundleContext getBundleContext();
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java Fri Oct 27 07:19:49 2017
@@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.felix.scr.component.ExtComponentContext;
import org.apache.felix.scr.impl.helper.ComponentServiceObjectsHelper;
import org.apache.felix.scr.impl.helper.ReadOnlyDictionary;
-import org.apache.felix.scr.impl.helper.SimpleLogger;
+import org.apache.felix.scr.impl.logger.ComponentLogger;
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -50,7 +50,7 @@ public class ComponentContextImpl<S> imp
private final EdgeInfo[] edgeInfos;
- private final ComponentInstance<S> m_componentInstance = new ComponentInstanceImpl<S>(this);
+ private final ComponentInstance<S> m_componentInstance = new ComponentInstanceImpl<>(this);
private final Bundle m_usingBundle;
@@ -67,9 +67,11 @@ public class ComponentContextImpl<S> imp
/** Mapping of ref pairs to value bound */
private Map<String, Map<RefPair<?, ?>, Object>> boundValues;
+ private final ComponentLogger logger;
-
- public ComponentContextImpl( final SingleComponentManager<S> componentManager, final Bundle usingBundle, ServiceRegistration<S> serviceRegistration )
+ public ComponentContextImpl( final SingleComponentManager<S> componentManager,
+ final Bundle usingBundle,
+ ServiceRegistration<S> serviceRegistration )
{
m_componentManager = componentManager;
m_usingBundle = usingBundle;
@@ -80,9 +82,40 @@ public class ComponentContextImpl<S> imp
edgeInfos[i] = new EdgeInfo();
}
this.serviceObjectsHelper = new ComponentServiceObjectsHelper(usingBundle.getBundleContext());
+ this.logger = new ComponentLogger()
+ {
+
+ @Override
+ public void log(final int level, final String message, final Throwable ex)
+ {
+ m_componentManager.getActivator().log(level,
+ message,
+ m_componentManager.getComponentMetadata(),
+ m_componentManager.getId() == 0 ? null : m_componentManager.getId(),
+ ex);
+ }
+
+ @Override
+ public void log(final int level, final String pattern, final Throwable ex, final Object... arguments)
+ {
+ m_componentManager.getActivator().log(level,
+ pattern,
+ arguments,
+ m_componentManager.getComponentMetadata(),
+ m_componentManager.getId() == 0 ? null : m_componentManager.getId(),
+ ex);
+ }
+
+ @Override
+ public boolean isLogEnabled(final int level)
+ {
+ return m_componentManager.getActivator().isLogEnabled(level);
+ }
+ };
}
- public void unsetServiceRegistration() {
+ public void unsetServiceRegistration()
+ {
m_serviceRegistration = null;
}
@@ -203,9 +236,9 @@ public class ComponentContextImpl<S> imp
return m_usingBundle;
}
- public SimpleLogger getLogger()
+ public ComponentLogger getLogger()
{
- return m_componentManager;
+ return this.logger;
}
@SuppressWarnings("unchecked")
@@ -219,22 +252,14 @@ public class ComponentContextImpl<S> imp
@Override
public void enableComponent( String name )
{
- ComponentActivator activator = m_componentManager.getActivator();
- if ( activator != null )
- {
- activator.enableComponent( name );
- }
+ m_componentManager.getActivator().enableComponent( name );
}
@Override
public void disableComponent( String name )
{
- ComponentActivator activator = m_componentManager.getActivator();
- if ( activator != null )
- {
- activator.disableComponent( name );
- }
+ m_componentManager.getActivator().disableComponent( name );
}
@@ -316,7 +341,7 @@ public class ComponentContextImpl<S> imp
{
if ( this.boundValues == null )
{
- this.boundValues = new HashMap<String, Map<RefPair<?,?>,Object>>();
+ this.boundValues = new HashMap<>();
}
Map<RefPair<?, ?>, Object> map = this.boundValues.get(key);
if ( map == null )
@@ -329,7 +354,7 @@ public class ComponentContextImpl<S> imp
private Map<RefPair<?, ?>, Object> createNewFieldHandlerMap()
{
- return new TreeMap<RefPair<?,?>, Object>(
+ return new TreeMap<>(
new Comparator<RefPair<?, ?>>()
{
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java Fri Oct 27 07:19:49 2017
@@ -414,7 +414,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>>();
+ List<RefPair<S, T>> failed = new ArrayList<>();
for (RefPair<S, T> refPair : tracked.values())
{
if (getServiceObject(key, m_bindMethods.getBind(), refPair))
@@ -611,7 +611,7 @@ public class DependencyManager<S, T> imp
private class MultipleStaticReluctantCustomizer extends AbstractCustomizer
{
- private final AtomicReference<Collection<RefPair<S, T>>> refs = new AtomicReference<Collection<RefPair<S, T>>>();
+ private final AtomicReference<Collection<RefPair<S, T>>> refs = new AtomicReference<>();
private int trackingCount;
@Override
@@ -722,7 +722,7 @@ public class DependencyManager<S, T> imp
}
return cardinalitySatisfied(serviceCount);
}
- refs = new ArrayList<RefPair<S, T>>();
+ refs = new ArrayList<>();
AtomicInteger trackingCount = new AtomicInteger();
SortedMap<ServiceReference<T>, RefPair<S, T>> tracked = getTracker().getTracked(true, trackingCount);
for (RefPair<S, T> refPair : tracked.values())
@@ -1343,15 +1343,8 @@ public class DependencyManager<S, T> imp
{
if (hasGetPermission())
{
- // component activator may be null if disposed concurrently
- ComponentActivator bca = m_componentManager.getActivator();
- if (bca == null)
- {
- return null;
- }
-
// get bundle context, may be null if component deactivated since getting bca
- BundleContext bc = bca.getBundleContext();
+ BundleContext bc = m_componentManager.getActivator().getBundleContext();
if (bc == null)
{
return null;
@@ -1424,7 +1417,7 @@ public class DependencyManager<S, T> imp
T[] getServices(ComponentContextImpl<S> key)
{
Collection<RefPair<S, T>> refs = m_customizer.getRefs(new AtomicInteger());
- List<T> services = new ArrayList<T>(refs.size());
+ List<T> services = new ArrayList<>(refs.size());
for (RefPair<S, T> ref : refs)
{
T service = getService(key, ref);
@@ -1445,7 +1438,7 @@ public class DependencyManager<S, T> imp
public List<ServiceReference<?>> getServiceReferences()
{
Collection<RefPair<S, T>> bound = m_customizer.getRefs(new AtomicInteger());
- List<ServiceReference<?>> result = new ArrayList<ServiceReference<?>>(bound.size());
+ List<ServiceReference<?>> result = new ArrayList<>(bound.size());
for (RefPair<S, T> ref : bound)
{
result.add(ref.getRef());
@@ -1602,7 +1595,7 @@ public class DependencyManager<S, T> imp
OpenStatus<S, T> open(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo)
{
int serviceCount = 0;
- final OpenStatus<S, T> status = new OpenStatus<S, T>();
+ final OpenStatus<S, T> status = new OpenStatus<>();
CountDownLatch openLatch;
synchronized (m_tracker.tracked())
{
@@ -1741,7 +1734,7 @@ public class DependencyManager<S, T> imp
final Object componentInstance = componentContext.getImplementationObject(false);
if (componentInstance != null)
{
- return m_bindMethods.getInit().init(componentInstance, m_componentManager);
+ return m_bindMethods.getInit().init(componentInstance, componentContext.getLogger());
}
}
return true;
@@ -2181,7 +2174,7 @@ public class DependencyManager<S, T> imp
new Object[] { getName(), initialActive, refMap, classFilterString, eventFilter,
initialReferenceFilterString },
null);
- ServiceTracker<T, RefPair<S, T>, ExtendedServiceEvent> tracker = new ServiceTracker<T, RefPair<S, T>, ExtendedServiceEvent>(
+ ServiceTracker<T, RefPair<S, T>, ExtendedServiceEvent> tracker = new ServiceTracker<>(
bundleContext, m_customizer, initialActive, m_componentManager.getActivator(), eventFilter,
classFilterString, initialReferenceFilterString);
m_customizer.setTracker(tracker);
@@ -2256,7 +2249,7 @@ public class DependencyManager<S, T> imp
}
else
{
- refMap = new TreeMap<ServiceReference<T>, RefPair<S, T>>(Collections.reverseOrder());
+ refMap = new TreeMap<>(Collections.reverseOrder());
m_componentManager.log(LogService.LOG_DEBUG,
" No existing service listener to unregister for dependency {0}", new Object[] { getName() }, null);
trackingCount.set(-1);
@@ -2298,13 +2291,13 @@ public class DependencyManager<S, T> imp
{
if (m_dependencyMetadata.getScope() == ReferenceScope.bundle)
{
- return new SingleRefPair<S, T>(serviceReference);
+ return new SingleRefPair<>(serviceReference);
}
if (m_componentManager.getComponentMetadata().getServiceScope() == Scope.singleton)
{
- return new SinglePrototypeRefPair<S, T>(m_componentManager.getBundleContext(), serviceReference);
+ return new SinglePrototypeRefPair<>(m_componentManager.getBundleContext(), serviceReference);
}
- return new MultiplePrototypeRefPair<S, T>(m_componentManager.getBundleContext(), serviceReference);
+ return new MultiplePrototypeRefPair<>(m_componentManager.getBundleContext(), serviceReference);
}
private void deactivateComponentManager()
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/MultiplePrototypeRefPair.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/MultiplePrototypeRefPair.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/MultiplePrototypeRefPair.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/MultiplePrototypeRefPair.java Fri Oct 27 07:19:49 2017
@@ -34,7 +34,7 @@ import org.osgi.service.log.LogService;
public class MultiplePrototypeRefPair<S, T> extends RefPair<S, T>
{
private final ServiceObjects<T> serviceObjects;
- private final ConcurrentMap<ComponentContextImpl<S>, T> instances = new ConcurrentHashMap<ComponentContextImpl<S>, T>();
+ private final ConcurrentMap<ComponentContextImpl<S>, T> instances = new ConcurrentHashMap<>();
public MultiplePrototypeRefPair( BundleContext context, ServiceReference<T> ref )
{
@@ -81,7 +81,7 @@ public class MultiplePrototypeRefPair<S,
setFailed();
key.getLogger().log(
LogService.LOG_WARNING,
- "Could not get service from serviceobjects for ref {0}", new Object[] {getRef()}, null );
+ "Could not get service from serviceobjects for ref {0}", null, getRef() );
return false;
}
if (!setServiceObject(key, service))
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java Fri Oct 27 07:19:49 2017
@@ -136,11 +136,7 @@ public class SingleComponentManager<S> e
log( LogService.LOG_DEBUG, "Set implementation object for component {0}", new Object[] { getName() }, null );
//notify that component was successfully created so any optional circular dependencies can be retried
- ComponentActivator activator = getActivator();
- if ( activator != null )
- {
- activator.missingServicePresent( getServiceReference() );
- }
+ m_container.getActivator().missingServicePresent( getServiceReference() );
}
return true;
}
@@ -276,6 +272,13 @@ public class SingleComponentManager<S> e
paramMap);
}
+ catch ( final InstantiationException ie)
+ {
+ // we don't need to log the stack trace
+ log( LogService.LOG_ERROR, "Error during instantiation of the implementation object: " + ie.getMessage(), null );
+ this.setFailureReason(ie);
+ return null;
+ }
catch ( Throwable t )
{
// failed to instantiate, return null
@@ -350,13 +353,10 @@ public class SingleComponentManager<S> e
else
{
componentContext.setImplementationAccessible( true );
- ComponentActivator activator = getActivator();
- if ( activator != null )
- {
- //call to leaveCreate must be done here since the change in service properties may cause a getService,
- //so the threadLocal must be cleared first.
- activator.leaveCreate(getServiceReference());
- }
+ //call to leaveCreate must be done here since the change in service properties may cause a getService,
+ //so the threadLocal must be cleared first.
+ m_container.getActivator().leaveCreate(getServiceReference());
+
//this may cause a getService as properties now match a filter.
setServiceProperties( result, null );
}
@@ -840,7 +840,7 @@ public class SingleComponentManager<S> e
@Override
public S getService( Bundle bundle, ServiceRegistration<S> serviceRegistration )
{
- if ( getActivator().enterCreate( serviceRegistration.getReference() ) )
+ if ( m_container.getActivator().enterCreate( serviceRegistration.getReference() ) )
{
return null;
}
@@ -873,7 +873,7 @@ public class SingleComponentManager<S> e
finally
{
//This is backup. Normally done in createComponent.
- getActivator().leaveCreate(serviceRegistration.getReference());
+ m_container.getActivator().leaveCreate(serviceRegistration.getReference());
}
}
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SinglePrototypeRefPair.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SinglePrototypeRefPair.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SinglePrototypeRefPair.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SinglePrototypeRefPair.java Fri Oct 27 07:19:49 2017
@@ -59,7 +59,7 @@ public class SinglePrototypeRefPair<S, T
setFailed();
key.getLogger().log(
LogService.LOG_WARNING,
- "Could not get service from serviceobjects for ref {0}", new Object[] {getRef()}, null );
+ "Could not get service from serviceobjects for ref {0}",null, getRef() );
return false;
}
if (!setServiceObject(key, service))
Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleRefPair.java Fri Oct 27 07:19:49 2017
@@ -31,7 +31,7 @@ import org.osgi.service.log.LogService;
*/
public class SingleRefPair<S, T> extends RefPair<S, T>
{
- private AtomicReference<T> serviceObjectRef = new AtomicReference<T>();
+ private AtomicReference<T> serviceObjectRef = new AtomicReference<>();
public SingleRefPair( ServiceReference<T> ref )
{
@@ -76,7 +76,7 @@ public class SingleRefPair<S, T> extends
setFailed();
key.getLogger().log(
LogService.LOG_WARNING,
- "Could not get service from ref {0}", new Object[] {getRef()}, null );
+ "Could not get service from ref {0}", null, getRef() );
return false;
}
if (!setServiceObject(key, service))
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/PackageIsolationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/PackageIsolationTest.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/PackageIsolationTest.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/PackageIsolationTest.java Fri Oct 27 07:19:49 2017
@@ -56,6 +56,7 @@ public class PackageIsolationTest extend
"org/apache/felix/scr/impl/inject",
"org/apache/felix/scr/impl/inject/field",
"org/apache/felix/scr/impl/inject/methods",
+ "org/apache/felix/scr/impl/logger",
"org/apache/felix/scr/impl/manager",
"org/apache/felix/scr/impl/metadata");
@@ -97,9 +98,9 @@ public class PackageIsolationTest extend
}
public static class DependencyVisitor extends ClassVisitor {
- Set<String> packages = new HashSet<String>();
+ Set<String> packages = new HashSet<>();
- Map<String, Map<String, Integer>> groups = new HashMap<String, Map<String, Integer>>();
+ Map<String, Map<String, Integer>> groups = new HashMap<>();
Map<String, Integer> current;
@@ -124,7 +125,7 @@ public class PackageIsolationTest extend
String p = getGroupKey(name);
current = groups.get(p);
if (current == null) {
- current = new HashMap<String, Integer>();
+ current = new HashMap<>();
groups.put(p, current);
}
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java Fri Oct 27 07:19:49 2017
@@ -19,9 +19,9 @@
package org.apache.felix.scr.impl.inject;
-import org.apache.felix.scr.impl.BundleComponentActivator;
import org.apache.felix.scr.impl.MockBundle;
import org.apache.felix.scr.impl.inject.methods.BindMethod;
+import org.apache.felix.scr.impl.manager.ComponentActivator;
import org.apache.felix.scr.impl.manager.ComponentContainer;
import org.apache.felix.scr.impl.manager.ComponentContextImpl;
import org.apache.felix.scr.impl.manager.RefPair;
@@ -457,13 +457,14 @@ public class BindMethodTest extends Test
private ComponentContainer newContainer()
{
+ final ComponentActivator activator = Mockito.mock(ComponentActivator.class);
final ComponentMetadata metadata = newMetadata();
ComponentContainer container = new ComponentContainer() {
@Override
- public BundleComponentActivator getActivator()
+ public ComponentActivator getActivator()
{
- return null;
+ return activator;
}
@Override
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/manager/ConfiguredComponentHolderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/manager/ConfiguredComponentHolderTest.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/manager/ConfiguredComponentHolderTest.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/manager/ConfiguredComponentHolderTest.java Fri Oct 27 07:19:49 2017
@@ -29,6 +29,7 @@ import org.apache.felix.scr.impl.inject.
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.apache.felix.scr.impl.metadata.DSVersion;
import org.apache.felix.scr.impl.metadata.TargetedPID;
+import org.mockito.Mockito;
import junit.framework.TestCase;
@@ -187,7 +188,7 @@ public class ConfiguredComponentHolderTe
{
TestingConfiguredComponentHolder( ComponentMetadata metadata )
{
- super( null, metadata );
+ super( Mockito.mock(ComponentActivator.class), metadata );
}
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/ComponentFieldActivationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/ComponentFieldActivationTest.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/ComponentFieldActivationTest.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/ComponentFieldActivationTest.java Fri Oct 27 07:19:49 2017
@@ -24,19 +24,13 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
-import java.util.Collection;
import org.apache.felix.scr.integration.components.FieldActivatorComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
@RunWith(PaxExam.class)
public class ComponentFieldActivationTest extends ComponentTestBase
@@ -66,12 +60,15 @@ public class ComponentFieldActivationTes
FieldActivatorComponent cmp = this.getServiceFromConfiguration(cc, FieldActivatorComponent.class);
- final String msg = cmp.test();
- assertNull(msg, msg);
+ assertTrue(cmp.isActivateCalled());
+ assertTrue(cmp.notSetBeforeActivate().isEmpty());
+ assertEquals(4, cmp.setBeforeActivate().size());
+ assertNull(cmp.additionalError());
+
disableAndCheck( cc );
}
-
- protected <S> void failGetServiceFromConfiguration(ComponentConfigurationDTO dto, Class<S> clazz)
+/**
+ private <S> void failGetServiceFromConfiguration(ComponentConfigurationDTO dto, Class<S> clazz)
{
long id = dto.id;
String filter = "(component.id=" + id + ")";
@@ -88,7 +85,7 @@ public class ComponentFieldActivationTes
TestCase.fail( e.getMessage() );
}
}
-
+*/
@Test
public void test_field_activator_failure() throws Exception
{
@@ -98,7 +95,13 @@ public class ComponentFieldActivationTes
assertEquals(1, cc.description.activationFields.length);
assertTrue(Arrays.asList(cc.description.activationFields).contains("foo"));
- this.failGetServiceFromConfiguration(cc, FieldActivatorComponent.class);
+ // we get the component, although the field does not exist!
+ FieldActivatorComponent cmp = this.getServiceFromConfiguration(cc, FieldActivatorComponent.class);
+
+ assertTrue(cmp.isActivateCalled());
+ assertTrue(cmp.setBeforeActivate().isEmpty());
+ assertEquals(4, cmp.notSetBeforeActivate().size());
+ assertNull(cmp.additionalError());
disableAndCheck( cc );
}
@@ -114,7 +117,15 @@ public class ComponentFieldActivationTes
assertTrue(Arrays.asList(cc.description.activationFields).contains("context"));
assertTrue(Arrays.asList(cc.description.activationFields).contains("foo"));
- this.failGetServiceFromConfiguration(cc, FieldActivatorComponent.class);
+ // we get the component, although some fields do not exist!
+ FieldActivatorComponent cmp = this.getServiceFromConfiguration(cc, FieldActivatorComponent.class);
+
+ assertTrue(cmp.isActivateCalled());
+ assertEquals(2, cmp.setBeforeActivate().size());
+ assertTrue(cmp.setBeforeActivate().contains("bundle"));
+ assertTrue(cmp.setBeforeActivate().contains("context"));
+ assertEquals(2, cmp.notSetBeforeActivate().size());
+ assertNull(cmp.additionalError());
disableAndCheck( cc );
}
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java Fri Oct 27 07:19:49 2017
@@ -33,16 +33,16 @@ public class ActivatorComponent
public static final String FLAG_FAIL_DEACTIVATE = "failDeactivate";
public static final String FLAG_REGISTER_SERVICE = "registerService";
-
+
private static ActivatorComponent activatorComponent;
private ServiceRegistration registration;
private SimpleService simpleService;
-
+
public static ActivatorComponent getInstance()
{
- return activatorComponent;
+ return activatorComponent;
}
@SuppressWarnings("unused")
@@ -58,7 +58,7 @@ public class ActivatorComponent
}
if ( activatorComponent != null )
{
- throw new IllegalStateException( "not the only activator component");
+ throw new IllegalStateException( "not the only activator component");
}
this.activatorComponent = this;
}
Modified: felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/FieldActivatorComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/FieldActivatorComponent.java?rev=1813478&r1=1813477&r2=1813478&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/FieldActivatorComponent.java (original)
+++ felix/trunk/osgi-r7/scr/src/test/java/org/apache/felix/scr/integration/components/FieldActivatorComponent.java Fri Oct 27 07:19:49 2017
@@ -19,6 +19,8 @@
package org.apache.felix.scr.integration.components;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.osgi.framework.BundleContext;
@@ -45,55 +47,92 @@ public class FieldActivatorComponent
private String activationTest;
+ private final List<String> notSetBeforeActivate = new ArrayList<>();
+
+ private final List<String> setBeforeActivate = new ArrayList<>();
+
+ public FieldActivatorComponent()
+ {
+ notSetBeforeActivate.add("bundle");
+ notSetBeforeActivate.add("context");
+ notSetBeforeActivate.add("config");
+ notSetBeforeActivate.add("annotation");
+ }
+
@SuppressWarnings("unused")
private void activator() {
// everything should be set here already
- activationTest = check();
+ check();
activated = true;
}
- private String check()
+ private void addError(final String msg)
{
- if ( bundle == null ) {
- return "bundle is null";
- }
- if ( context == null ) {
- return "context is null";
- }
- if ( config == null ) {
- return "config is null";
- }
- if ( annotation == null ) {
- return "annotation is null";
- }
- if ( !annotation.email().equals("foo") ) {
- return "Wrong value for annotation.email: " + annotation.email();
- }
- if ( annotation.port() != 80 ) {
- return "Wrong value for annotation.port: " + annotation.port();
- }
- if ( annotation.test() != 0 ) {
- return "Wrong value for annotation.test: " + annotation.test();
- }
- if ( !config.get("email").equals("foo") ) {
- return "Wrong value for map.email: " + config.get("email");
- }
- if ( !config.get("port").equals("80") ) {
- return "Wrong value for map.email: " + config.get("port");
- }
- if ( config.get("test") != null ) {
- return "Wrong value for map.test: " + config.get("test");
+ if ( activationTest == null )
+ {
+ activationTest = msg;
+ }
+ else
+ {
+ activationTest = activationTest + ", " + msg;
}
- return null;
}
- public String test() {
- if ( !activated ) {
- return "activate not called";
- }
- if ( activationTest != null ) {
- return "not set before activate: " + activationTest;
+ private void check()
+ {
+ if ( bundle != null ) {
+ notSetBeforeActivate.remove("bundle");
+ setBeforeActivate.add("bundle");
+ }
+ if ( context != null ) {
+ notSetBeforeActivate.remove("context");
+ setBeforeActivate.add("context");
+ }
+ if ( config != null ) {
+ notSetBeforeActivate.remove("config");
+ setBeforeActivate.add("config");
+ if ( !config.get("email").equals("foo") ) {
+ addError("Wrong value for map.email: " + config.get("email"));
+ }
+ if ( !config.get("port").equals("80") ) {
+ addError("Wrong value for map.email: " + config.get("port"));
+ }
+ if ( config.get("test") != null ) {
+ addError("Wrong value for map.test: " + config.get("test"));
+ }
+ }
+ if ( annotation != null ) {
+ notSetBeforeActivate.remove("annotation");
+ setBeforeActivate.add("annotation");
+ if ( !annotation.email().equals("foo") ) {
+ addError("Wrong value for annotation.email: " + annotation.email());
+ }
+ if ( annotation.port() != 80 ) {
+ addError("Wrong value for annotation.port: " + annotation.port());
+ }
+ if ( annotation.test() != 0 ) {
+ addError("Wrong value for annotation.test: " + annotation.test());
+ }
}
- return check();
+ }
+
+ public boolean isActivateCalled()
+ {
+ return activated;
+ }
+
+ public List<String> setBeforeActivate()
+ {
+ return setBeforeActivate;
+ }
+
+ public List<String> notSetBeforeActivate()
+ {
+ return notSetBeforeActivate;
+ }
+
+ public String additionalError()
+ {
+ return activationTest;
}
}