Buju 0.4

biz.bbeans.buju
Class BServer.BConnection

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

public class BServer.BConnection
extends Thread


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 void close()
          Close this connection gracefully.
 String getAdminCommandToken()
          Get the token for recognizing an admin command.
 BInterpreter getInterpreter()
          Get this connection's current interpreter.
 Throwable getLastThrowable()
          Get the last throwable encountered by this connection when it was evaluating source code.
 int getPID()
          Gets the connection thread process ID assigned when the thread was created.
 Map getProperties()
          Get the properties Map.
 long getTimeout()
          Get this connection's timeout setting.
 void run()
          Run the thread servicing the client.
 void setAdminCommandToken(String token)
          Set the token for recognizing an admin command.
 void setInterpreter(BInterpreter interp)
          Set the current interpreter for this connection.
 void setTimeout(long timeout)
          Set this connection's timeout in milleseconds.
 
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
 

Method Detail

run

public void run()
Run the thread servicing the client. The main elements in the run loop are: - Read the incoming message from the socket - Dispatch the message's source line to either the admin interpreter or the current thread's interpreter. - Write the outgoing evaluation result to the socket The protocol for incoming and outgoing messages is simple: - A Java int (four-byte signed integer) indicating the number of bytes of data to follow in the message. For outgoing messages, this int can be positive or negative, but its absolute value always represents the length of the subsequent message. A negative value indicates an exception condition, and the message will describe the condition. - A string of bytes representing the source to evaluate (incoming) or the result of the evaluation (outgoing).


setTimeout

public void setTimeout(long timeout)
Set this connection's timeout in milleseconds. The timeout value is used to start a timer for any thread wait() block. When the timer expires, the thread is interrupted if it is still blocked. Any shared interpreter will block at lock(), unlock(), and eval() if the interpreter is locked by another thread (connection). If a thread unblocks before the timer expires, the interrupt is cancelled.

Parameters:
timeout - Time in milleseconds to wait before interrupting the blocked thread. A value of zero will never interrupt the thread, potentially leaving it blocked forever. Any negative value will interrupt the blocked thread immediately.

getTimeout

public long getTimeout()
Get this connection's timeout setting.

Returns:
Timeout setting in milleseconds. A value of zero will never interrupt the thread, potentially leaving it blocked forever. Any negative value will interrupt the blocked thread immediately.

setAdminCommandToken

public void setAdminCommandToken(String token)
Set the token for recognizing an admin command. This string is typically a single character. If a line is sent to the connection beginning with this token, the token is replaced with the string "admin." and sent on to the admin interpreter for evaluation. This substitution process makes scripted methods in the inner "class" admin() in the admin init script 'public' and all other methods 'private'.

Parameters:
token - Admin command token. A received line beginning with this string is processed by the admin interpreter.

getAdminCommandToken

public String getAdminCommandToken()
Get the token for recognizing an admin command.

Returns:
Admin command token.

setInterpreter

public void setInterpreter(BInterpreter interp)
Set the current interpreter for this connection. After this method returns, all subsequent received lines will be evaluated by this interpreter.

Parameters:
interp - Interpreter to set.

getInterpreter

public BInterpreter getInterpreter()
Get this connection's current interpreter.


getProperties

public Map getProperties()
Get the properties Map. The properties Map is meant for use by the admin script to store other information associated with this connection. It is initially empty. The Map returned is structurally thread-safe.

Returns:
The properties Map.

getLastThrowable

public Throwable getLastThrowable()
Get the last throwable encountered by this connection when it was evaluating source code.

Returns:
Last throwable.

close

public void close()
Close this connection gracefully.


getPID

public int getPID()
Gets the connection thread process ID assigned when the thread was created. The pid is not guaranteed to be unique, but in practice it probably is.

Returns:
Thread process ID.

Buju 0.4