com.swath
Class UserDefinedDaemon

java.lang.Object
  extended bycom.swath.UserDefinedDaemon
Direct Known Subclasses:
ExampleDaemon1

public abstract class UserDefinedDaemon
extends java.lang.Object

User Defined Daemon base class.

Since:
SWATH 1.7

Constructor Summary
UserDefinedDaemon()
          Constructor.
 
Method Summary
 void enableEvents()
          This method enables processing of events.
 void enableIncomingText()
          This method enables processing of incoming text.
 void endDaemon()
          Called by the framework when the daemon is shut down.
 java.lang.String getClassName()
          Gets the class name.
 java.lang.String getName()
          Called by the framework to get the name of the daemon.
 java.net.URL getResource(java.lang.String resource)
          Finds a resource with a given name.
 boolean initDaemon()
          Called by the framework to initialise the daemon.
 void onEvent(EventIfc event)
          This method is called for each posted event.
 void onText(java.lang.String buffer, java.lang.String text)
          This method is called when new text has arrived from the game server.
 void onTimer(java.util.Date time)
          This method is called when the timer is triggered.
 void postEvent(UserDefinedEvent event)
          This method posts an event in the SWATH event queue.
 void printTrace(java.lang.Exception e)
          Print an exception and the complete stack trace in the SWATH console window.
 void printTrace(java.lang.String text)
          Print trace text in the SWATH console window.
 void setBufferText(java.lang.String text)
          Sets the current text buffer content.
 void setTimer(java.util.Date time)
          This method sets the timer.
 void setTimer(long delay)
          This method sets the timer to the current time plus the delay.
 void skipBufferText(int count)
          Removes characters from the current text buffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserDefinedDaemon

public UserDefinedDaemon()
Constructor.

Method Detail

getClassName

public final java.lang.String getClassName()
Gets the class name.

Returns:
The daemon class name.
Since:
SWATH 1.7

getResource

public final java.net.URL getResource(java.lang.String resource)
Finds a resource with a given name. The search is done using the class path.

Parameters:
resource - The name of the wanted resource.
Returns:
The URL to the wanted resource or null if not found.
Since:
SWATH 1.7

enableEvents

public final void enableEvents()
This method enables processing of events.
You must call this method from initDaemon.
If enabled, the onEvent method will be called for each new event in the SWATH event queue.

Since:
SWATH 1.7
See Also:
onEvent(com.swath.EventIfc), initDaemon()

enableIncomingText

public final void enableIncomingText()
This method enables processing of incoming text.
You must call this method from initDaemon.
If enabled, the onText method will be called when there is new text from the game server.

Since:
SWATH 1.7
See Also:
onText(java.lang.String, java.lang.String), initDaemon()

skipBufferText

public final void skipBufferText(int count)
Removes characters from the current text buffer.

Parameters:
count - Number of characters to remove.
Since:
SWATH 1.7.1
See Also:
setBufferText(java.lang.String), onText(java.lang.String, java.lang.String)

setBufferText

public final void setBufferText(java.lang.String text)
Sets the current text buffer content.

Parameters:
text - The new content.
Since:
SWATH 1.7.1
See Also:
skipBufferText(int), onText(java.lang.String, java.lang.String)

postEvent

public final void postEvent(UserDefinedEvent event)
This method posts an event in the SWATH event queue. Everyone that listens for this event will be notified.

Parameters:
event - The event to post.
Since:
SWATH 1.7

setTimer

public final void setTimer(java.util.Date time)
This method sets the timer. If the given time has already occured, the timer will be activated immediately.

Parameters:
time - When the timer should trigger or null to reset the timer.
Since:
SWATH 1.7
See Also:
onTimer(java.util.Date), setTimer(long)

setTimer

public final void setTimer(long delay)
This method sets the timer to the current time plus the delay. If the delay is zero, the timer will be activated immediately. A negative delay value will reset the timer.

Parameters:
delay - The delay in milliseconds.
Since:
SWATH 1.7
See Also:
onTimer(java.util.Date), setTimer(Date)

printTrace

public final void printTrace(java.lang.String text)
                      throws java.lang.Exception
Print trace text in the SWATH console window.

Parameters:
text - The text to print.
Throws:
java.lang.Exception
Since:
SWATH 1.7

printTrace

public final void printTrace(java.lang.Exception e)
                      throws java.lang.Exception
Print an exception and the complete stack trace in the SWATH console window.

Parameters:
e - The exception to print.
Throws:
java.lang.Exception
Since:
SWATH 1.7

getName

public java.lang.String getName()
Called by the framework to get the name of the daemon.
You should override this method.

Returns:
The daemon name.
Since:
SWATH 1.7

initDaemon

public boolean initDaemon()
                   throws java.lang.Exception
Called by the framework to initialise the daemon.
You should override this method to make your own initialisation.

Returns:
true if the initialisation was successful, otherwise false.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
enableEvents(), enableIncomingText(), postEvent(com.swath.UserDefinedEvent), setTimer(java.util.Date), printTrace(java.lang.String), onTimer(java.util.Date), onText(java.lang.String, java.lang.String), onEvent(com.swath.EventIfc)

endDaemon

public void endDaemon()
               throws java.lang.Exception
Called by the framework when the daemon is shut down.
You can override this method to clean up after the daemon if needed.

Throws:
java.lang.Exception
Since:
SWATH 1.7

onTimer

public void onTimer(java.util.Date time)
             throws java.lang.Exception
This method is called when the timer is triggered.

Parameters:
time - The current time.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
postEvent(com.swath.UserDefinedEvent), setTimer(java.util.Date), printTrace(java.lang.String)

onText

public void onText(java.lang.String buffer,
                   java.lang.String text)
            throws java.lang.Exception
This method is called when new text has arrived from the game server.
You can override this method to handle incoming text.
You must call setIncomingTextMode to enable this callback method.

The current text buffer contains both the previous text and the new text that just arrived. You can use it when searching for information using the string helper methods. To remove text from the current buffer or reset its content, use the skipBufferText and setBufferText methods.

Parameters:
buffer - The current text buffer.
text - The new incoming text.
Throws:
java.lang.Exception
Since:
SWATH 1.7.1
See Also:
enableIncomingText(), skipBufferText(int), setBufferText(java.lang.String), postEvent(com.swath.UserDefinedEvent), setTimer(java.util.Date), printTrace(java.lang.String)

onEvent

public void onEvent(EventIfc event)
             throws java.lang.Exception
This method is called for each posted event.
You can override this method to handle events.

Parameters:
event - The event.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
enableEvents(), postEvent(com.swath.UserDefinedEvent), setTimer(java.util.Date), printTrace(java.lang.String)