geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r772830 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context: BlueprintContextImpl.java RecipeBuilder.java ServiceReferenceTracker.java ServiceRegistrationProxy.java
Date Fri, 08 May 2009 02:52:57 GMT
Author: gawor
Date: Fri May  8 02:52:56 2009
New Revision: 772830

URL: http://svn.apache.org/viewvc?rev=772830&view=rev
Log:
track of all service registrations (top-level or nested) and let service registration proxies
auto register the service during injection

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java?rev=772830&r1=772829&r2=772830&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
Fri May  8 02:52:56 2009
@@ -105,6 +105,7 @@
     private List<BeanProcessor> beanProcessors;
     private Map<String, Destroyable> destroyables = new HashMap<String, Destroyable>();
     private Map<String, List<SatisfiableRecipe>> satisfiables;
+    private Map<ServiceMetadata, ServiceRegistrationProxy> services;
     private boolean serviceActivation;
     private Map<ServiceMetadata, TriggerService> triggerServices;
     private long timeout = 5 * 60 * 1000; 
@@ -122,6 +123,7 @@
         this.lazyActivation = lazyActivation;
         this.triggerServices = new HashMap<ServiceMetadata, TriggerService>();
         this.beanProcessors = new ArrayList<BeanProcessor>();
+        this.services = Collections.synchronizedMap(new HashMap<ServiceMetadata, ServiceRegistrationProxy>());
     }
 
     public Class loadClass(String name) throws ClassNotFoundException {
@@ -235,7 +237,6 @@
                         return;
                     case Create:
                         instantiateComponents();
-                        registerAllServices();
 
                         // Register the BlueprintContext in the OSGi registry
                         if (registration == null) {
@@ -416,7 +417,7 @@
                 if (!local.isLazyInit() && BeanMetadata.SCOPE_SINGLETON.equals(scope))
{
                     components.add(name);
                 }
-            } else if (components instanceof ServiceReferenceMetadata) {
+            } else {
                 components.add(name);
             }
         }
@@ -440,25 +441,21 @@
         }
     }
     
-    private void registerAllServices() {
-        for (ServiceMetadata service : getExportedServicesMetadata()) {
-            ServiceRegistrationProxy proxy = (ServiceRegistrationProxy) getComponent(service.getId());
-            if (proxy != null) {
-                proxy.register();
-            }
+    protected void registerService(ServiceRegistrationProxy registration) { 
+        ServiceMetadata metadata = registration.getMetadata();
+        if (services.put(metadata, registration) != null) {
+            LOGGER.warn("Service for this metadata is already registered {}", metadata);
         }
     }
-    
-    private void unregisterAllServices() {
-        for (ServiceMetadata service : getExportedServicesMetadata()) {
-            ServiceRegistrationProxy proxy = (ServiceRegistrationProxy) getComponent(service.getId());
-            if (proxy != null) {
-                proxy.unregister();
-            }
+        
+    private void unregisterServices() {
+        for (ServiceRegistrationProxy proxy : services.values()) {
+            proxy.unregister();
         }
     }
         
     private void registerTriggerServices() {
+        // TODO: right now this only returns top-level services
         for (ServiceMetadata service : getExportedServicesMetadata()) {
             // Trigger services are only created for services without listeners and explicitly
defined interface classes
             if (service.getRegistrationListeners().isEmpty() && !service.getInterfaceNames().isEmpty())
{
@@ -567,7 +564,7 @@
         }
         handlers.removeListener(this);
         sender.sendDestroying(this);
-        unregisterAllServices();  
+        unregisterServices();  
         unregisterTriggerServices();
         destroyComponents();
         // TODO: stop all reference / collections
@@ -583,7 +580,7 @@
 
     public synchronized void namespaceHandlerUnregistered(URI uri) {
         if (namespaces != null && namespaces.contains(uri)) {
-            unregisterAllServices();
+            unregisterServices();
             destroyComponents();
             // TODO: stop all reference / collections
             // TODO: clear the repository

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java?rev=772830&r1=772829&r2=772830&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
Fri May  8 02:52:56 2009
@@ -168,6 +168,7 @@
         recipe.allow(Option.PRIVATE_PROPERTIES);
         recipe.setName(getName(serviceExport.getId()));
         recipe.setExplicitDependencies(serviceExport.getExplicitDependencies());
+        recipe.setInitMethod("init");
         recipe.setProperty("blueprintContext", blueprintContext);
         BeanMetadata exportedComponent = getLocalServiceComponent(serviceExport.getServiceComponent());
         if (exportedComponent != null && BeanMetadata.SCOPE_BUNDLE.equals(exportedComponent.getScope()))
{

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java?rev=772830&r1=772829&r2=772830&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
Fri May  8 02:52:56 2009
@@ -45,7 +45,7 @@
     private boolean optional;
     private boolean satisfied;
     private List<ServiceReference> referenceSet;
-    
+    private boolean started;   
     private List<ServiceListener> serviceListeners = new CopyOnWriteArrayList<ServiceListener>();
     private List<SatisfactionListener> satisfactionListeners = new CopyOnWriteArrayList<SatisfactionListener>();
     
@@ -54,11 +54,15 @@
         this.filter = filter;
         this.optional = optional;
         
+        this.started = false;
         this.satisfied = false;
         this.referenceSet = new ArrayList<ServiceReference>();
     }
     
-    public synchronized void start() throws InvalidSyntaxException {        
+    public synchronized void start() throws InvalidSyntaxException {
+        if (started) {
+            return;
+        }
         context.addServiceListener(this, filter);
         ServiceReference[] references = context.getServiceReferences(null, filter);
         if (references != null) {
@@ -66,13 +70,15 @@
                 referenceSet.add(reference);
             }
         }
-        satisfied = (optional) ? true : !referenceSet.isEmpty();       
+        satisfied = (optional) ? true : !referenceSet.isEmpty();   
+        started = true;
     }
     
-    public void close() {
+    public synchronized void close() {
         context.removeServiceListener(this);
         referenceSet.clear();
         satisfactionListeners.clear();
+        started = false;
     }
     
     public boolean isSatisfied() {
@@ -116,7 +122,7 @@
         }
     }
     
-    protected void serviceModified(ServiceEvent event) { 
+    protected synchronized void serviceModified(ServiceEvent event) { 
         ServiceReference ref = event.getServiceReference();
         notifyServiceListeners(event);
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java?rev=772830&r1=772829&r2=772830&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
Fri May  8 02:52:56 2009
@@ -60,7 +60,16 @@
     protected Map getRegistrationProperties() {
         return registrationProperties;
     }
-
+    
+    public void init() {
+        register();
+        blueprintContext.registerService(this);
+    }
+    
+    public ServiceMetadata getMetadata() {
+        return metadata;
+    }
+    
     public boolean isRegistered() {
         return registration != null;
     }



Mime
View raw message