You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/07/16 17:43:51 UTC

svn commit: r964841 - in /directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs: StartLdapServerJob.java StartLdapServerWatchDogThread.java StopLdapServerJob.java StopLdapServerWatchDogThread.java

Author: pamarcelot
Date: Fri Jul 16 15:43:50 2010
New Revision: 964841

URL: http://svn.apache.org/viewvc?rev=964841&view=rev
Log:
Added a Start and Stop watchdog threads.

Added:
    directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java
    directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java
Modified:
    directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerJob.java
    directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerJob.java

Modified: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerJob.java?rev=964841&r1=964840&r2=964841&view=diff
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerJob.java (original)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerJob.java Fri Jul 16 15:43:50 2010
@@ -56,10 +56,8 @@ public class StartLdapServerJob extends 
     }
 
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+    /**
+     * {@inheritDoc}
      */
     protected IStatus run( IProgressMonitor monitor )
     {
@@ -69,6 +67,10 @@ public class StartLdapServerJob extends 
         // Setting the status on the server to 'starting'
         server.setStatus( LdapServerStatus.STARTING );
 
+        // Starting a new watchdog thread
+        StartLdapServerWatchDogThread.runNewWatchDogThread( server );
+
+        // Launching the 'start()' method of the LDAP Server Adapter
         LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension();
         if ( ldapServerAdapterExtension != null )
         {
@@ -87,18 +89,6 @@ public class StartLdapServerJob extends 
             }
         }
 
-        // TODO remove this
-        try
-        {
-            Thread.sleep( 3000 );
-        }
-        catch ( InterruptedException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        server.setStatus( LdapServerStatus.STARTED );
-
         return Status.OK_STATUS;
     }
 }

Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java?rev=964841&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java Fri Jul 16 15:43:50 2010
@@ -0,0 +1,101 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapservers.jobs;
+
+
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.apache.directory.studio.ldapservers.model.LdapServerStatus;
+
+
+/**
+ * This class implements a {@link Thread} that is used as a watch for the start of an LDAP Server.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StartLdapServerWatchDogThread extends Thread
+{
+    /** The server */
+    private LdapServer server;
+
+
+    /**
+     * Creates a new instance of StartLdapServerJob.
+     * 
+     * @param server
+     *            the LDAP Server
+     */
+    private StartLdapServerWatchDogThread( LdapServer server )
+    {
+        super();
+        this.server = server;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        // Getting the current time
+        long startTime = System.currentTimeMillis();
+
+        // Calculating the watchdog time
+        final long watchDog = startTime + ( 1000 * 60 * 1 ); // 3 minutes
+
+        // Looping until the end of the watchdog time or when the server status is no longer 'starting'
+        while ( ( System.currentTimeMillis() < watchDog ) && ( LdapServerStatus.STARTING == server.getStatus() ) )
+        {
+            // We just wait one second before starting the test once
+            // again
+            try
+            {
+                Thread.sleep( 1000 );
+            }
+            catch ( InterruptedException e1 )
+            {
+                // Nothing to do...
+            }
+        }
+
+        // We exited from the waiting loop
+
+        // Checking if the watchdog time is expired
+        if ( ( System.currentTimeMillis() >= watchDog ) && ( LdapServerStatus.STARTING == server.getStatus() ) )
+        {
+            // TODO Display an error message...
+
+            // Setting the status of the server to 'Stopped'
+            server.setStatus( LdapServerStatus.STOPPED );
+        }
+    }
+
+
+    /**
+     * Runs a new watchdog thread with the given LDAP Server.
+     *
+     * @param server
+     *      the LDAP Server
+     */
+    public static void runNewWatchDogThread( LdapServer server )
+    {
+        new StartLdapServerWatchDogThread( server ).start();
+    }
+}

Modified: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerJob.java?rev=964841&r1=964840&r2=964841&view=diff
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerJob.java (original)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerJob.java Fri Jul 16 15:43:50 2010
@@ -56,10 +56,8 @@ public class StopLdapServerJob extends J
     }
 
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+    /**
+     * {@inheritDoc}
      */
     protected IStatus run( IProgressMonitor monitor )
     {
@@ -69,6 +67,10 @@ public class StopLdapServerJob extends J
         // Setting the status on the server to 'stopping'
         server.setStatus( LdapServerStatus.STOPPING );
 
+        // Starting a new watchdog thread
+        StopLdapServerWatchDogThread.runNewWatchDogThread( server );
+
+        // Launching the 'stop()' of the LDAP Server Adapter
         LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension();
         if ( ldapServerAdapterExtension != null )
         {
@@ -87,18 +89,6 @@ public class StopLdapServerJob extends J
             }
         }
 
-        // TODO remove this
-        try
-        {
-            Thread.sleep( 3000 );
-        }
-        catch ( InterruptedException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        server.setStatus( LdapServerStatus.STOPPED );
-
         return Status.OK_STATUS;
     }
 }

Added: directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java?rev=964841&view=auto
==============================================================================
--- directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java (added)
+++ directory/studio/trunk/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java Fri Jul 16 15:43:50 2010
@@ -0,0 +1,101 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldapservers.jobs;
+
+
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.apache.directory.studio.ldapservers.model.LdapServerStatus;
+
+
+/**
+ * This class implements a {@link Thread} that is used as a watch for the stop of an LDAP Server.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StopLdapServerWatchDogThread extends Thread
+{
+    /** The server */
+    private LdapServer server;
+
+
+    /**
+     * Creates a new instance of StopLdapServerWatchDogThread.
+     * 
+     * @param server
+     *            the LDAP Server
+     */
+    private StopLdapServerWatchDogThread( LdapServer server )
+    {
+        super();
+        this.server = server;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        // Getting the current time
+        long startTime = System.currentTimeMillis();
+
+        // Calculating the watchdog time
+        final long watchDog = startTime + ( 1000 * 60 * 1 ); // 3 minutes
+
+        // Looping until the end of the watchdog time or when the server status is no longer 'starting'
+        while ( ( System.currentTimeMillis() < watchDog ) && ( LdapServerStatus.STOPPING == server.getStatus() ) )
+        {
+            // We just wait one second before starting the test once
+            // again
+            try
+            {
+                Thread.sleep( 1000 );
+            }
+            catch ( InterruptedException e1 )
+            {
+                // Nothing to do...
+            }
+        }
+
+        // We exited from the waiting loop
+
+        // Checking if the watchdog time is expired
+        if ( ( System.currentTimeMillis() >= watchDog ) && ( LdapServerStatus.STOPPING == server.getStatus() ) )
+        {
+            // TODO Display an error message...
+
+            // Setting the status of the server to 'Started'
+            server.setStatus( LdapServerStatus.STARTED );
+        }
+    }
+
+
+    /**
+     * Runs a new watchdog thread with the given LDAP Server.
+     *
+     * @param server
+     *      the LDAP Server
+     */
+    public static void runNewWatchDogThread( LdapServer server )
+    {
+        new StopLdapServerWatchDogThread( server ).start();
+    }
+}