Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

dragonfly: re-add shell support for command-line access to osgi

framework in bug.simulator.
  • Loading branch information...
commit 582167dc1c1a3b65412fb462d142e22233a09501 1 parent 05ed5c9
@kgilmer kgilmer authored
View
3  com.buglabs.bug.simulator/META-INF/MANIFEST.MF
@@ -45,4 +45,5 @@ Import-Package:
org.osgi.service.http,
org.osgi.service.log,
org.osgi.util.position,
- org.osgi.util.tracker
+ org.osgi.util.tracker,
+ org.knapsack.shell.pub
View
8 com.buglabs.bug.simulator/com/buglabs/bug/simulator/Activator.java
@@ -62,6 +62,7 @@
import com.buglabs.bug.module.video.VideoActivator;
import com.buglabs.bug.module.vonhippel.VHActivator;
import com.buglabs.bug.simulator.controller.Server;
+import com.buglabs.bug.simulator.ui.ShellIOThread;
import com.buglabs.support.SupportInfoTextFormatter;
import com.buglabs.support.SupportInfoXMLFormatter;
import com.buglabs.util.osgi.LogServiceUtil;
@@ -127,6 +128,8 @@
private VideoActivator videoActivator;
+ private ShellIOThread shellThread;
+
public void start(final BundleContext context) throws Exception {
// Basic setup ********************************************
this.context = context;
@@ -203,9 +206,14 @@ public void run(Map<String, Object> services) {
Dictionary<String, String> d = new Hashtable<String, String>();
d.put("bug.base.version", "2.0");
baseControlReg = context.registerService(IBUG20BaseControl.class.getName(), controllerServer, d);
+
+ shellThread = new ShellIOThread(Integer.parseInt(System.getProperty("org.knapsack.shell.port")));
+ shellThread.start();
}
public void stop(BundleContext context) throws Exception {
+ shellThread.shutdown();
+
if (controllerServer != null) {
controllerServer.shutdown();
}
View
70 com.buglabs.bug.simulator/com/buglabs/bug/simulator/ui/ShellIOThread.java
@@ -0,0 +1,70 @@
+package com.buglabs.bug.simulator.ui;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+import org.knapsack.shell.pub.Netcat;
+
+/**
+ * A class to read from the stdin, send to knapsack, and print result.
+ *
+ * @author kgilmer
+ *
+ */
+public class ShellIOThread extends Thread {
+
+ private final int port;
+
+ /**
+ * @param port
+ */
+ public ShellIOThread(int port) {
+ this.port = port;
+ }
+
+ @Override
+ public void run() {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ OutputStream os = System.out;
+
+ String line = null;
+ try {
+ printPrompt(os);
+ while (!Thread.interrupted() && (line = br.readLine()) != null) {
+ Netcat.run("localhost", port, new ByteArrayInputStream(line.getBytes()), os);
+ os.flush();
+ printPrompt(os);
+ }
+ } catch (IOException e) {
+
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ /**
+ * @param os
+ * @throws IOException
+ */
+ private void printPrompt(OutputStream os) throws IOException {
+ os.write("\n(: ".getBytes());
+ }
+
+ /**
+ * Shutdown the thread
+ */
+ public void shutdown() {
+ this.interrupt();
+ try {
+ System.out.write("\n".getBytes());
+ } catch (IOException e) {
+ }
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.