continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r395936 - in /maven/continuum/branches/continuum-1.0.x: continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-core/src/main/java/org/apache/maven/continuum/ continuum-store/src/main/java/org/apache/maven/continuum/store/
Date Fri, 21 Apr 2006 16:30:47 GMT
Author: evenisse
Date: Fri Apr 21 09:30:44 2006
New Revision: 395936

URL: http://svn.apache.org/viewcvs?rev=395936&view=rev
Log:
o close the store when continuum shutdown
o Add a message if continuum can't update project state at startup (jpox don't always update
it, strange)

Modified:
    maven/continuum/branches/continuum-1.0.x/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/branches/continuum-1.0.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    maven/continuum/branches/continuum-1.0.x/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java

Modified: maven/continuum/branches/continuum-1.0.x/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=395936&r1=395935&r2=395936&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
(original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
Fri Apr 21 09:30:44 2006
@@ -228,4 +228,6 @@
     UserGroup getUserGroup( String name );
 
     void removeUserGroup( UserGroup group );
+
+    void closeStore();
 }

Modified: maven/continuum/branches/continuum-1.0.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=395936&r1=395935&r2=395936&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Fri Apr 21 09:30:44 2006
@@ -152,6 +152,28 @@
      */
     private BuildExecutorManager executorManager;
 
+    private boolean stopped = false;
+
+    public DefaultContinuum()
+    {
+        super();
+
+        Runtime.getRuntime().addShutdownHook( new Thread()
+        {
+            public void run()
+            {
+                try
+                {
+                    stopContinuum();
+                }
+                catch ( StoppingException e )
+                {
+                    e.printStackTrace();
+                }
+            }
+        } );
+    }
+
     // ----------------------------------------------------------------------
     // Projects
     // ----------------------------------------------------------------------
@@ -1928,13 +1950,25 @@
                 project.getState() != ContinuumProjectState.OK && project.getState()
!= ContinuumProjectState.FAILED &&
                 project.getState() != ContinuumProjectState.ERROR )
             {
+                int state = project.getState();
+
                 project.setState( project.getOldState() );
 
                 project.setOldState( 0 );
 
                 try
                 {
+                    getLogger().info( "Fix project state for project " + project.getId()
+ ":" + project.getName() +
+                        ":" + project.getVersion() );
+
                     store.updateProject( project );
+
+                    Project p = store.getProject( project.getId() );
+
+                    if ( state == p.getState() )
+                    {
+                        getLogger().info( "Can't fix the project state." );
+                    }
                 }
                 catch ( ContinuumStoreException e )
                 {
@@ -1989,9 +2023,25 @@
         }
     }
 
+    private void closeStore()
+    {
+        store.closeStore();
+    }
+
     public void stop()
         throws StoppingException
     {
+        stopContinuum();
+    }
+
+    public void stopContinuum()
+        throws StoppingException
+    {
+        if ( stopped )
+        {
+            return;
+        }
+
         try
         {
             configurationService.store();
@@ -2001,7 +2051,11 @@
             throw new StoppingException( "Error storing the Continuum configuration.", e
);
         }
 
+        closeStore();
+
         stopMessage();
+
+        stopped = true;
     }
 
     public Collection getBuildResultsForProject( int projectId )

Modified: maven/continuum/branches/continuum-1.0.x/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/branches/continuum-1.0.x/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=395936&r1=395935&r2=395936&view=diff
==============================================================================
--- maven/continuum/branches/continuum-1.0.x/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
(original)
+++ maven/continuum/branches/continuum-1.0.x/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
Fri Apr 21 09:30:44 2006
@@ -37,6 +37,7 @@
 
 import javax.jdo.Extent;
 import javax.jdo.JDOHelper;
+import javax.jdo.JDOUserException;
 import javax.jdo.PersistenceManager;
 import javax.jdo.PersistenceManagerFactory;
 import javax.jdo.Query;
@@ -1301,5 +1302,53 @@
     public void removeUserGroup( UserGroup group )
     {
         removeObject( group );
+    }
+
+    public void closeStore()
+    {
+        closePersistenceManagerFactory( 1 );
+    }
+
+    /**
+     * Close the PersistenceManagerFactory.
+     *
+     * @param numTry The number of try. The maximum try is 5.
+     */
+    private void closePersistenceManagerFactory( int numTry )
+    {
+        if ( pmf != null )
+        {
+            if ( !pmf.isClosed() )
+            {
+                try
+                {
+                    pmf.close();
+                }
+                catch ( SecurityException e )
+                {
+                    throw e;
+                }
+                catch ( JDOUserException e )
+                {
+                    if ( numTry < 5 )
+                    {
+                        try
+                        {
+                            Thread.currentThread().wait( 1000 );
+                        }
+                        catch ( InterruptedException ie )
+                        {
+                            //nothing to do
+                        }
+
+                        closePersistenceManagerFactory( numTry + 1 );
+                    }
+                    else
+                    {
+                        throw e;
+                    }
+                }
+            }
+        }
     }
 }



Mime
View raw message