Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 95413 invoked from network); 16 Jul 2010 15:44:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Jul 2010 15:44:49 -0000 Received: (qmail 66942 invoked by uid 500); 16 Jul 2010 15:44:49 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66885 invoked by uid 500); 16 Jul 2010 15:44:49 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 66878 invoked by uid 99); 16 Jul 2010 15:44:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Jul 2010 15:44:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Jul 2010 15:44:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5195323889CB; Fri, 16 Jul 2010 15:43:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Fri, 16 Jul 2010 15:43:51 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100716154351.5195323889CB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Apache Directory Project + */ +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 Apache Directory Project + */ +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(); + } +}