You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/10/29 02:39:27 UTC
svn commit: r589467 -
/incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java
Author: jsdelfino
Date: Sun Oct 28 18:39:26 2007
New Revision: 589467
URL: http://svn.apache.org/viewvc?rev=589467&view=rev
Log:
Automatically launch domain controller if it's not running, when launching a node.
Modified:
incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java
Modified: incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java?rev=589467&r1=589466&r2=589467&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java (original)
+++ incubator/tuscany/java/sca/tools/eclipse/plugins/core/src/main/java/org/apache/tuscany/sca/core/launch/TuscanyLaunchShortcut.java Sun Oct 28 18:39:26 2007
@@ -19,7 +19,14 @@
package org.apache.tuscany.sca.core.launch;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -28,6 +35,7 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -57,41 +65,18 @@
return;
}
- // Get the Java project
- IJavaProject javaProject = JavaCore.create(file.getProject());
-
- // Find the Java source container containing the selected
- // .composite file
- IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
- int segments = 0;
- for (IClasspathEntry entry : classpathEntries)
- if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- segments = entry.getPath().matchingFirstSegments(file.getFullPath());
- if (segments > 0)
- break;
- }
-
// Get our launch configuration type
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType launchConfigurationType =
- launchManager.getLaunchConfigurationType("org.apache.tuscany.sca.core.launch.configurationtype");
-
- // Create a launch configuration
- ILaunchConfigurationWorkingCopy configuration =
- launchConfigurationType.newInstance(null,
- launchManager.generateUniqueLaunchConfigurationNameFrom(file.getFullPath().removeFileExtension().lastSegment()));
- configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.apache.tuscany.sca.node.launch.SCANodeLauncher");
- configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, file.getProject().getName());
-
- // Pass the path of the .composite relative to the classpath root to the launcher
- configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, file.getFullPath()
- .removeFirstSegments(segments).toString());
+ ILaunchConfigurationType launchConfigurationType =launchManager.getLaunchConfigurationType(
+ "org.apache.tuscany.sca.core.launch.configurationtype");
- // Save the configuration
- configuration.doSave();
+ // If the SCA domain controller is not running yet, launch it
+ if (!isDomainControllerRunning()) {
+ launchDomainController(mode, file, launchManager, launchConfigurationType);
+ }
- // Launch!!
- configuration.launch(mode, null);
+ // Launch an SCA node
+ launchNode(mode, file, launchManager, launchConfigurationType);
} catch (Exception e) {
e.printStackTrace();
@@ -101,4 +86,136 @@
public void launch(IEditorPart editor, String mode) {
//TODO later...
}
+
+ /**
+ * Launch an SCA node.
+ *
+ * @param mode
+ * @param file
+ * @param launchManager
+ * @param launchConfigurationType
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void launchNode(String mode,
+ IFile file,
+ ILaunchManager launchManager,
+ ILaunchConfigurationType launchConfigurationType) throws CoreException, JavaModelException {
+
+ // Create a launch configuration
+ ILaunchConfigurationWorkingCopy configuration = launchConfigurationType.newInstance(null,
+ launchManager.generateUniqueLaunchConfigurationNameFrom(file.getFullPath().removeFileExtension().lastSegment()));
+
+ // Get the Java project
+ IJavaProject javaProject = JavaCore.create(file.getProject());
+
+ // Set the project and type to launch
+ configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.apache.tuscany.sca.node.launch.SCANodeLauncher");
+ configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, file.getProject().getName());
+
+ // Find the Java source container containing the selected .composite file
+ IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
+ int sourceFolderSegments = 0;
+ for (IClasspathEntry entry : classpathEntries)
+ if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ sourceFolderSegments = entry.getPath().matchingFirstSegments(file.getFullPath());
+ if (sourceFolderSegments > 0)
+ break;
+ }
+
+ // Pass the path of the .composite relative to the source folder to the launcher
+ configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
+ file.getFullPath().removeFirstSegments(sourceFolderSegments).toString());
+
+ // Save the configuration
+ configuration.doSave();
+
+ // Launch
+ configuration.launch(mode, null);
+ }
+
+ /**
+ * Launch the SCA domain controller.
+ *
+ * @param mode
+ * @param launchManager
+ * @param launchConfigurationType
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void launchDomainController(String mode,
+ IFile file,
+ ILaunchManager launchManager,
+ ILaunchConfigurationType launchConfigurationType) throws CoreException, JavaModelException {
+
+ // Create a launch configuration
+ ILaunchConfigurationWorkingCopy configuration = launchConfigurationType.newInstance(null,
+ launchManager.generateUniqueLaunchConfigurationNameFrom("Tuscany Domain Controller"));
+
+ // Set the project and type to launch
+ configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, file.getProject().getName());
+ configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.apache.tuscany.sca.domain.launch.SCADomainControllerLauncher");
+
+ // Save the configuration
+ configuration.doSave();
+
+ // Launch
+ configuration.launch(mode, null);
+ }
+
+ private static final String PING_HEADER =
+ "GET /domain/index.html HTTP/1.0\n" + "Host: localhost\n"
+ + "Content-Type: text/xml\n"
+ + "Connection: close\n"
+ + "Content-Length: ";
+ private static final String PING_CONTENT = "";
+ private static final String PING =
+ PING_HEADER + PING_CONTENT.getBytes().length + "\n\n" + PING_CONTENT;
+
+ /**
+ * Returns true if the SCA domain controller is running.
+ *
+ * @return
+ */
+ private boolean isDomainControllerRunning() {
+ try {
+ Socket client = new Socket("localhost", 9999);
+ OutputStream os = client.getOutputStream();
+ os.write(PING.getBytes());
+ os.flush();
+ String response = read(client);
+ if (response.indexOf("Tuscany") != -1) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Read a String from a socket.
+ *
+ * @param socket
+ * @return
+ * @throws IOException
+ */
+ private static String read(Socket socket) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org