net.sf.asterisk.manager
Class DefaultAsteriskManager

java.lang.Object
  extended by net.sf.asterisk.manager.DefaultAsteriskManager
All Implemented Interfaces:
java.util.EventListener, AsteriskManager, ManagerEventHandler

public class DefaultAsteriskManager
extends java.lang.Object
implements AsteriskManager, ManagerEventHandler

Default implementation of the AsteriskManager interface.

Version:
$Id: DefaultAsteriskManager.java,v 1.23 2005/10/29 12:09:05 srt Exp $
Author:
srt
See Also:
AsteriskManager

Constructor Summary
DefaultAsteriskManager()
          Creates a new instance.
DefaultAsteriskManager(ManagerConnection connection)
          Creates a new instance.
 
Method Summary
protected  void addChannel(Channel channel)
           
protected  void addQueue(Queue queue)
           
 Channel getChannelById(java.lang.String id)
          Returns a channel by its unique id.
 Channel getChannelByName(java.lang.String name)
          Returns a channel by its name.
 java.util.Map getChannels()
          Returns a map of all active channel by their unique id.
 java.util.Map getQueues()
          Returns a Map of all queues.
The map contains the queue names as keys and objects of type Queue as values.
 java.lang.String getVersion()
          Returns the version of the Asterisk server you are connected to.
This typically looks like "Asterisk 1.0.9 built by root@host on a i686 running Linux".
 int[] getVersion(java.lang.String file)
          Returns the CVS revision of a given source file of the Asterisk server you are connected to.
For example getVersion("app_meetme.c") may return {1, 102} for CVS revision "1.102".
Note that this feature is not available with Asterisk 1.0.x.
You can use this feature if you need to write applications that behave different depending on specific modules being available in a specific version or not.
protected  void handleConnectEvent(ConnectEvent connectEvent)
          Requests the current state from the asterisk server after the connection to the asterisk server is restored.
protected  void handleDisconnectEvent(DisconnectEvent disconnectEvent)
          Resets the internal state when the connection to the asterisk server is lost.
 void handleEvent(ManagerEvent event)
          Handles all events received from the asterisk server.
Events are queued until channels and queues are initialized and then delegated to the dispatchEvent method.
protected  void handleHangupEvent(HangupEvent event)
           
protected  void handleJoinEvent(JoinEvent event)
           
protected  void handleLeaveEvent(LeaveEvent event)
           
protected  void handleLinkEvent(LinkEvent event)
           
protected  void handleNewCallerIdEvent(NewCallerIdEvent event)
           
protected  void handleNewChannelEvent(NewChannelEvent event)
           
protected  void handleNewExtenEvent(NewExtenEvent event)
           
protected  void handleNewStateEvent(NewStateEvent event)
           
protected  void handleQueueEntryEvent(QueueEntryEvent event)
           
protected  void handleQueueMemberEvent(QueueMemberEvent event)
           
protected  void handleQueueParamsEvent(QueueParamsEvent event)
           
protected  void handleRenameEvent(RenameEvent event)
           
protected  void handleStatusEvent(StatusEvent event)
           
protected  void handleUnlinkEvent(UnlinkEvent event)
           
 void initialize()
           
 Call originateCall(Originate originate)
          Generates an outgoing call.
protected  Call originateEvent2Call(OriginateEvent event)
           
protected  void removeChannel(Channel channel)
           
protected  void removeQueue(Queue queue)
           
 void setManagerConnection(ManagerConnection connection)
           
 void setSkipQueues(boolean skipQueues)
          Determines if queue status is retrieved at startup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAsteriskManager

public DefaultAsteriskManager()
Creates a new instance.


DefaultAsteriskManager

public DefaultAsteriskManager(ManagerConnection connection)
Creates a new instance.

Parameters:
connection - the manager connection to use
Method Detail

setSkipQueues

public void setSkipQueues(boolean skipQueues)
Determines if queue status is retrieved at startup. If you don't need queue information and still run Asterisk 1.0.x you can set this to true to circumvent the startup delay caused by the missing QueueStatusComplete event.
Default is false.

Parameters:
skipQueues - true to skip queue initialization, false to not skip.
Since:
0.2

setManagerConnection

public void setManagerConnection(ManagerConnection connection)

initialize

public void initialize()
                throws TimeoutException,
                       java.io.IOException,
                       AuthenticationFailedException
Throws:
TimeoutException
java.io.IOException
AuthenticationFailedException

originateCall

public Call originateCall(Originate originate)
                   throws TimeoutException,
                          java.io.IOException
Description copied from interface: AsteriskManager
Generates an outgoing call.

Specified by:
originateCall in interface AsteriskManager
Parameters:
originate - conatins the details of the call to originate
Returns:
a Call object representing the originated call
Throws:
TimeoutException - if the originated call is not answered in time
java.io.IOException - if the action cannot be sent to the asterisk server

getChannels

public java.util.Map getChannels()
Returns a map of all active channel by their unique id.

Specified by:
getChannels in interface AsteriskManager
Returns:
a Map of active channels.

getQueues

public java.util.Map getQueues()
Description copied from interface: AsteriskManager
Returns a Map of all queues.
The map contains the queue names as keys and objects of type Queue as values.

Specified by:
getQueues in interface AsteriskManager
Returns:
a Map of queues.

getVersion

public java.lang.String getVersion()
Description copied from interface: AsteriskManager
Returns the version of the Asterisk server you are connected to.
This typically looks like "Asterisk 1.0.9 built by root@host on a i686 running Linux".

Specified by:
getVersion in interface AsteriskManager
Returns:
the version of the Asterisk server you are connected to

getVersion

public int[] getVersion(java.lang.String file)
Description copied from interface: AsteriskManager
Returns the CVS revision of a given source file of the Asterisk server you are connected to.
For example getVersion("app_meetme.c") may return {1, 102} for CVS revision "1.102".
Note that this feature is not available with Asterisk 1.0.x.
You can use this feature if you need to write applications that behave different depending on specific modules being available in a specific version or not.

Specified by:
getVersion in interface AsteriskManager
Parameters:
file - the file for which to get the version like "app_meetme.c"
Returns:
the CVS revision of the file, or null if that file is not part of the Asterisk instance you are connected to (maybe due to a module that provides it has not been loaded) or if you are connected to an Astersion 1.0.x

handleEvent

public void handleEvent(ManagerEvent event)
Handles all events received from the asterisk server.
Events are queued until channels and queues are initialized and then delegated to the dispatchEvent method.

Specified by:
handleEvent in interface ManagerEventHandler
Parameters:
event - the event received

addChannel

protected void addChannel(Channel channel)

removeChannel

protected void removeChannel(Channel channel)

addQueue

protected void addQueue(Queue queue)

removeQueue

protected void removeQueue(Queue queue)

handleStatusEvent

protected void handleStatusEvent(StatusEvent event)

handleDisconnectEvent

protected void handleDisconnectEvent(DisconnectEvent disconnectEvent)
Resets the internal state when the connection to the asterisk server is lost.


handleConnectEvent

protected void handleConnectEvent(ConnectEvent connectEvent)
Requests the current state from the asterisk server after the connection to the asterisk server is restored.


handleQueueParamsEvent

protected void handleQueueParamsEvent(QueueParamsEvent event)

handleQueueMemberEvent

protected void handleQueueMemberEvent(QueueMemberEvent event)

handleQueueEntryEvent

protected void handleQueueEntryEvent(QueueEntryEvent event)

handleJoinEvent

protected void handleJoinEvent(JoinEvent event)

handleLeaveEvent

protected void handleLeaveEvent(LeaveEvent event)

getChannelByName

public Channel getChannelByName(java.lang.String name)
Returns a channel by its name.

Parameters:
name - name of the channel to return
Returns:
the channel with the given name

getChannelById

public Channel getChannelById(java.lang.String id)
Returns a channel by its unique id.

Parameters:
id - the unique id of the channel to return
Returns:
the channel with the given unique id

handleNewChannelEvent

protected void handleNewChannelEvent(NewChannelEvent event)

handleNewExtenEvent

protected void handleNewExtenEvent(NewExtenEvent event)

handleNewStateEvent

protected void handleNewStateEvent(NewStateEvent event)

handleNewCallerIdEvent

protected void handleNewCallerIdEvent(NewCallerIdEvent event)

handleHangupEvent

protected void handleHangupEvent(HangupEvent event)

handleLinkEvent

protected void handleLinkEvent(LinkEvent event)

handleUnlinkEvent

protected void handleUnlinkEvent(UnlinkEvent event)

handleRenameEvent

protected void handleRenameEvent(RenameEvent event)

originateEvent2Call

protected Call originateEvent2Call(OriginateEvent event)


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