net.clackrouter.application
Class ClackApplication

java.lang.Object
  extended by java.lang.Thread
      extended by net.clackrouter.application.ClackApplication
All Implemented Interfaces:
java.lang.Runnable, Alarm
Direct Known Subclasses:
HelloApp, HTTPGetter, Ifconfig, MiniWebServer, Ping, Show, TCPRedirector, UDPRedirector, UnixRoute

public abstract class ClackApplication
extends java.lang.Thread
implements Alarm

Abstract class to be sub-classed by all applications to be run on Clack.

The functionality of the application should be implemented with application_main(String[]) with parameters passed in using the argument array.

Sockets are created by calling either of the supplied methods, createTCPSocket() or createUDPSocket() .


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClackApplication()
           
 
Method Summary
protected  void alert(java.lang.String msg)
          Creates a simple dialog box to display a message
abstract  void application_main(java.lang.String[] args)
          Abstract "main method" to be implemented by sub-class
 void configure(java.lang.String name, Router router, java.lang.String[] config)
          Used to configure the application before it is run (for internal Clack use).
protected  TCPSocket createTCPSocket()
          Create a TCPSocket running on this router
protected  UDPSocket createUDPSocket()
          Create a UDPSocket running on this router
 java.lang.String getAppName()
          Get application name
abstract  java.lang.String getDescription()
          Returns a very brief (single line) description of the application
 Router getRouter()
          Get the router associated with this application
 long getTime()
           
 void notifyAlarm()
          call-back method implemented by the code setting the alarm.
 void pause(long msecs)
           
protected  void print(java.lang.String s)
          Print out a message to the application console
 void run()
          Starts the application (for internal Clack use)
 void setAlarm(long msecs_from_now)
          Sets a timer
 void setShell(ClackShell shell)
          Set active shell for this application.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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
 

Constructor Detail

ClackApplication

public ClackApplication()
Method Detail

configure

public void configure(java.lang.String name,
                      Router router,
                      java.lang.String[] config)
Used to configure the application before it is run (for internal Clack use).

Parameters:
name - An identifier for this application
router - The router hosting this application
config - A String[] of parameters

setShell

public void setShell(ClackShell shell)
Set active shell for this application.

Parameters:
shell -

run

public void run()
Starts the application (for internal Clack use)

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

createTCPSocket

protected TCPSocket createTCPSocket()
                             throws java.lang.Exception
Create a TCPSocket running on this router

Throws:
java.lang.Exception - errors if TCP is not enabled on the router

createUDPSocket

protected UDPSocket createUDPSocket()
                             throws java.lang.Exception
Create a UDPSocket running on this router

Throws:
java.lang.Exception - errors if UDP is not enabled on the router

alert

protected void alert(java.lang.String msg)
Creates a simple dialog box to display a message

Parameters:
msg - message to be displayed

print

protected void print(java.lang.String s)
Print out a message to the application console

Parameters:
s - text to be printed

application_main

public abstract void application_main(java.lang.String[] args)
                               throws java.lang.InterruptedException
Abstract "main method" to be implemented by sub-class

Parameters:
args - the application arguments
Throws:
java.lang.InterruptedException

getDescription

public abstract java.lang.String getDescription()
Returns a very brief (single line) description of the application


getRouter

public Router getRouter()
Get the router associated with this application

Specified by:
getRouter in interface Alarm
Returns:

getAppName

public java.lang.String getAppName()
Get application name


pause

public void pause(long msecs)

setAlarm

public void setAlarm(long msecs_from_now)
Description copied from interface: Alarm
Sets a timer

Specified by:
setAlarm in interface Alarm
Parameters:
msecs_from_now - milliseconds later in "clack time" that the alarm will fire.

getTime

public long getTime()

notifyAlarm

public void notifyAlarm()
Description copied from interface: Alarm
call-back method implemented by the code setting the alarm. notifies that the alarm has fired.

Specified by:
notifyAlarm in interface Alarm