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 2008/05/26 19:26:42 UTC
svn commit: r660238 - in
/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations:
actions/ jobs/ model/
Author: pamarcelot
Date: Mon May 26 10:26:40 2008
New Revision: 660238
URL: http://svn.apache.org/viewvc?rev=660238&view=rev
Log:
Improved Launch Configuration
Added implementation for the Stop Action.
Modified:
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceStopAction.java
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java?rev=660238&r1=660237&r2=660238&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java Mon May 26 10:26:40 2008
@@ -84,7 +84,7 @@
if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) )
{
// Getting the server instance
- ServerInstance serverInstance = ( ServerInstance ) selection.getFirstElement();
+ final ServerInstance serverInstance = ( ServerInstance ) selection.getFirstElement();
// Parsing the 'server.xml' file
ServerXmlIOV152 serverXmlIOV152 = new ServerXmlIOV152();
@@ -147,7 +147,9 @@
}
}
- LaunchServerInstanceJob job = new LaunchServerInstanceJob( serverInstance );
+ // Creating, setting and launching the launch job
+ LaunchServerInstanceJob job = new LaunchServerInstanceJob( serverInstance, serverConfiguration );
+ serverInstance.setLaunchJob( job );
job.schedule();
}
}
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceStopAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceStopAction.java?rev=660238&r1=660237&r2=660238&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceStopAction.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceStopAction.java Mon May 26 10:26:40 2008
@@ -22,10 +22,15 @@
import org.apache.directory.studio.apacheds.experimentations.ApacheDsPlugin;
import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginConstants;
+import org.apache.directory.studio.apacheds.experimentations.jobs.LaunchServerInstanceJob;
+import org.apache.directory.studio.apacheds.experimentations.model.ServerInstance;
import org.apache.directory.studio.apacheds.experimentations.views.ServersView;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
@@ -60,6 +65,34 @@
*/
public void run()
{
+ // Getting the selection
+ StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection();
+ if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) )
+ {
+ // Getting the server
+ ServerInstance server = ( ServerInstance ) selection.getFirstElement();
+
+ // Getting the launch job
+ LaunchServerInstanceJob launchJob = server.getLaunchJob();
+ if ( launchJob != null )
+ {
+ // Getting the launch
+ ILaunch launch = launchJob.getLaunch();
+ if ( ( launch != null ) && ( !launch.isTerminated() ) )
+ {
+ // Terminating the launch
+ try
+ {
+ launch.terminate();
+ }
+ catch ( DebugException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
}
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java?rev=660238&r1=660237&r2=660238&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java Mon May 26 10:26:40 2008
@@ -21,16 +21,17 @@
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
-import org.apache.directory.studio.apacheds.configuration.model.ServerXmlIOException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+
import org.apache.directory.studio.apacheds.configuration.model.v152.ServerConfigurationV152;
-import org.apache.directory.studio.apacheds.configuration.model.v152.ServerXmlIOV152;
import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginUtils;
import org.apache.directory.studio.apacheds.experimentations.ConsolesHandler;
import org.apache.directory.studio.apacheds.experimentations.LogMessageConsole;
@@ -45,21 +46,23 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
+
+import sun.security.action.GetLongAction;
/**
@@ -70,42 +73,55 @@
*/
public class LaunchServerInstanceJob extends Job
{
+ /** The server */
+ private ServerInstance server;
+
+ /** The configuration */
+ private ServerConfigurationV152 configuration;
+
+ /** The launch that will be created when running the server */
+ private ILaunch launch;
+
+ /** The minimum port number for the socket server */
private static final int MIN_PORT = 1024;
- /** The server instance */
- private ServerInstance serverInstance;
/**
* Creates a new instance of LaunchServerInstanceJob.
+ *
+ * @param server
+ * the server
+ * @param configuration
+ * the configuration
*/
- public LaunchServerInstanceJob( ServerInstance serverInstance )
+ public LaunchServerInstanceJob( ServerInstance server, ServerConfigurationV152 configuration )
{
super( "" );
- this.serverInstance = serverInstance;
+ this.server = server;
+ this.configuration = configuration;
}
/*
* (non-Javadoc)
- *
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run( IProgressMonitor monitor )
{
// Setting the name of the Job
- setName( "Starting " + serverInstance.getName() + "..." );
+ setName( "Starting " + server.getName() + "..." );
// Setting the server in a "starting" state
- serverInstance.setState( ServerStateEnum.STARTING );
+ server.setState( ServerStateEnum.STARTING );
Display.getDefault().asyncExec( new Runnable()
{
public void run()
{
- LogMessageConsole console = ConsolesHandler.getDefault().getLogMessageConsole( serverInstance.getId() );
+ LogMessageConsole console = ConsolesHandler.getDefault().getLogMessageConsole( server.getId() );
try
{
- console.getInfoConsoleMessageStream().write( "Starting " + serverInstance.getName() + "...\n" );
+ console.getInfoConsoleMessageStream().write( "Starting " + server.getName() + "...\n" );
}
catch ( IOException e )
{
@@ -135,18 +151,153 @@
// Launching Apache DS
launchApacheDS();
- try
+ // Starting the startup listener thread
+ startStartupListenerThread();
+
+ // Starting the "terminate" listener thread
+ startTerminateListenerThread();
+
+ return Status.OK_STATUS;
+ }
+
+
+ /**
+ * Starts the startup listener thread.
+ */
+ private void startStartupListenerThread()
+ {
+ // Getting the current time
+ long startTime = System.currentTimeMillis();
+
+ // Calculating the watch dog time
+ final long watchDog = startTime + ( 1000 * 60 * 1 ); // 3 minutes
+
+ // Creating the thread
+ Thread thread = new Thread()
{
- Thread.sleep( 1000 );
- }
- catch ( InterruptedException e )
+ public void run()
+ {
+ // Looping until the end of the watchdog
+ while ( ( System.currentTimeMillis() < watchDog ) && ( ServerStateEnum.STARTING == server.getState() ) )
+ {
+ try
+ {
+ // Let's try to create a context on the server
+ createInitialDirContext();
+
+ // If we pass the creation of the context, it means
+ // the server is correctly started
+
+ // We set the state of the server to 'started'...
+ server.setState( ServerStateEnum.STARTED );
+
+ /// ... and we exit the thread
+ return;
+ }
+ catch ( NamingException e )
+ {
+ // If we get an exception when trying to create the
+ // context, it means the server is not yest started
+
+ // We just wait one second before starting the test once again
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch ( InterruptedException e1 )
+ {
+ // Nothing to do...
+ }
+ }
+ }
+
+ // If at the end of the watch dog the state of the server is
+ // still 'starting' then, we declare the server as 'stopped'
+ if ( ServerStateEnum.STARTING == server.getState() )
+ {
+ server.setState( ServerStateEnum.STOPPED );
+ }
+ }
+
+
+ /**
+ * Creates a context on the server.
+ *
+ * @throws NamingException
+ * if an error occurs when creating the context
+ */
+ private void createInitialDirContext() throws NamingException
+ {
+ Hashtable<String, String> environment = new Hashtable<String, String>();
+ environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); //$NON-NLS-1$
+ environment.put( "java.naming.ldap.version", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
+ environment.put( Context.PROVIDER_URL, "ldap://" + "localhost" + ":" + configuration.getLdapPort() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ InitialLdapContext context = new InitialLdapContext( environment, null );
+ context.close();
+ }
+ };
+
+ // Starting the thread
+ thread.start();
+ }
+
+
+ /**
+ * Starting the "terminate" listener thread.
+ */
+ private void startTerminateListenerThread()
+ {
+ // Creating the thread
+ Thread thread = new Thread()
{
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- serverInstance.setState( ServerStateEnum.STARTED );
+ /** The debug event listener */
+ private IDebugEventSetListener debugEventSetListener;
- return Status.OK_STATUS;
+
+ public void run()
+ {
+ // Creating the listener
+ debugEventSetListener = new IDebugEventSetListener()
+ {
+ public void handleDebugEvents( DebugEvent[] events )
+ {
+ // Looping on the debug events array
+ for ( DebugEvent debugEvent : events )
+ {
+ // We only care of event with kind equals to 'terminate'
+ if ( debugEvent.getKind() == DebugEvent.TERMINATE )
+ {
+ // Getting the source of the debug event
+ Object source = debugEvent.getSource();
+ if ( source instanceof RuntimeProcess )
+ {
+ RuntimeProcess runtimeProcess = ( RuntimeProcess ) source;
+
+ // Getting the associated launch
+ ILaunch debugEventLaunch = runtimeProcess.getLaunch();
+ if ( debugEventLaunch.equals( launch ) )
+ {
+ // The launch we had created is now terminated
+ // The server is now stopped
+ server.setState( ServerStateEnum.STOPPED );
+
+ // Removing the listener
+ DebugPlugin.getDefault().addDebugEventListener( debugEventSetListener );
+ }
+ }
+ }
+ }
+ }
+ };
+
+ // Adding the listener
+ DebugPlugin.getDefault().addDebugEventListener( debugEventSetListener );
+ }
+ };
+
+ // Starting the thread
+ thread.start();
}
@@ -162,8 +313,8 @@
private void launchSocketServer( int port )
{
final int finalPort = port;
- final IPath serverSocketFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append(
- serverInstance.getId() ).append( "serverSocket" );
+ final IPath serverSocketFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append( server.getId() )
+ .append( "serverSocket" );
final IPath log4jPropertiesFilePath = serverSocketFolderPath.append( "log4j.properties" );
// Creating a new thread for the SocketServer
@@ -191,7 +342,7 @@
*/
private void overwriteServerInstanceLog4jPropertiesFile( int port ) throws IOException
{
- IPath confFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append( serverInstance.getId() )
+ IPath confFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append( server.getId() )
.append( "conf" );
File confFolder = new File( confFolderPath.toOSString() );
ApacheDsPluginUtils.createServerInstanceLog4jPropertiesFile( new FileOutputStream( new File( confFolder,
@@ -214,7 +365,7 @@
ILaunchConfigurationWorkingCopy workingCopy = null;
try
{
- workingCopy = type.newInstance( null, "Starting " + serverInstance.getName() );
+ workingCopy = type.newInstance( null, "Starting " + server.getName() );
}
catch ( CoreException e )
{
@@ -251,13 +402,14 @@
// Setting the classpath type attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath );
+ workingCopy.setAttribute( DebugPlugin.ATTR_CAPTURE_OUTPUT, false );
// Setting the default classpath type attribute to false
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false );
// Useful paths
IPath instancesFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder();
- IPath instanceFolderPath = instancesFolderPath.append( serverInstance.getId() );
+ IPath instanceFolderPath = instancesFolderPath.append( server.getId() );
// Setting the program arguments attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, instanceFolderPath.append(
@@ -274,7 +426,8 @@
vmArguments.append( " " );
vmArguments.append( "-Dapacheds.run.dir=" + instanceFolderPath.append( "run" ).toOSString() );
vmArguments.append( " " );
- vmArguments.append( "-Dapacheds.instance=" + serverInstance.getName() );
+ vmArguments.append( "-Dapacheds.instance=" + server.getName() );
+ // vmArguments.append( "-Dorg.eclipse.debug.core.capture_output=false" );
// Setting the VM arguments attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArguments.toString() );
@@ -296,13 +449,24 @@
// Launching the launch configuration
try
{
- configuration.launch( ILaunchManager.RUN_MODE, new NullProgressMonitor() );
+ launch = configuration.launch( ILaunchManager.RUN_MODE, new NullProgressMonitor() );
}
catch ( CoreException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
- // DebugUITools.launch( configuration, ILaunchManager.RUN_MODE );
+ }
+
+
+ /**
+ * Gets the associated launch.
+ *
+ * @return
+ * the associated launch
+ */
+ public ILaunch getLaunch()
+ {
+ return launch;
}
}
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java?rev=660238&r1=660237&r2=660238&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java Mon May 26 10:26:40 2008
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.UUID;
+import org.apache.directory.studio.apacheds.experimentations.jobs.LaunchServerInstanceJob;
import org.eclipse.core.runtime.IAdaptable;
@@ -44,8 +45,12 @@
/** The state of the instance */
private ServerStateEnum state = ServerStateEnum.STOPPED;
+ /** The listeners list*/
private List<ServerListener> listeners = new ArrayList<ServerListener>();
+ /** The launch job */
+ private LaunchServerInstanceJob launchJob;
+
/**
* Creates a new instance of ApacheDsInstance.
@@ -55,6 +60,12 @@
}
+ /**
+ * Adds a listener.
+ *
+ * @param listener
+ * the listener
+ */
public void addListener( ServerListener listener )
{
if ( listener == null )
@@ -66,6 +77,12 @@
}
+ /**
+ * Removes a listener.
+ *
+ * @param listener
+ * the listener
+ */
public void removeListener( ServerListener listener )
{
if ( listener == null )
@@ -218,7 +235,7 @@
/**
- * Fire a server listener state change event.
+ * Fires a server listener state change event.
*/
private void fireServerStateChangeEvent()
{
@@ -229,6 +246,30 @@
}
+ /**
+ * Gets the launch job.
+ *
+ * @return
+ * the launch job
+ */
+ public LaunchServerInstanceJob getLaunchJob()
+ {
+ return launchJob;
+ }
+
+
+ /**
+ * Sets the launch job.
+ *
+ * @param launchJob
+ * the launch job
+ */
+ public void setLaunchJob( LaunchServerInstanceJob launchJob )
+ {
+ this.launchJob = launchJob;
+ }
+
+
public Object getAdapter( Class adapter )
{
// TODO Auto-generated method stub