|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ManagerConnection
The main interface to talk to an Asterisk server via the Asterisk Manager
API.
The ManagerConnection repesents a connection to an Asterisk Server and is
capable to send Actions and receive Responses and Events. It does not add any
valuable functionality but rather provides a Java view to Asterisk's Manager
API (freeing you from TCP/IP connection and parsing stuff).
It is used as the foundation for higher leveled interfaces like the
AsteriskManager.
A concrete implementation of this interface can be obtained from a
ManagerConnectionFactory.
ManagerConnectionFactory
Method Summary | |
---|---|
void |
addEventHandler(ManagerEventHandler eventHandler)
Registers an event handler to be called whenever an ManagerEvent is receiced from the
Asterisk server.Event handlers are notified about new events in the same order as they were registered via addEventHandler. |
AsteriskServer |
getAsteriskServer()
Returns the Asterisk server of this connection. |
java.lang.String |
getProtocolIdentifier()
Returns the protocol identifier, i.e. |
boolean |
isConnected()
Checks if the connection to the Asterisk server is established. |
void |
login()
Logs in to the Asterisk server with the username and password specified when this connection was created. |
void |
logoff()
Sends a LogoffAction to the Asterisk server and disconnects. |
void |
registerUserEventClass(java.lang.Class userEventClass)
Registers a new user event type. Asterisk allows you to send custom events via the UserEvent application. |
void |
removeEventHandler(ManagerEventHandler eventHandler)
Unregisters a previously registered event handler. Does nothing if the given event handler hasn't be been regiered before. |
ManagerResponse |
sendAction(ManagerAction action)
Sends a ManagerAction to the Asterisk server and waits for the corresponding ManagerResponse. |
ManagerResponse |
sendAction(ManagerAction action,
long timeout)
Sends a ManagerAction to the Asterisk server and waits for the corresponding ManagerResponse. |
void |
sendAction(ManagerAction action,
ManagerResponseHandler callbackHandler)
Sends a ManagerAction to the Asterisk server and registers a callback handler to be called when the corresponding ManagerResponse is received. |
ResponseEvents |
sendEventGeneratingAction(EventGeneratingAction action)
Sends a EventGeneratingAction to the Asterisk server and waits for the corresponding ManagerResponse and the ResponseEvents. EventGeneratingActions are ManagerActions that don't return their response in the corresponding ManagerResponse but send a series of events that contain the payload. Examples for EventGeneratingActions are the StatusAction , the
net.sf.asterisk.manager.action.QueueAction or the
AgentsAction . |
ResponseEvents |
sendEventGeneratingAction(EventGeneratingAction action,
long timeout)
Sends a EventGeneratingAction to the Asterisk server and waits for the corresponding ManagerResponse and the ResponseEvents. |
void |
setSocketTimeout(int socketTimeout)
The timeout to use when connecting the the Asterisk server. Default is 0, that is using Java's built-in default. |
Method Detail |
---|
void registerUserEventClass(java.lang.Class userEventClass)
manager_event()
function directly and don't use the
channel and uniqueid attributes provided by UserEvent you can also
register events that directly subclass ManagerEvent.
userEventClass
- the class of the user event to register.UserEvent
,
ManagerEvent
void setSocketTimeout(int socketTimeout)
socketTimeout
- the timeout value to be used in milliseconds.Socket.connect(java.net.SocketAddress, int)
void login() throws java.io.IOException, AuthenticationFailedException, TimeoutException
java.io.IOException
- if the network connection is disrupted.
AuthenticationFailedException
- if the username and/or password are
incorrect or the ChallengeResponse could not be built.
TimeoutException
- if no response is received within the default
timeout period. If the implementation uses challenge/response
this can either be a timeout of the ChallengeAction or the
LoginAction; otherwise it is always a timeout of the
LoginAction.LoginAction
,
ChallengeAction
void logoff() throws java.io.IOException, TimeoutException
java.io.IOException
- if the network connection is disrupted.
TimeoutException
- if no response to the logoff action is received
within the default timeout period.LogoffAction
java.lang.String getProtocolIdentifier()
null
otherwiseManagerResponse sendAction(ManagerAction action) throws java.io.IOException, TimeoutException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
action
- the action to send to the Asterisk server
java.io.IOException
- if the network connection is disrupted.
TimeoutException
- if no response is received within the default
timeout period.
java.lang.IllegalArgumentException
- if the action is null
.
java.lang.IllegalStateException
- if you are not connected to an Asterisk
server.sendAction(ManagerAction, long)
,
sendAction(ManagerAction, ManagerResponseHandler)
ManagerResponse sendAction(ManagerAction action, long timeout) throws java.io.IOException, TimeoutException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
action
- the action to send to the Asterisk servertimeout
- milliseconds to wait for the response before throwing a
TimeoutException
java.io.IOException
- if the network connection is disrupted.
TimeoutException
- if no response is received within the given
timeout period.
java.lang.IllegalArgumentException
- if the action is null
.
java.lang.IllegalStateException
- if you are not connected to an Asterisk
server.sendAction(ManagerAction, ManagerResponseHandler)
void sendAction(ManagerAction action, ManagerResponseHandler callbackHandler) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
action
- the action to send to the Asterisk servercallbackHandler
- the callback handler to call when the response is
received or null
if you are not interested in
the response
java.io.IOException
- if the network connection is disrupted.
java.lang.IllegalArgumentException
- if the action is null
.
java.lang.IllegalStateException
- if you are not connected to an Asterisk
server.ResponseEvents sendEventGeneratingAction(EventGeneratingAction action) throws java.io.IOException, EventTimeoutException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
StatusAction
, the
net.sf.asterisk.manager.action.QueueAction
or the
AgentsAction
.
action
- the action to send to the Asterisk server
java.io.IOException
- if the network connection is disrupted.
EventTimeoutException
- if no response or not all response events are
received within the given timeout period.
java.lang.IllegalArgumentException
- if the action is null
,
the actionCompleteEventClass property of the action is
null
or if actionCompleteEventClass is not a
ResponseEvent.
java.lang.IllegalStateException
- if you are not connected to an Asterisk
server.EventGeneratingAction
,
ResponseEvent
ResponseEvents sendEventGeneratingAction(EventGeneratingAction action, long timeout) throws java.io.IOException, EventTimeoutException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
StatusAction
, the
net.sf.asterisk.manager.action.QueueAction
or the
AgentsAction
.
action
- the action to send to the Asterisk servertimeout
- milliseconds to wait for the response and the response
events before throwing a TimeoutException
java.io.IOException
- if the network connection is disrupted.
EventTimeoutException
- if no response or not all response events are
received within the given timeout period.
java.lang.IllegalArgumentException
- if the action is null
,
the actionCompleteEventClass property of the action is
null
or if actionCompleteEventClass is not a
ResponseEvent.
java.lang.IllegalStateException
- if you are not connected to an Asterisk
server.EventGeneratingAction
,
ResponseEvent
void addEventHandler(ManagerEventHandler eventHandler)
ManagerEvent
is receiced from the
Asterisk server.
eventHandler
- the handler to call whenever a manager event is
receivedremoveEventHandler(ManagerEventHandler)
void removeEventHandler(ManagerEventHandler eventHandler)
eventHandler
- the event handle to unregisteraddEventHandler(ManagerEventHandler)
AsteriskServer getAsteriskServer()
boolean isConnected()
true
if the connection is established,
false
otherwise.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |