geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1380949 - in /geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries: ApplicationGBean.java ApplicationInstaller.java
Date Wed, 05 Sep 2012 02:24:09 GMT
Author: gawor
Date: Wed Sep  5 02:24:08 2012
New Revision: 1380949

URL: http://svn.apache.org/viewvc?rev=1380949&view=rev
Log:
GERONIMO-6386: Implement application notifications using AriesApplicationListener

Modified:
    geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
    geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java?rev=1380949&r1=1380948&r2=1380949&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Wed Sep  5 02:24:08 2012
@@ -125,6 +125,8 @@ public class ApplicationGBean implements
         } finally {
             bundleContext.ungetService(applicationManagerReference);
         }
+        
+        setApplicationState(ApplicationState.INSTALLED);
     }
 
     public long[] getApplicationContentBundleIds() {
@@ -355,8 +357,6 @@ public class ApplicationGBean implements
                 bundleContext.ungetService(packageAdminRef);
             }
         }
-
-        applicationState = ApplicationState.INSTALLED;
     }
     
     @SuppressWarnings("deprecation")
@@ -405,14 +405,10 @@ public class ApplicationGBean implements
     public void doStart() throws Exception {
         LOG.debug("Starting {} application.", getApplicationName());
         
-        applicationState = ApplicationState.STARTING;
         try {
             startApplicationBundles();
-            applicationState = ApplicationState.ACTIVE;
             LOG.debug("Application {} started successfully.", getApplicationName());
         } catch (BundleException be) {
-            applicationState = ApplicationState.INSTALLED;
-            
             Exception rootException = be;
             String rootMessage = be.getMessage();
             
@@ -448,6 +444,9 @@ public class ApplicationGBean implements
             throw new BundleException("One or more bundles in " + getApplicationName() +
" application could not be resolved.");
         }
         
+        setApplicationState(ApplicationState.RESOLVED);
+        setApplicationState(ApplicationState.STARTING);
+        
         LinkedList<Bundle> bundlesWeStarted = new LinkedList<Bundle>();
         try {
             applicationBundles = getSortedBundles();
@@ -458,7 +457,9 @@ public class ApplicationGBean implements
                     bundlesWeStarted.addFirst(b); 
                 }
             }
+            setApplicationState(ApplicationState.ACTIVE);
         } catch (BundleException be) {
+            setApplicationState(ApplicationState.STOPPING);
             for (Bundle b : bundlesWeStarted) {
                 try {
                     b.stop();
@@ -471,6 +472,7 @@ public class ApplicationGBean implements
                     // stop.
                 }
             }
+            setApplicationState(ApplicationState.RESOLVED);
             throw be;
         }
     }
@@ -557,6 +559,10 @@ public class ApplicationGBean implements
     public void doStop() {
         LOG.debug("Stopping {} application.", getApplicationName());
         
+        if (getApplicationState() == ApplicationState.ACTIVE) {
+            setApplicationState(ApplicationState.STOPPING);
+        }
+        
         // stop bundles in reverse order
         LinkedList<Bundle> sortedList = new LinkedList<Bundle>();
         for (Bundle bundle : applicationBundles) {
@@ -573,7 +579,7 @@ public class ApplicationGBean implements
         }
         applicationBundles.clear();
 
-        applicationState = ApplicationState.RESOLVED;
+        setApplicationState(ApplicationState.UNINSTALLED);        
     }
 
     public void doFail() {
@@ -607,7 +613,14 @@ public class ApplicationGBean implements
             // ignore
         }
                      
-        applicationState = ApplicationState.UNINSTALLED;
+        setApplicationState(ApplicationState.UNINSTALLED);
     }
 
+    private void setApplicationState(ApplicationState newState) {
+        if (applicationState != newState) {
+            applicationState = newState;
+            installer.fireApplicationEvent(application, newState);
+        }
+    }
+        
 }

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java?rev=1380949&r1=1380948&r2=1380949&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
Wed Sep  5 02:24:08 2012
@@ -27,7 +27,9 @@ import java.util.zip.ZipInputStream;
 import org.apache.aries.application.ApplicationMetadata;
 import org.apache.aries.application.DeploymentMetadata;
 import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationListener;
 import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.AriesApplicationContext.ApplicationState;
 import org.apache.aries.application.utils.AppConstants;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentContext;
@@ -57,6 +59,8 @@ import org.apache.geronimo.kernel.util.F
 import org.apache.geronimo.kernel.util.IOUtils;
 import org.apache.geronimo.kernel.util.JarUtils;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,7 +162,7 @@ public class ApplicationInstaller implem
             data.setReferencePattern("Installer", abstractName);
 
             context.addGBean(data);
-
+            
             return context;
         } catch (DeploymentException e) {
             throw e;
@@ -255,5 +259,30 @@ public class ApplicationInstaller implem
         }
         return null;
     }
+    
+    protected void fireApplicationEvent(AriesApplication application, ApplicationState state)
{
+        Collection<ServiceReference<AriesApplicationListener>> references = null;
+        try {
+            references = bundleContext.getServiceReferences(AriesApplicationListener.class,
null);
+        } catch (InvalidSyntaxException e) {
+            // this can't happen
+            throw new Error(e);
+        }
+        if (references != null && !references.isEmpty()) {
+            GeronimoApplicationEvent event = new GeronimoApplicationEvent(application, state);
+            for (ServiceReference<AriesApplicationListener> reference : references)
{
+                AriesApplicationListener listener = bundleContext.getService(reference);
+                if (listener != null) {
+                    try {
+                        listener.applicationChanged(event);
+                    } catch (Exception e) {
+                        LOG.debug("Error calling AriesApplicationListener", e);
+                    } finally {
+                        bundleContext.ungetService(reference);
+                    }
+                }
+            }
+        }
+    }
 
 }



Mime
View raw message