com.planet_ink.coffee_mud.Common.interfaces
Class Session.InputCallback

java.lang.Object
  extended by com.planet_ink.coffee_mud.Common.interfaces.Session.InputCallback
Direct Known Subclasses:
Session.TickingCallback
Enclosing interface:
Session

public abstract static class Session.InputCallback
extends java.lang.Object

The internal class to managing asynchronous user input. This class supports three types of input: open text (PROMPT), one-letter options (CHOOSE), and Y/N (CONFIRM).


Nested Class Summary
static class Session.InputCallback.Type
          The threa different types of user input processing supported by the abstract InputCallback class
 
Field Summary
protected  boolean confirmed
           
protected  java.lang.String input
           
protected  boolean noTrim
           
protected  long timeout
           
protected  long timeoutMs
           
protected  boolean waiting
           
 
Constructor Summary
Session.InputCallback(Session.InputCallback.Type type)
          Constructor.
Session.InputCallback(Session.InputCallback.Type type, long timeoutMs)
          Constructor.
Session.InputCallback(Session.InputCallback.Type type, java.lang.String defaultInput)
          Constructor.
Session.InputCallback(Session.InputCallback.Type type, java.lang.String defaultInput, long timeoutMs)
          Constructor.
Session.InputCallback(Session.InputCallback.Type type, java.lang.String defaultInput, java.lang.String choicesStr, long timeoutMs)
          Full constructor.
 
Method Summary
abstract  void callBack()
          This method is called if the user hits ENTER, and their input data is valid (one of the choices for CHOOSE or CONFIRM), or anything else for PROMPT.
 boolean isTimedOut()
          Returns true if a timeout was given, and this class has been active longer than that amount of time.
 Session.InputCallback reset()
          This method allows reuse of a given InputCallback.
 void setInput(java.lang.String input)
          Forces user-input into this class, potentially changing its user input waiting state.
abstract  void showPrompt()
          This method is called by InputCallback before user input is requested.
abstract  void timedOut()
          This method is call by InputCallback if a timeout value greater than 0 is given and that amount of time has been exceeded.
 boolean waitForInput()
          Returns true if this class is currently waiting for user input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeoutMs

protected final long timeoutMs

timeout

protected volatile long timeout

input

protected volatile java.lang.String input

confirmed

protected volatile boolean confirmed

waiting

protected volatile boolean waiting

noTrim

protected volatile boolean noTrim
Constructor Detail

Session.InputCallback

public Session.InputCallback(Session.InputCallback.Type type,
                             java.lang.String defaultInput,
                             java.lang.String choicesStr,
                             long timeoutMs)
Full constructor. Receives the Type of processing, a default input for when the user just hits ENTER, a list of one-character choices (if CHOOSE Type is used) and an amount of time, in ms, for the user to be given before timeout and the timedOut() method is called.

Parameters:
type - the type of processing
defaultInput - default input value
choicesStr - list of one-character options (if CHOOSE Type)
timeoutMs - time, in ms, before the user is kicked

Session.InputCallback

public Session.InputCallback(Session.InputCallback.Type type,
                             java.lang.String defaultInput,
                             long timeoutMs)
Constructor. Receives the Type of processing, a default input for when the user just hits ENTER, and an amount of time, in ms, for the user to be given before timeout and the timedOut() method is called.

Parameters:
type - the type of processing
defaultInput - default input value
timeoutMs - time, in ms, before the user is kicked

Session.InputCallback

public Session.InputCallback(Session.InputCallback.Type type,
                             long timeoutMs)
Constructor. Receives the Type of processing, and an amount of time, in ms, for the user to be given before timeout and the timedOut() method is called.

Parameters:
type - the type of processing
timeoutMs - time, in ms, before the user is kicked

Session.InputCallback

public Session.InputCallback(Session.InputCallback.Type type)
Constructor. Receives the Type of processing.

Parameters:
type - the type of processing

Session.InputCallback

public Session.InputCallback(Session.InputCallback.Type type,
                             java.lang.String defaultInput)
Constructor. Receives the Type of processing, a default input for when the user just hits ENTER.

Parameters:
type - the type of processing
defaultInput - default input value
Method Detail

isTimedOut

public boolean isTimedOut()
Returns true if a timeout was given, and this class has been active longer than that amount of time.

Returns:
true if timed out, false otherwise.

setInput

public void setInput(java.lang.String input)
Forces user-input into this class, potentially changing its user input waiting state. If the input is invalid for CONFIRM or CHOOSE, then this will call ShowPrompt and go back to waiting. Otherwise, waiting is set to false and it becomes very likely that callBack() will be called.

Parameters:
input - the user input to force

waitForInput

public boolean waitForInput()
Returns true if this class is currently waiting for user input.

Returns:
true if waiting, false if waiting is over.

reset

public Session.InputCallback reset()
This method allows reuse of a given InputCallback. It will re-start the timeout period, and flag the callback for requiring more input.

Returns:
this

showPrompt

public abstract void showPrompt()
This method is called by InputCallback before user input is requested. If a CHOOSE or CONFIRM type is used, and the user enters something unrecognized, then this method is called again before more input.


timedOut

public abstract void timedOut()
This method is call by InputCallback if a timeout value greater than 0 is given and that amount of time has been exceeded.


callBack

public abstract void callBack()
This method is called if the user hits ENTER, and their input data is valid (one of the choices for CHOOSE or CONFIRM), or anything else for PROMPT. If the user has entered nothing, and a default value has been given, the default value is returned. The user entry is available to this method in this.input variable.