Buju 0.4

biz.bbeans.buju
Class BServer

java.lang.Object
  extended byjava.lang.Thread
      extended bybiz.bbeans.buju.BServer
All Implemented Interfaces:
Runnable

public class BServer
extends Thread

Java interpreter non-interactive remote session server. Adapted from bsh.util.Sessiond.


Nested Class Summary
 class BServer.BConnection
           
 
Field Summary
static String VERSION
          Buju version.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 boolean accessAllowed(String user, String password)
          Access allowed for the given user and password.
 String getInterpScript()
          Get the interpreter initialization script.
static biz.bbeans.usage.BUsage getUsage()
          Build and return the command line usage for the Main method.
static void main(String[] args)
          For usage display on standard out, use the -h option.
 boolean paused()
          Status of the server.
 boolean pauseServer(String password)
          Pause the server.
 boolean refreshServer(String password)
          Refresh the server's data.
 boolean restarted()
          Status of the server.
 boolean restartServer(String password)
          Restart the server by creating a new server instance.
 boolean resumeServer(String password)
          Resume the server after being paused.
 void run()
          Run the service.
 boolean started()
          Status of the server.
 boolean stopped()
          Status of the server.
 boolean stopServer(String password)
          Stop the server.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Buju version.

See Also:
Constant Field Values
Method Detail

accessAllowed

public boolean accessAllowed(String user,
                             String password)
                      throws NoSuchAlgorithmException,
                             UnsupportedEncodingException
Access allowed for the given user and password.

Parameters:
user - User ID.
password - User password in clear text.
Returns:
True if the user ID with the given password is valid.
Throws:
NoSuchAlgorithmException
UnsupportedEncodingException

started

public boolean started()
Status of the server.

Returns:
True if the server was ever started, otherwise false. If the server is now stopped, this method will return true, because the server can't be stopped if it was never started.

paused

public boolean paused()
Status of the server.

Returns:
True if the server is paused, otherwise false.

restarted

public boolean restarted()
Status of the server.

Returns:
True if the server was restarted, otherwise false. A server instance can only be restarted once, because it creates a new server instance using the same port.

stopped

public boolean stopped()
Status of the server.

Returns:
True if the server was started and then stopped, otherwise false.

pauseServer

public boolean pauseServer(String password)
                    throws IOException,
                           NoSuchAlgorithmException,
                           UnsupportedEncodingException
Pause the server. After being paused, the server will accept no connections until resumed.

Parameters:
password - Admin password.
Returns:
True if the server paused, otherwise false.
Throws:
IOException - If there was a problem closing the server socket.
NoSuchAlgorithmException - If the encryption algorithm is not supported.
UnsupportedEncodingException - If UTF-8 character set encoding is not supported.

resumeServer

public boolean resumeServer(String password)
                     throws IOException,
                            NoSuchAlgorithmException,
                            UnsupportedEncodingException
Resume the server after being paused.

Parameters:
password - Admin password.
Returns:
True if the server resumed, otherwise false.
Throws:
IOException - If there was a problem re-creating the server socket.
NoSuchAlgorithmException - If the encryption algorithm is not supported.
UnsupportedEncodingException - If UTF-8 character set encoding is not supported.

restartServer

public boolean restartServer(String password)
                      throws EvalError,
                             IOException,
                             NoSuchAlgorithmException
Restart the server by creating a new server instance. If this server instance has not been stopped, stopServer is called. Then a new BServer instance is created and started using this server's configuration. This server's connections and the new server's connections will not share any interpreters, including the admin interpreter.

Parameters:
password - Admin password.
Returns:
True if the server stopped, otherwise false.
Throws:
EvalError - If the admin script does not evaluate properly.
IOException - If there was a problem closing the server socket.
NoSuchAlgorithmException - If the encryption algorithm is not supported.

refreshServer

public boolean refreshServer(String password)
                      throws EvalError,
                             IOException,
                             NoSuchAlgorithmException
Refresh the server's data.

Parameters:
password - Admin password.
Returns:
True if the server was refreshed, otherwise false.
Throws:
EvalError - If the admin script does not evaluate properly.
IOException - If there was a problem reading data.
NoSuchAlgorithmException - If the encryption algorithm is not supported.

stopServer

public boolean stopServer(String password)
                   throws IOException,
                          NoSuchAlgorithmException,
                          UnsupportedEncodingException
Stop the server. After being stopped, the server will accept no new connections, ever. However, a current connection can create a new BServer instance using this server's original configuration by calling restartServer.

Parameters:
password - Admin password.
Returns:
True if the server stopped, otherwise false.
Throws:
IOException - If there was a problem closing the server socket.
NoSuchAlgorithmException - If the encryption algorithm is not supported.
UnsupportedEncodingException - If UTF-8 character set encoding is not supported.

run

public void run()
Run the service. Stopped by calling stopServer(). Once stopped, a server instance may not be re-started; a new server instance should be created instead.


getInterpScript

public String getInterpScript()
Get the interpreter initialization script. This script will be sourced when each new interpreter is created. May return null if the script file did not exist.

Returns:
The interpreter initialization script. May return null.

getUsage

public static biz.bbeans.usage.BUsage getUsage()
Build and return the command line usage for the Main method. Usage help can then be displayed by calling: printUsage(PrintStream ps) on the returned BUsage object.

Returns:
Command line usage.

main

public static void main(String[] args)
For usage display on standard out, use the -h option.


Buju 0.4