Author: chirino
Date: Wed Dec 5 08:29:45 2007
New Revision: 601396
URL: http://svn.apache.org/viewvc?rev=601396&view=rev
Log:
Updated the MainService interface so that the exit code can be passed back. We
now
shutdown the system when teh GShell is exited.
Modified:
servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/pom.xml
servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/spi/MainService.java
Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/pom.xml?rev=601396&r1=601395&r2=601396&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/pom.xml
(original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/pom.xml Wed
Dec 5 08:29:45 2007
@@ -73,6 +73,11 @@
<version>4.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-osgi-core</artifactId>
+ <version>${spring.osgi.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.geronimo.gshell</groupId>
<artifactId>gshell-core</artifactId>
<version>${gshell.version}</version>
Modified:
servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
URL:
http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java?rev=601396&r1=601395&r2=601396&view=diff
==============================================================================
---
servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
(original)
+++
servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
Wed Dec 5 08:29:45 2007
@@ -21,6 +21,9 @@
import org.apache.geronimo.gshell.shell.Environment;
import org.apache.geronimo.gshell.shell.InteractiveShell;
import org.apache.servicemix.main.spi.MainService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.springframework.osgi.context.BundleContextAware;
/**
* Created by IntelliJ IDEA.
@@ -29,7 +32,7 @@
* Time: 10:20:37 PM
* To change this template use File | Settings | File Templates.
*/
-public class GShell implements Runnable {
+public class GShell implements Runnable, BundleContextAware {
private InteractiveShell shell;
private Thread thread;
@@ -37,6 +40,7 @@
private Environment env;
private boolean start;
private MainService mainService;
+ private BundleContext bundleContext;
public GShell(InteractiveShell shell) {
this.shell = shell;
@@ -76,17 +80,34 @@
// If a command was specified on the command line, then just
execute that command.
if( args!=null && args.length > 0 ) {
System.out.println("Executing 1 command:");
- shell.execute((Object[])args);
- }
-// For now we don't know how to shutdown after executing
the command so go into a shell loop
-// else {
+ Object value = shell.execute((Object[])args);
+ if( mainService!=null ) {
+ if( value instanceof Number ) {
+
mainService.setExitCode(((Number)value).intValue());
+ } else {
+
mainService.setExitCode(value!=null?1:0);
+ }
+ }
+ } else {
System.out.println("going int interactive loop:");
// Otherwise go into a command shell.
shell.run();
-// }
+ if( mainService!=null ) {
+ mainService.setExitCode(0);
+ }
+ }
} catch (Exception e) {
+ if( mainService!=null ) {
+ mainService.setExitCode(-1);
+ }
e.printStackTrace();
+ } finally {
+ try {
+ getBundleContext().getBundle(0).stop();
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
}
}
@@ -96,6 +117,14 @@
public void setMainService(MainService main) {
this.mainService = main;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
}
}
Modified:
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
URL:
http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java?rev=601396&r1=601395&r2=601396&view=diff
==============================================================================
---
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
(original)
+++
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/Main.java
Wed Dec 5 08:29:45 2007
@@ -22,6 +22,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
+import java.util.concurrent.CountDownLatch;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.cache.BundleCache;
@@ -69,6 +70,7 @@
private static Felix m_felix = null;
private final String[] args;
+ private int exitCode;
public Main(String[] args) {
this.args = args;
@@ -202,7 +204,8 @@
}
// Register the Main class so that other bundles can inspect the
command line args.
- final MainService main = new Main(argv);
+ final MainService main = new Main(argv);
+ final CountDownLatch shutdown = new CountDownLatch(1);
BundleActivator activator = new BundleActivator() {
private ServiceRegistration registration;
public void start(BundleContext context)
@@ -213,6 +216,7 @@
public void stop(BundleContext context)
{
registration.unregister();
+ shutdown.countDown();
}
};
List<BundleActivator> activations = new ArrayList<BundleActivator>();
@@ -231,6 +235,20 @@
ex.printStackTrace();
System.exit(-1);
}
+
+ // Wait for the system to get shutdown.
+ try
+ {
+ shutdown.await();
+ m_felix.stopAndWait();
+ }
+ catch (Exception ex)
+ {
+ System.err.println("Error occured shutting down framework: " + ex);
+ ex.printStackTrace();
+ } finally {
+ System.exit(main.getExitCode());
+ }
}
/**
@@ -630,5 +648,13 @@
*/
public String[] getArgs() {
return args;
+ }
+
+ public int getExitCode() {
+ return exitCode;
+ }
+
+ public void setExitCode(int exitCode) {
+ this.exitCode = exitCode;
}
}
Modified:
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/spi/MainService.java
URL:
http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/spi/MainService.java?rev=601396&r1=601395&r2=601396&view=diff
==============================================================================
---
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/spi/MainService.java
(original)
+++
servicemix/branches/servicemix-4.0/runtime/main/src/main/java/org/apache/servicemix/main/spi/MainService.java
Wed Dec 5 08:29:45 2007
@@ -21,5 +21,7 @@
public interface MainService {
public abstract String[] getArgs();
+ public int getExitCode();
+ public void setExitCode(int exitCode);
}