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/07 12:06:40 UTC
svn commit: r654061 - in
/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations:
./ META-INF/ lib/
src/main/java/org/apache/directory/studio/apacheds/experimentations/
src/main/java/org/apache/directory/studio/apacheds/ex...
Author: pamarcelot
Date: Wed May 7 03:06:38 2008
New Revision: 654061
URL: http://svn.apache.org/viewvc?rev=654061&view=rev
Log:
o Added a ConsolesHandler class
o Updated the LaunchService to register a Log4J SocketServer which will help redirecting the logs to the Studio Console.
Added:
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/mina-core-1.1.6.jar (with props)
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ConsolesHandler.java
Removed:
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/resources/log4j.properties
Modified:
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPlugin.java
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/StudioConsoleAppender.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/ServersHandler.java
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath Wed May 7 03:06:38 2008
@@ -9,5 +9,6 @@
<classpathentry kind="lib" path="lib/slf4j-api-1.4.3.jar"/>
<classpathentry kind="lib" path="lib/slf4j-log4j12-1.4.3.jar"/>
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
+ <classpathentry kind="lib" path="lib/mina-core-1.1.6.jar"/>
<classpathentry kind="output" path="target"/>
</classpath>
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF Wed May 7 03:06:38 2008
@@ -17,4 +17,5 @@
lib/log4j-1.2.14.jar,
lib/slf4j-api-1.4.3.jar,
lib/slf4j-log4j12-1.4.3.jar,
- lib/dom4j-1.6.1.jar
+ lib/dom4j-1.6.1.jar,
+ lib/mina-core-1.1.6.jar
Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/mina-core-1.1.6.jar
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/mina-core-1.1.6.jar?rev=654061&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/mina-core-1.1.6.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPlugin.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/ApacheDsPlugin.java?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPlugin.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPlugin.java Wed May 7 03:06:38 2008
@@ -30,9 +30,6 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.console.ConsolePlugin;
-import org.eclipse.ui.console.IConsole;
-import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -51,9 +48,6 @@
/** The servers handler */
private ServersHandler serversHandler;
- private static Logger logger = Logger.getLogger( ApacheDsPlugin.class );
- private LogMessageConsole logMessageConsole;
-
/**
* The constructor
@@ -91,14 +85,6 @@
// Verifying the libraries in the plugin's folder
ApacheDsPluginUtils.verifyLibrariesFolder();
-
- // Configuring Log4J
-// PropertyConfigurator.configure( Platform.getBundle( PLUGIN_ID ).getResource( "log4j.properties" ) ); //$NON-NLS-1$
- logger.info( "Sending INFO Message..." ); //$NON-NLS-1$
- logger.debug( "Sending DEBUG Message..." ); //$NON-NLS-1$
- logger.warn( "Sending WARN Message..." ); //$NON-NLS-1$
- logger.error( "Sending ERROR Message..." ); //$NON-NLS-1$
- logger.fatal( "Sending FATAL Message..." ); //$NON-NLS-1$
}
@@ -114,25 +100,6 @@
/**
- * Gets the log message console.
- *
- * @return
- * the log message console
- */
- public LogMessageConsole getLogMessageConsole()
- {
- if ( logMessageConsole == null )
- {
- logMessageConsole = new LogMessageConsole( "Apache DS", null );
- ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[]
- { logMessageConsole } );
- }
-
- return logMessageConsole;
- }
-
-
- /**
* Use this method to get SWT images. Use the IMG_ constants from
* PluginConstants for the key.
*
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.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/ApacheDsPluginUtils.java?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java Wed May 7 03:06:38 2008
@@ -127,8 +127,8 @@
private static void copyLibrary( String library, File destination ) throws IOException
{
// Getting he URL of the library within the bundle
- URL libraryUrl = FileLocator.find( ApacheDsPlugin.getDefault().getBundle(), new Path( RESOURCES + IPath.SEPARATOR
- + LIBS + IPath.SEPARATOR + library ), null );
+ URL libraryUrl = FileLocator.find( ApacheDsPlugin.getDefault().getBundle(), new Path( RESOURCES
+ + IPath.SEPARATOR + LIBS + IPath.SEPARATOR + library ), null );
// Creating the input and output streams
InputStream libraryInputStream = libraryUrl.openStream();
@@ -208,6 +208,8 @@
// Creating the instance sub folders
File confFolder = new File( instanceFolder, "conf" );
confFolder.mkdir();
+ File serverSocketFolder = new File( instanceFolder, "serverSocket" );
+ serverSocketFolder.mkdir();
new File( instanceFolder, "ldif" ).mkdir();
new File( instanceFolder, "log" ).mkdir();
new File( instanceFolder, "partitions" ).mkdir();
@@ -221,11 +223,15 @@
// Copying log4j.properties file
File log4jPropertiesFile = new File( confFolder, "log4j.properties" );
- copyConfigurationFile( "log4j.properties", log4jPropertiesFile );
+ createServerInstanceLog4jPropertiesFile( new FileOutputStream( log4jPropertiesFile ), id, 1024 ); // Setting 1024 as default port
// Copying server.xml file
File serverXmlFile = new File( confFolder, "server.xml" );
copyConfigurationFile( "server.xml", serverXmlFile );
+
+ // Creating log4j.properties file to the serverSocket folder
+ File log4jPropertiesServerSocketFile = new File( serverSocketFolder, "log4j.properties" );
+ createServerSocketLog4jPropertiesFile( new FileOutputStream( log4jPropertiesServerSocketFile ), id );
}
catch ( IOException e )
{
@@ -236,6 +242,103 @@
/**
+ * Create the log4j.properties file for the server socket logger.
+ *
+ * @param os
+ * the {@link OutputStream} to write to
+ * @param id
+ * the id of the server instance
+ * @throws IOException
+ * if an error occurs when writing to the file
+ */
+ public static void createServerInstanceLog4jPropertiesFile( OutputStream os, String id, int port )
+ throws IOException
+ {
+ // Creating the file content in a StringBuffer
+ StringBuffer sb = new StringBuffer();
+ sb.append( "#############################################################################" ).append( "\n" );
+ sb.append( "# Licensed to the Apache Software Foundation (ASF) under one or more" ).append( "\n" );
+ sb.append( "# contributor license agreements. See the NOTICE file distributed with" ).append( "\n" );
+ sb.append( "# this work for additional information regarding copyright ownership." ).append( "\n" );
+ sb.append( "# The ASF licenses this file to You under the Apache License, Version 2.0" ).append( "\n" );
+ sb.append( "# (the \"License\"); you may not use this file except in compliance with" ).append( "\n" );
+ sb.append( "# the License. You may obtain a copy of the License at" ).append( "\n" );
+ sb.append( "#" ).append( "\n" );
+ sb.append( "# http://www.apache.org/licenses/LICENSE-2.0" ).append( "\n" );
+ sb.append( "#" ).append( "\n" );
+ sb.append( "# Unless required by applicable law or agreed to in writing, software" ).append( "\n" );
+ sb.append( "# distributed under the License is distributed on an \"AS IS\" BASIS," ).append( "\n" );
+ sb.append( "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." ).append( "\n" );
+ sb.append( "# See the License for the specific language governing permissions and" ).append( "\n" );
+ sb.append( "# limitations under the License." ).append( "\n" );
+ sb.append( "#############################################################################" ).append( "\n" );
+ sb.append( "log4j.rootCategory=WARN, socketAppender" ).append( "\n" );
+ sb.append( "" ).append( "\n" );
+ sb.append( "log4j.appender.socketAppender=org.apache.log4j.net.SocketAppender" ).append( "\n" );
+ sb.append( "log4j.appender.socketAppender.RemoteHost=localhost" ).append( "\n" );
+ sb.append( "log4j.appender.socketAppender.Port=" ).append( port ).append( "\n" );
+ sb.append( "" ).append( "\n" );
+ sb.append( "# with these we'll not get innundated when switching to DEBUG" ).append( "\n" );
+ sb.append( "log4j.logger.org.apache.directory.shared.ldap.name=WARN" ).append( "\n" );
+ sb.append( "log4j.logger.org.springframework=WARN" ).append( "\n" );
+ sb.append( "log4j.logger.org.apache.directory.shared.codec=WARN" ).append( "\n" );
+ sb.append( "log4j.logger.org.apache.directory.shared.asn1=WARN" ).append( "\n" );
+
+ // Writing the content to the file
+ os.write( sb.toString().getBytes() );
+ }
+
+
+ /**
+ * Create the log4j.properties file for the server socket logger.
+ *
+ * @param os
+ * the {@link OutputStream} to write to
+ * @param id
+ * the id of the server instance
+ * @throws IOException
+ * if an error occurs when writing to the file
+ */
+ private static void createServerSocketLog4jPropertiesFile( OutputStream os, String id ) throws IOException
+ {
+ // Creating the file content in a StringBuffer
+ StringBuffer sb = new StringBuffer();
+ sb.append( "#############################################################################" ).append( "\n" );
+ sb.append( "# Licensed to the Apache Software Foundation (ASF) under one or more" ).append( "\n" );
+ sb.append( "# contributor license agreements. See the NOTICE file distributed with" ).append( "\n" );
+ sb.append( "# this work for additional information regarding copyright ownership." ).append( "\n" );
+ sb.append( "# The ASF licenses this file to You under the Apache License, Version 2.0" ).append( "\n" );
+ sb.append( "# (the \"License\"); you may not use this file except in compliance with" ).append( "\n" );
+ sb.append( "# the License. You may obtain a copy of the License at" ).append( "\n" );
+ sb.append( "#" ).append( "\n" );
+ sb.append( "# http://www.apache.org/licenses/LICENSE-2.0" ).append( "\n" );
+ sb.append( "#" ).append( "\n" );
+ sb.append( "# Unless required by applicable law or agreed to in writing, software" ).append( "\n" );
+ sb.append( "# distributed under the License is distributed on an \"AS IS\" BASIS," ).append( "\n" );
+ sb.append( "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." ).append( "\n" );
+ sb.append( "# See the License for the specific language governing permissions and" ).append( "\n" );
+ sb.append( "# limitations under the License." ).append( "\n" );
+ sb.append( "#############################################################################" ).append( "\n" );
+ sb.append( "log4j.rootCategory=ALL, studioConsoleAppender" ).append( "\n" );
+ sb.append( "" ).append( "\n" );
+ sb.append( "# Studio Console Appender (identified with the server instance id)" ).append( "\n" );
+ sb
+ .append(
+ "log4j.appender.studioConsoleAppender=org.apache.directory.studio.apacheds.experimentations.StudioConsoleAppender" )
+ .append( "\n" );
+ sb.append( "log4j.appender.studioConsoleAppender.ServerInstanceId=" ).append( id ).append( "\n" );
+ sb.append( "log4j.appender.studioConsoleAppender.layout=org.apache.log4j.PatternLayout" ).append( "\n" );
+ sb.append( "" ).append( "\n" );
+ sb.append( "# Hiding logs from log4j" ).append( "\n" );
+ sb.append( "log4j.logger.org.apache.log4j.net.SocketServer=OFF" ).append( "\n" );
+ sb.append( "log4j.logger.org.apache.log4j.net.SocketNode=OFF" ).append( "\n" );
+
+ // Writing the content to the file
+ os.write( sb.toString().getBytes() );
+ }
+
+
+ /**
* Copies a configuration file.
*
* @param inputFilename
Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ConsolesHandler.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/ConsolesHandler.java?rev=654061&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ConsolesHandler.java (added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ConsolesHandler.java Wed May 7 03:06:38 2008
@@ -0,0 +1,105 @@
+/*
+ * 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.apacheds.experimentations;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.studio.apacheds.experimentations.model.ServerInstance;
+import org.apache.directory.studio.apacheds.experimentations.model.ServersHandler;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+
+
+/**
+ * This class implements the consoles handler.
+ * <p>
+ *
+ * It is used to store all the consoles associated to server instances.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConsolesHandler
+{
+ /** The default instance */
+ private static ConsolesHandler instance;
+
+ /** The map of consoles identified by server instance ID */
+ private Map<String, LogMessageConsole> consolesMap;
+
+
+ /**
+ * Creates a new instance of ConsolesHandler.
+ */
+ private ConsolesHandler()
+ {
+ // Initialization of the map
+ consolesMap = new HashMap<String, LogMessageConsole>();
+ }
+
+
+ /**
+ * Gets the default consoles handler (singleton pattern).
+ *
+ * @return
+ * the default consoles handler
+ */
+ public static ConsolesHandler getDefault()
+ {
+ if ( instance == null )
+ {
+ instance = new ConsolesHandler();
+ }
+
+ return instance;
+ }
+
+
+ /**
+ * Gets the log message console associated with the if of the server instance.
+ *
+ * @param serverInstanceId
+ * the id of the server instance
+ * @return
+ * the associated log message console.
+ */
+ public LogMessageConsole getLogMessageConsole( String serverInstanceId )
+ {
+ if ( consolesMap.containsKey( serverInstanceId ) )
+ {
+ return consolesMap.get( serverInstanceId );
+ }
+ else
+ {
+ ServerInstance serverInstance = ServersHandler.getDefault().getServerInstanceById( serverInstanceId );
+
+ LogMessageConsole logMessageConsole = new LogMessageConsole( serverInstance.getName() );
+
+ consolesMap.put( serverInstanceId, logMessageConsole );
+
+ ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[]
+ { logMessageConsole } );
+
+ return logMessageConsole;
+ }
+ }
+}
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/StudioConsoleAppender.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/StudioConsoleAppender.java?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/StudioConsoleAppender.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/StudioConsoleAppender.java Wed May 7 03:06:38 2008
@@ -34,43 +34,47 @@
*/
public class StudioConsoleAppender extends AppenderSkeleton
{
+ /** The id of the server instance */
+ private String serverInstanceId;
+
+
+ /**
+ * Creates a new instance of StudioConsoleAppender.
+ */
public StudioConsoleAppender()
{
- System.out.println( "Create Logger");
}
-
+
+
/* (non-Javadoc)
* @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
*/
protected void append( LoggingEvent event )
{
+ LogMessageConsole console = ConsolesHandler.getDefault().getLogMessageConsole( serverInstanceId );
+
Level level = event.getLevel();
Object message = event.getMessage();
if ( level == Level.INFO )
{
- ApacheDsPlugin.getDefault().getLogMessageConsole().getInfoConsoleMessageStream().println(
- message.toString() );
+ console.getInfoConsoleMessageStream().println( message.toString() );
}
else if ( level == Level.DEBUG )
{
- ApacheDsPlugin.getDefault().getLogMessageConsole().getDebugConsoleMessageStream().println(
- message.toString() );
+ console.getDebugConsoleMessageStream().println( message.toString() );
}
else if ( level == Level.WARN )
{
- ApacheDsPlugin.getDefault().getLogMessageConsole().getWarnConsoleMessageStream().println(
- message.toString() );
+ console.getWarnConsoleMessageStream().println( message.toString() );
}
else if ( level == Level.ERROR )
{
- ApacheDsPlugin.getDefault().getLogMessageConsole().getErrorConsoleMessageStream().println(
- message.toString() );
+ console.getErrorConsoleMessageStream().println( message.toString() );
}
else if ( level == Level.FATAL )
{
- ApacheDsPlugin.getDefault().getLogMessageConsole().getFatalConsoleMessageStream().println(
- message.toString() );
+ console.getFatalConsoleMessageStream().println( message.toString() );
}
}
@@ -93,4 +97,28 @@
// TODO Auto-generated method stub
return false;
}
+
+
+ /**
+ * Gets the id of the server instance.
+ *
+ * @return
+ * the id of the server instance
+ */
+ public String getServerInstanceId()
+ {
+ return serverInstanceId;
+ }
+
+
+ /**
+ * Sets the id of the server instance.
+ *
+ * @param serverInstanceId
+ * the id of the server instance
+ */
+ public void setServerInstanceId( String serverInstanceId )
+ {
+ this.serverInstanceId = serverInstanceId;
+ }
}
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=654061&r1=654060&r2=654061&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 Wed May 7 03:06:38 2008
@@ -20,11 +20,20 @@
package org.apache.directory.studio.apacheds.experimentations.jobs;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.directory.studio.apacheds.experimentations.ApacheDsPlugin;
import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginUtils;
+import org.apache.directory.studio.apacheds.experimentations.ConsolesHandler;
+import org.apache.directory.studio.apacheds.experimentations.LogMessageConsole;
import org.apache.directory.studio.apacheds.experimentations.model.ServerInstance;
+import org.apache.log4j.net.SocketServer;
+import org.apache.mina.util.AvailablePortFinder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -41,8 +50,7 @@
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
-
-import com.sun.org.apache.xpath.internal.Arg;
+import org.eclipse.swt.widgets.Display;
/**
@@ -53,6 +61,7 @@
*/
public class LaunchServerInstanceJob extends Job
{
+ private static final int MIN_PORT = 1024;
/** The server instance */
private ServerInstance serverInstance;
@@ -72,18 +81,102 @@
*/
protected IStatus run( IProgressMonitor monitor )
{
- setName( "Starting " + serverInstance.getName() );
+ // Setting the name of the Job
+ setName( "Starting " + serverInstance.getName() + "..." );
+
+ Display.getDefault().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ LogMessageConsole console = ConsolesHandler.getDefault().getLogMessageConsole( serverInstance.getId() );
+ try
+ {
+ console.getInfoConsoleMessageStream().write( "Starting " + serverInstance.getName() + "...\n" );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ } );
+
+ // Getting the first available port for the Log4J socket server
+ int port = AvailablePortFinder.getNextAvailable( MIN_PORT );
+
+ // Launching the socket server
+ launchSocketServer( port );
+
+ // Overwriting the server instance log4j.properties file
+ overwriteServerInstanceLog4jPropertiesFile( port );
+
+ // Launching Apache DS
+ launchApacheDS();
+
+ return Status.OK_STATUS;
+ }
+
+
+ /**
+ * Launches a Log4J {@link SocketServer} which will be used to redirect
+ * the logs of Apache DS to the console.
+ *
+ * @param port
+ * the port
+ * @param
+ *
+ */
+ private void launchSocketServer( int port )
+ {
+ final int finalPort = port;
+ final IPath serverSocketFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append(
+ serverInstance.getId() ).append( "serverSocket" );
+ final IPath log4jPropertiesFilePath = serverSocketFolderPath.append( "log4j.properties" );
+ // Creating a new thread for the SocketServer
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ SocketServer.main( new String[]
+ { "" + finalPort, log4jPropertiesFilePath.toOSString(), serverSocketFolderPath.toOSString() } );
+ }
+ };
+
+ // Launching the SocketServer
+ thread.start();
+ }
+
+
+ /**
+ * Overwrites the log4j.properties file of the server instance with the given port number.
+ *
+ * @param port
+ * the port
+ */
+ private void overwriteServerInstanceLog4jPropertiesFile( int port )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ /**
+ * Launches Apache DS using a launch configuration.
+ */
+ private void launchApacheDS()
+ {
+ // Getting the default VM installation
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
- // Testing the launch configuration
+ // Creating a new editable launch configuration
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager
.getLaunchConfigurationType( IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION );
ILaunchConfigurationWorkingCopy workingCopy = null;
try
{
- workingCopy = type.newInstance( null, "Start ApacheDS" );
+ workingCopy = type.newInstance( null, "Starting " + serverInstance.getName() );
}
catch ( CoreException e )
{
@@ -91,16 +184,18 @@
e.printStackTrace();
}
+ // Setting the JRE container path attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, vmInstall
.getInstallLocation().toString() );
+
+ // Setting the main type attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"org.apache.directory.server.UberjarMain" );
- String[] libraries = ApacheDsPluginUtils.apachedsLibraries;
- IPath apacheDsLibrariesFolder = ApacheDsPluginUtils.getApacheDsLibrariesFolder();
-
+ // Creating the classpath list
List classpath = new ArrayList();
- for ( String library : libraries )
+ IPath apacheDsLibrariesFolder = ApacheDsPluginUtils.getApacheDsLibrariesFolder();
+ for ( String library : ApacheDsPluginUtils.apachedsLibraries )
{
IPath libraryPath = apacheDsLibrariesFolder.append( library );
IRuntimeClasspathEntry libraryClasspathEntry = JavaRuntime.newArchiveRuntimeClasspathEntry( libraryPath );
@@ -116,15 +211,21 @@
}
}
+ // Setting the classpath type attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath );
+
+ // Setting the default classpath type attribute to false
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false );
+ // Useful path
IPath instancesFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder();
IPath instanceFolderPath = instancesFolderPath.append( serverInstance.getId() );
+ // Setting the program arguments attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, instanceFolderPath.append(
"conf" ).append( "server.xml" ).toOSString() );
+ // Creating the VM arguments string
StringBuffer vmArguments = new StringBuffer();
vmArguments.append( "-Dlog4j.configuration=file:"
+ instanceFolderPath.append( "conf" ).append( "log4j.properties" ).toOSString() );
@@ -137,10 +238,10 @@
vmArguments.append( " " );
vmArguments.append( "-Dapacheds.instance=" + serverInstance.getName() );
- System.err.println( vmArguments.toString() );
-
+ // Setting the VM arguments attribute
workingCopy.setAttribute( IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArguments.toString() );
+ // Saving to a launch configuration
ILaunchConfiguration configuration = null;
try
{
@@ -151,8 +252,8 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
- DebugUITools.launch( configuration, ILaunchManager.RUN_MODE );
- return Status.OK_STATUS;
+ // Launching the launch configuration
+ DebugUITools.launch( configuration, ILaunchManager.RUN_MODE );
}
}
Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.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/ServersHandler.java?rev=654061&r1=654060&r2=654061&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java (original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java Wed May 7 03:06:38 2008
@@ -39,6 +39,7 @@
/**
* This class implements the servers handler.
* <p>
+ *
* It is used to store all the server instances used in the plugin.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -52,10 +53,10 @@
/** The list of server instances */
private List<ServerInstance> serverInstancesList;
- /** The map of server instances ordered by name */
+ /** The map of server instances identified by name */
private Map<String, ServerInstance> serverInstancesNameMap;
- /** The map of server instances ordered by ID */
+ /** The map of server instances identified by ID */
private Map<String, ServerInstance> serverInstancesIdMap;
/** The listeners */
@@ -318,4 +319,16 @@
{
return serverInstancesList;
}
+
+
+ /**
+ * Gets the server instance associated with the given id.
+ *
+ * @return
+ * the server instance associated witht the given id.
+ */
+ public ServerInstance getServerInstanceById( String id )
+ {
+ return serverInstancesIdMap.get( id );
+ }
}