org.eclipse.osgi.framework.internal.core
Class FrameworkConsole

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.core.FrameworkConsole
All Implemented Interfaces:
java.lang.Runnable

public class FrameworkConsole
extends java.lang.Object
implements java.lang.Runnable

This class starts OSGi with a console for development use. FrameworkConsole provides a printStackTrace method to print Exceptions and their nested Exceptions.


Field Summary
protected  java.lang.String[] args
          The command line arguments passed at launch time
protected  BundleContext context
          The current bundle context
protected  ServiceTracker cptracker
          A tracker containing the service object of all registered command providers
protected  boolean disconnect
           
protected  java.io.BufferedReader in
          The stream to receive commands on
protected  org.eclipse.osgi.framework.internal.core.OSGi osgi
          The current osgi instance
protected  CommandProvider osgicp
          The OSGi Command Provider
protected  java.io.PrintWriter out
          The stream to write command results to
protected  int port
           
protected  java.net.Socket s
           
protected  org.eclipse.osgi.framework.internal.core.FrameworkConsole.ConsoleSocketGetter scsg
           
protected  boolean useSocketStream
          set to true if accepting commands from port
 
Constructor Summary
FrameworkConsole(org.eclipse.osgi.framework.internal.core.OSGi osgi, int port, java.lang.String[] args)
          Constructor for FrameworkConsole.
FrameworkConsole(org.eclipse.osgi.framework.internal.core.OSGi osgi, java.lang.String[] args)
          Constructor for FrameworkConsole.
 
Method Summary
protected  void console()
          Command Line Interface for OSGi.
 void console(java.lang.String[] args)
          Command Line Interface for OSGi.
 void disconnect()
          Disconnects from console if useSocketStream is set to true.
protected  void docommand(java.lang.String cmdline)
          Process the args on the command line.
 java.lang.String getInput()
          Reads a string from standard input until user hits the Enter key.
 java.io.BufferedReader getReader()
          Return the current input BufferedReader
 java.lang.Object[] getServices()
          Return an array of service objects for all services being tracked by this ServiceTracker object.
 boolean getUseSocketStream()
          Return if the SocketSteam (telnet to the console) is being used
 java.io.PrintWriter getWriter()
          Return the current output PrintWriter
 void run()
          Begin doing the active part of the class' code.
 void shutdown()
          Stops the console so the thread can be GC'ed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.BufferedReader in
The stream to receive commands on


out

protected java.io.PrintWriter out
The stream to write command results to


context

protected final BundleContext context
The current bundle context


osgi

protected final org.eclipse.osgi.framework.internal.core.OSGi osgi
The current osgi instance


args

protected final java.lang.String[] args
The command line arguments passed at launch time


osgicp

protected final CommandProvider osgicp
The OSGi Command Provider


cptracker

protected final ServiceTracker cptracker
A tracker containing the service object of all registered command providers


useSocketStream

protected final boolean useSocketStream
set to true if accepting commands from port


disconnect

protected boolean disconnect

port

protected final int port

scsg

protected org.eclipse.osgi.framework.internal.core.FrameworkConsole.ConsoleSocketGetter scsg

s

protected java.net.Socket s
Constructor Detail

FrameworkConsole

public FrameworkConsole(org.eclipse.osgi.framework.internal.core.OSGi osgi,
                        java.lang.String[] args)
Constructor for FrameworkConsole. It creates a service tracker to track CommandProvider registrations. The console InputStream is set to System.in and the console PrintStream is set to System.out.

Parameters:
osgi - - an instance of an osgi framework
args - - any arguments passed on the command line when Launcher is started.

FrameworkConsole

public FrameworkConsole(org.eclipse.osgi.framework.internal.core.OSGi osgi,
                        int port,
                        java.lang.String[] args)
Constructor for FrameworkConsole. It creates a service tracker to track CommandProvider registrations. The console InputStream is set to System.in and the console PrintStream is set to System.out.

Parameters:
osgi - - an instance of an osgi framework
args - - any arguments passed on the command line when Launcher is started.
Method Detail

getWriter

public java.io.PrintWriter getWriter()
Return the current output PrintWriter

Returns:
The currently active PrintWriter

getReader

public java.io.BufferedReader getReader()
Return the current input BufferedReader

Returns:
The currently active BufferedReader

getUseSocketStream

public boolean getUseSocketStream()
Return if the SocketSteam (telnet to the console) is being used

Returns:
Return if the SocketSteam is being used

run

public void run()
Begin doing the active part of the class' code. Starts up the console.

Specified by:
run in interface java.lang.Runnable

console

public void console(java.lang.String[] args)
             throws java.io.IOException
Command Line Interface for OSGi. The method processes the initial commands and then reads and processes commands from the console InputStream. Command output is written to the console PrintStream. The method will loop reading commands from the console InputStream until end-of-file is reached. This method will then return.

Parameters:
args - Initial set of commands to execute.
Throws:
java.io.IOException

console

protected void console()
                throws java.io.IOException
Command Line Interface for OSGi. The method processes the initial commands and then reads and processes commands from the console InputStream. Command output is written to the console PrintStream. The method will loop reading commands from the console InputStream until end-of-file is reached. This method will then return.

Throws:
java.io.IOException

docommand

protected void docommand(java.lang.String cmdline)
Process the args on the command line. This method invokes a CommandInterpreter to do the actual work.

Parameters:
cmdline - a string containing the command line arguments

disconnect

public void disconnect()
Disconnects from console if useSocketStream is set to true. This will cause the console to close from a telnet session.


getInput

public java.lang.String getInput()
Reads a string from standard input until user hits the Enter key.

Returns:
The string read from the standard input without the newline character.

getServices

public java.lang.Object[] getServices()
Return an array of service objects for all services being tracked by this ServiceTracker object. The array is sorted primarily by descending Service Ranking and secondarily by ascending Service ID.

Returns:
Array of service objects or null if no service are being tracked.

shutdown

public void shutdown()
Stops the console so the thread can be GC'ed

Throws:
java.io.IOException