You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/05/13 10:56:08 UTC
svn commit: r774260 - in
/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context:
CollectionBasedServiceReferenceRecipe.java UnaryServiceReferenceRecipe.java
Author: gnodet
Date: Wed May 13 08:56:07 2009
New Revision: 774260
URL: http://svn.apache.org/viewvc?rev=774260&view=rev
Log:
Make sure services are lazily retrieved to keep lazy ativated bundles
Modified:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java?rev=774260&r1=774259&r2=774260&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java Wed May 13 08:56:07 2009
@@ -199,25 +199,35 @@
public ServiceDispatcher(ServiceReference reference, boolean memberReference) throws Exception {
this.reference = reference;
this.memberReference = memberReference;
- this.service = reference.getBundle().getBundleContext().getService(reference);
}
- public Object getMember() {
- return (memberReference) ? reference : service;
+ public synchronized Object getMember() {
+ if (memberReference) {
+ return reference;
+ } else {
+ if (service == null && reference != null) {
+ service = reference.getBundle().getBundleContext().getService(reference);
+ }
+ return service;
+ }
}
- public void destroy() {
+ public synchronized void destroy() {
if (reference != null) {
reference.getBundle().getBundleContext().ungetService(reference);
+ reference = null;
service = null;
proxy = null;
}
}
- public Object loadObject() throws Exception {
- if (service == null) {
+ public synchronized Object loadObject() throws Exception {
+ if (reference == null) {
throw new ServiceUnregisteredException();
}
+ if (service == null) {
+ service = reference.getBundle().getBundleContext().getService(reference);
+ }
return service;
}
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java?rev=774260&r1=774259&r2=774260&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java Wed May 13 08:56:07 2009
@@ -48,6 +48,7 @@
private final ReferenceMetadata metadata;
private Class proxyClass;
+ private Object proxy;
private volatile ServiceReference trackedServiceReference;
private volatile Object trackedService;
@@ -65,13 +66,13 @@
protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
try {
// Create the proxy
- Object obj = createProxy(new ServiceDispatcher(), metadata.getInterfaceNames());
- proxyClass = obj.getClass();
+ proxy = createProxy(new ServiceDispatcher(), metadata.getInterfaceNames());
+ proxyClass = proxy.getClass();
// Create the listeners and initialize them
createListeners();
// Add the created proxy to the context
if (getName() != null) {
- ExecutionContext.getContext().addObject(getName(), obj);
+ ExecutionContext.getContext().addObject(getName(), proxy);
}
// Start tracking the service
@@ -79,7 +80,7 @@
retrack();
// Return the object
- return obj;
+ return proxy;
} catch (Throwable t) {
throw new ConstructionException(t);
}
@@ -123,10 +124,9 @@
blueprintContext.getBundleContext().ungetService(trackedServiceReference);
}
trackedServiceReference = ref;
- trackedService = blueprintContext.getBundleContext().getService(trackedServiceReference);
monitor.notifyAll();
for (Listener listener : listeners) {
- listener.bind(trackedServiceReference, trackedService);
+ listener.bind(trackedServiceReference, proxy);
}
}
}
@@ -134,9 +134,7 @@
private void unbind() {
synchronized (monitor) {
if (trackedServiceReference != null) {
- for (Listener listener : listeners) {
- listener.unbind(trackedServiceReference, trackedService);
- }
+ // Listeners are not called for a reference
blueprintContext.getBundleContext().ungetService(trackedServiceReference);
trackedServiceReference = null;
trackedService = null;
@@ -148,18 +146,21 @@
public Object loadObject() throws Exception {
synchronized (monitor) {
- if (tracker.isStarted() && trackedService == null && metadata.getTimeout() > 0) {
+ if (tracker.isStarted() && trackedServiceReference == null && metadata.getTimeout() > 0) {
Set<String> interfaces = new HashSet<String>(metadata.getInterfaceNames());
sender.sendWaiting(blueprintContext, interfaces.toArray(new String[interfaces.size()]), getOsgiFilter());
monitor.wait(metadata.getTimeout());
}
- if (trackedService == null) {
+ if (trackedServiceReference == null) {
if (tracker.isStarted()) {
throw new ServiceUnavailableException("Timeout expired when waiting for OSGi service", proxyClass.getSuperclass(), getOsgiFilter());
} else {
throw new ServiceUnavailableException("Service tracker is stopped", proxyClass.getSuperclass(), getOsgiFilter());
}
}
+ if (trackedService == null) {
+ trackedService = blueprintContext.getBundleContext().getService(trackedServiceReference);
+ }
return trackedService;
}
}