Asterisk-Java

org.asteriskjava.fastagi
Class AgiServerThread

java.lang.Object
  extended by org.asteriskjava.fastagi.AgiServerThread

public class AgiServerThread
extends java.lang.Object

Runs an AgiServer in a separate Thread.

You can use this class to run an AgiServer in the background of your application or run it in your servlet container or application server.

By default the thread used by this class is marked as daemon thread, that means it will be destroyed when the last user thread has finished.

Since:
0.2
Version:
$Id: AgiServerThread.java 1355 2009-08-31 13:23:44Z srt $
Author:
srt

Constructor Summary
AgiServerThread()
          Creates a new AgiServerThread.
AgiServerThread(AgiServer agiServer)
          Creates a new AgiServerThread that runs the given AgiServer.
 
Method Summary
protected  java.lang.Thread createThread()
           
 void setAgiServer(AgiServer agiServer)
          Sets the AgiServer to run.
 void setDaemon(boolean daemon)
          Marks the thread as either a daemon thread or a user thread.
 void shutdown()
          Stops the AgiServer.
 void startup()
          Starts the AgiServer in its own thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgiServerThread

public AgiServerThread()
Creates a new AgiServerThread.

Before you can run this thread you must set an AgiServer using setAgiServer(AgiServer).

This constructor is mainly intended for use with setter based dependency injection.


AgiServerThread

public AgiServerThread(AgiServer agiServer)
Creates a new AgiServerThread that runs the given AgiServer.

Parameters:
agiServer - the AgiServer to run.
Method Detail

setAgiServer

public void setAgiServer(AgiServer agiServer)
Sets the AgiServer to run.

This property must be set before starting the AgiServerThread by calling startup.

Parameters:
agiServer - the AgiServer to run.

setDaemon

public void setDaemon(boolean daemon)
Marks the thread as either a daemon thread or a user thread.

Default is true.

Parameters:
daemon - if false, marks the thread as a user thread.
Since:
0.3
See Also:
Thread.setDaemon(boolean)

startup

public void startup()
             throws java.lang.IllegalStateException,
                    java.lang.RuntimeException
Starts the AgiServer in its own thread.

Note: The AgiServerThread is designed to handle one AgiServer instance at a time so calling this method twice without stopping the AgiServer in between will result in a RuntimeException.

Throws:
java.lang.IllegalStateException - if the mandatory property agiServer has not been set or the AgiServer had already been started.
java.lang.RuntimeException - if the AgiServer can't be started due to IO problems, for example because the socket has already been bound by another process.

createThread

protected java.lang.Thread createThread()

shutdown

public void shutdown()
              throws java.lang.IllegalStateException
Stops the AgiServer.

The AgiServer must have been started by calling startup() before you can stop it.

Throws:
java.lang.IllegalStateException - if the mandatory property agiServer has not been set or the AgiServer had already been shut down.
See Also:
AgiServer.shutdown()

Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.