Thread: [Asterisk-java-cvs] CVS: asterisk-java/src/net/sf/asterisk/manager AsteriskServer.java,NONE,1.1 Mana
Brought to you by:
srt
From: PY R. <par...@us...> - 2005-02-04 18:54:14
|
Update of /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25685/src/net/sf/asterisk/manager Modified Files: ManagerReader.java DefaultManagerConnection.java ManagerConnection.java Channel.java MultiAsterisksManager.java DefaultAsteriskManager.java Added Files: AsteriskServer.java Log Message: Add new class : AsteriskServer to manage multiServers. --- NEW FILE: AsteriskServer.java --- /* * Created on 3 févr. 2005 by Pierre-Yves ROGER. * */ package net.sf.asterisk.manager; import java.io.Serializable; /** * @author PY * net.sf.asterisk.manager, AsteriskServer.java */ public class AsteriskServer implements Serializable { /** * */ private String hostname = "localhost"; private int port = 5038 ; public AsteriskServer() { } public AsteriskServer(String hostname, int port) { this.hostname=hostname ; this.port=port ; } /** * @return Returns the hostname. */ public String getHostname() { return hostname; } /** * @param hostname The hostname to set. */ public void setHostname(String hostname) { this.hostname = hostname; } /** * @return Returns the port. */ public int getPort() { return port; } /** * @param port The port to set. */ public void setPort(int port) { this.port = port; } } Index: ManagerReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/ManagerReader.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -p -r1.15 -r1.16 --- ManagerReader.java 29 Jan 2005 10:59:57 -0000 1.15 +++ ManagerReader.java 4 Feb 2005 18:54:03 -0000 1.16 @@ -1,275 +1,275 @@ -/* - * (c) 2004 Stefan Reuter - * - * Created on Apr 22, 2004 - */ -package net.sf.asterisk.manager; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.sf.asterisk.manager.event.ManagerEvent; -import net.sf.asterisk.manager.response.ChallengeResponse; -import net.sf.asterisk.manager.response.CommandResponse; -import net.sf.asterisk.manager.response.ExtensionStateResponse; -import net.sf.asterisk.manager.response.MailboxCountResponse; -import net.sf.asterisk.manager.response.MailboxStatusResponse; -import net.sf.asterisk.manager.response.ManagerError; -import net.sf.asterisk.manager.response.ManagerResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * The ManagerReader is a Thread that reads events and responses from an asterisk - * server, parses them to the corresponding ManagerEvent and ManagerResponse objects and - * dispatches them via the associated DefaultManagerConnection. - * <br> - * This class is intended to be used only by the DefaultManagerConnection. - * - * @see net.sf.asterisk.manager.event.ManagerEvent - * @see net.sf.asterisk.manager.response.ManagerResponse - * @see net.sf.asterisk.manager.DefaultManagerConnection - * - * @author srt - * @version $Id$ - */ -class ManagerReader extends Thread -{ - private Log log = LogFactory.getLog(getClass()); - - private static int threadCount = 0; - private EventBuilder eventBuilder; - private boolean die = false; - private BufferedReader reader; - private DefaultManagerConnection connection; - - ManagerReader(DefaultManagerConnection connection, BufferedReader reader) - { - int i = threadCount++; - setName("ManagerReader-" + i); - - this.connection = connection; - this.reader = reader; - - this.eventBuilder = new EventBuilder(); - } - - /** - * Reads line by line from the asterisk server, sets the protocol identifier - * as soon as it is received and dispatches the received - * events and responses via the associated connection. - * - * @see DefaultManagerConnection#dispatchEvent(ManagerEvent) - * @see DefaultManagerConnection#dispatchResponse(ManagerResponse) - * @see DefaultManagerConnection#setProtocolIdentifier(String) - */ - public void run() - { - String line; - List commandResult = new ArrayList(); - boolean processingCommandResult = false; - Map buffer = new HashMap(); - - try - { - while ((line = reader.readLine()) != null && !die) - { - // dirty hack for handling the CommandAction. Needs fix when manager protocol is enhanced. - if (processingCommandResult) - { - if ("--END COMMAND--".equals(line)) - { - CommandResponse commandResponse = new CommandResponse(); - - if (!commandResult.isEmpty() - && ((String) commandResult.get(0)).startsWith("ActionID")) - { - String tmp = (String) commandResult.get(0); - int delimiterIndex = tmp.indexOf(":"); - if (delimiterIndex > 0 && tmp.length() > delimiterIndex + 2) - { - commandResult.remove(0); - commandResponse.setActionId(tmp.substring(delimiterIndex + 2)); - } - } - commandResponse.setResponse("Follows"); - commandResponse.setDateReceived(new Date()); - commandResponse.setResult(commandResult); - connection.dispatchResponse(commandResponse); - commandResult = new ArrayList(); - processingCommandResult = false; - } - else - { - commandResult.add(line); - } - continue; - } - if ("Response: Follows".equalsIgnoreCase(line)) - { - processingCommandResult = true; - continue; - } - - // maybe we will find a better way to identify the protocol identifier but for now - // this works quite well. - if (line.startsWith("Asterisk Call Manager/") - && connection.getProtocolIdentifier() == null) - { - connection.setProtocolIdentifier(line); - continue; - } - - // an empty line indicates a normal response's or event's end so we build - // the corresponding value object and dispatch it through the ManagerConnection. - if (line.length() == 0) - { - if (buffer.containsKey("response")) - { - ManagerResponse response = buildResponse(buffer); - if (response != null) - { - connection.dispatchResponse(response); - } - } - else if (buffer.containsKey("event")) - { - ManagerEvent event = buildEvent(connection, buffer); - if (event != null) - { - connection.dispatchEvent(event); - } - } - - buffer.clear(); - } - else - { - int delimiterIndex; - - delimiterIndex = line.indexOf(":"); - if (delimiterIndex > 0 && line.length() > delimiterIndex + 2) - { - String name; - String value; - - name = line.substring(0, delimiterIndex).toLowerCase(); - value = line.substring(delimiterIndex + 2); - - buffer.put(name, value); - } - } - } - connection.handleDisconnection(); - } - catch (IOException e) - { - log.warn("IOException while reading from asterisk server, terminating thread.", e); - } - finally - { - log.info("Disconnected, closing reader"); - try - { - reader.close(); - } - catch (IOException ex) - { - log.warn("Unable to close reader", ex); - } - } - } - - public void die() - { - this.die = true; - } - - private ManagerResponse buildResponse(Map buffer) - { - ManagerResponse response; - String responseType = (String) buffer.get("response"); - - // determine type - if ("error".equals(responseType)) - { - response = new ManagerError(); - } - else if (buffer.containsKey("challenge")) - { - ChallengeResponse challengeResponse = new ChallengeResponse(); - challengeResponse.setChallenge((String) buffer.get("challenge")); - response = challengeResponse; - } - else if (buffer.containsKey("mailbox") && buffer.containsKey("waiting")) - { - MailboxStatusResponse mailboxStatusResponse = new MailboxStatusResponse(); - mailboxStatusResponse.setMailbox((String) buffer.get("mailbox")); - mailboxStatusResponse.setWaiting(new Integer((String) buffer.get("mailbox"))); - response = mailboxStatusResponse; - } - else if (buffer.containsKey("mailbox") && buffer.containsKey("newmessages") - && buffer.containsKey("oldmessages")) - { - MailboxCountResponse mailboxCountResponse = new MailboxCountResponse(); - mailboxCountResponse.setMailbox((String) buffer.get("mailbox")); - mailboxCountResponse.setNewMessages(new Integer((String) buffer.get("newmessages"))); - mailboxCountResponse.setOldMessages(new Integer((String) buffer.get("oldmessages"))); - response = mailboxCountResponse; - } - else if (buffer.containsKey("exten") && buffer.containsKey("context") - && buffer.containsKey("hint") && buffer.containsKey("status")) - { - ExtensionStateResponse extensionStateResponse = new ExtensionStateResponse(); - extensionStateResponse.setExten((String) buffer.get("exten")); - extensionStateResponse.setContext((String) buffer.get("context")); - extensionStateResponse.setHint((String) buffer.get("hint")); - extensionStateResponse.setStatus(new Integer((String) buffer.get("status"))); - response = extensionStateResponse; - } - else - { - response = new ManagerResponse(); - } - - // fill known attributes - response.setResponse(responseType); - - if (buffer.containsKey("actionid")) - { - response.setActionId((String) buffer.get("actionid")); - } - if (buffer.containsKey("message")) - { - response.setMessage((String) buffer.get("message")); - } - if (buffer.containsKey("uniqueid")) - { - response.setUniqueId((String) buffer.get("uniqueid")); - } - - response.setDateReceived(new Date()); - - return response; - } - - private ManagerEvent buildEvent(Object source, Map buffer) - { - ManagerEvent event; - - event = this.eventBuilder.buildEvent(source, buffer); - - if (event != null) - { - event.setDateReceived(new Date()); - } - - return event; - } +/* + * (c) 2004 Stefan Reuter + * + * Created on Apr 22, 2004 + */ +package net.sf.asterisk.manager; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.asterisk.manager.event.ManagerEvent; +import net.sf.asterisk.manager.response.ChallengeResponse; +import net.sf.asterisk.manager.response.CommandResponse; +import net.sf.asterisk.manager.response.ExtensionStateResponse; +import net.sf.asterisk.manager.response.MailboxCountResponse; +import net.sf.asterisk.manager.response.MailboxStatusResponse; +import net.sf.asterisk.manager.response.ManagerError; +import net.sf.asterisk.manager.response.ManagerResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The ManagerReader is a Thread that reads events and responses from an asterisk + * server, parses them to the corresponding ManagerEvent and ManagerResponse objects and + * dispatches them via the associated DefaultManagerConnection. + * <br> + * This class is intended to be used only by the DefaultManagerConnection. + * + * @see net.sf.asterisk.manager.event.ManagerEvent + * @see net.sf.asterisk.manager.response.ManagerResponse + * @see net.sf.asterisk.manager.DefaultManagerConnection + * + * @author srt + * @version $Id$ + */ +class ManagerReader extends Thread +{ + private Log log = LogFactory.getLog(getClass()); + + private static int threadCount = 0; + private EventBuilder eventBuilder; + private boolean die = false; + private BufferedReader reader; + private DefaultManagerConnection connection; + + ManagerReader(DefaultManagerConnection connection, BufferedReader reader) + { + int i = threadCount++; + setName("ManagerReader-" + i); + + this.connection = connection; + this.reader = reader; + + this.eventBuilder = new EventBuilder(); + } + + /** + * Reads line by line from the asterisk server, sets the protocol identifier + * as soon as it is received and dispatches the received + * events and responses via the associated connection. + * + * @see DefaultManagerConnection#dispatchEvent(ManagerEvent) + * @see DefaultManagerConnection#dispatchResponse(ManagerResponse) + * @see DefaultManagerConnection#setProtocolIdentifier(String) + */ + public void run() + { + String line; + List commandResult = new ArrayList(); + boolean processingCommandResult = false; + Map buffer = new HashMap(); + + try + { + while ((line = reader.readLine()) != null && !die) + { + // dirty hack for handling the CommandAction. Needs fix when manager protocol is enhanced. + if (processingCommandResult) + { + if ("--END COMMAND--".equals(line)) + { + CommandResponse commandResponse = new CommandResponse(); + + if (!commandResult.isEmpty() + && ((String) commandResult.get(0)).startsWith("ActionID")) + { + String tmp = (String) commandResult.get(0); + int delimiterIndex = tmp.indexOf(":"); + if (delimiterIndex > 0 && tmp.length() > delimiterIndex + 2) + { + commandResult.remove(0); + commandResponse.setActionId(tmp.substring(delimiterIndex + 2)); + } + } + commandResponse.setResponse("Follows"); + commandResponse.setDateReceived(new Date()); + commandResponse.setResult(commandResult); + connection.dispatchResponse(commandResponse); + commandResult = new ArrayList(); + processingCommandResult = false; + } + else + { + commandResult.add(line); + } + continue; + } + if ("Response: Follows".equalsIgnoreCase(line)) + { + processingCommandResult = true; + continue; + } + + // maybe we will find a better way to identify the protocol identifier but for now + // this works quite well. + if (line.startsWith("Asterisk Call Manager/") + && connection.getProtocolIdentifier() == null) + { + connection.setProtocolIdentifier(line); + continue; + } + + // an empty line indicates a normal response's or event's end so we build + // the corresponding value object and dispatch it through the ManagerConnection. + if (line.length() == 0) + { + if (buffer.containsKey("response")) + { + ManagerResponse response = buildResponse(buffer); + if (response != null) + { + connection.dispatchResponse(response); + } + } + else if (buffer.containsKey("event")) + { + ManagerEvent event = buildEvent(connection.getAsteriskServer(), buffer); + if (event != null) + { + connection.dispatchEvent(event); + } + } + + buffer.clear(); + } + else + { + int delimiterIndex; + + delimiterIndex = line.indexOf(":"); + if (delimiterIndex > 0 && line.length() > delimiterIndex + 2) + { + String name; + String value; + + name = line.substring(0, delimiterIndex).toLowerCase(); + value = line.substring(delimiterIndex + 2); + + buffer.put(name, value); + } + } + } + connection.handleDisconnection(); + } + catch (IOException e) + { + log.warn("IOException while reading from asterisk server, terminating thread.", e); + } + finally + { + log.info("Disconnected, closing reader"); + try + { + reader.close(); + } + catch (IOException ex) + { + log.warn("Unable to close reader", ex); + } + } + } + + public void die() + { + this.die = true; + } + + private ManagerResponse buildResponse(Map buffer) + { + ManagerResponse response; + String responseType = (String) buffer.get("response"); + + // determine type + if ("error".equals(responseType)) + { + response = new ManagerError(); + } + else if (buffer.containsKey("challenge")) + { + ChallengeResponse challengeResponse = new ChallengeResponse(); + challengeResponse.setChallenge((String) buffer.get("challenge")); + response = challengeResponse; + } + else if (buffer.containsKey("mailbox") && buffer.containsKey("waiting")) + { + MailboxStatusResponse mailboxStatusResponse = new MailboxStatusResponse(); + mailboxStatusResponse.setMailbox((String) buffer.get("mailbox")); + mailboxStatusResponse.setWaiting(new Integer((String) buffer.get("mailbox"))); + response = mailboxStatusResponse; + } + else if (buffer.containsKey("mailbox") && buffer.containsKey("newmessages") + && buffer.containsKey("oldmessages")) + { + MailboxCountResponse mailboxCountResponse = new MailboxCountResponse(); + mailboxCountResponse.setMailbox((String) buffer.get("mailbox")); + mailboxCountResponse.setNewMessages(new Integer((String) buffer.get("newmessages"))); + mailboxCountResponse.setOldMessages(new Integer((String) buffer.get("oldmessages"))); + response = mailboxCountResponse; + } + else if (buffer.containsKey("exten") && buffer.containsKey("context") + && buffer.containsKey("hint") && buffer.containsKey("status")) + { + ExtensionStateResponse extensionStateResponse = new ExtensionStateResponse(); + extensionStateResponse.setExten((String) buffer.get("exten")); + extensionStateResponse.setContext((String) buffer.get("context")); + extensionStateResponse.setHint((String) buffer.get("hint")); + extensionStateResponse.setStatus(new Integer((String) buffer.get("status"))); + response = extensionStateResponse; + } + else + { + response = new ManagerResponse(); + } + + // fill known attributes + response.setResponse(responseType); + + if (buffer.containsKey("actionid")) + { + response.setActionId((String) buffer.get("actionid")); + } + if (buffer.containsKey("message")) + { + response.setMessage((String) buffer.get("message")); + } + if (buffer.containsKey("uniqueid")) + { + response.setUniqueId((String) buffer.get("uniqueid")); + } + + response.setDateReceived(new Date()); + + return response; + } + + private ManagerEvent buildEvent(Object source, Map buffer) + { + ManagerEvent event; + + event = this.eventBuilder.buildEvent(source, buffer); + + if (event != null) + { + event.setDateReceived(new Date()); + } + + return event; + } } \ No newline at end of file Index: DefaultManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/DefaultManagerConnection.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -p -r1.11 -r1.12 --- DefaultManagerConnection.java 1 Feb 2005 17:20:34 -0000 1.11 +++ DefaultManagerConnection.java 4 Feb 2005 18:54:03 -0000 1.12 @@ -47,8 +47,7 @@ public class DefaultManagerConnection im private long actionIdCount = 0; /* Config attributes */ - private String hostname = "localhost"; - private int port = 5038; + private AsteriskServer asteriskServer ; private String username; private String password; private long defaultTimeout = 2000; @@ -67,12 +66,12 @@ public class DefaultManagerConnection im public DefaultManagerConnection() { + this.asteriskServer = new AsteriskServer() ; } public DefaultManagerConnection(String hostname, int port, String username, String password) { - setHostname(hostname); - setPort(port); + this.asteriskServer = new AsteriskServer(hostname,port) ; setUsername(username); setPassword(password); } @@ -85,7 +84,7 @@ public class DefaultManagerConnection im */ public void setHostname(String hostname) { - this.hostname = hostname; + this.asteriskServer.setHostname(hostname) ; } /** @@ -97,7 +96,7 @@ public class DefaultManagerConnection im */ public void setPort(int port) { - this.port = port; + this.asteriskServer.setPort(port); } /** @@ -247,16 +246,16 @@ public class DefaultManagerConnection im logger.info("Successfully logged in"); // notify event listeners - dispatchEvent(new ConnectEvent(this)); + dispatchEvent(new ConnectEvent(this.asteriskServer)); } private void connect() throws IOException { BufferedReader bufferedReader; - logger.info("Connecting to " + hostname + " port " + port); + logger.info("Connecting to " + asteriskServer.getHostname()+ " port " + asteriskServer.getPort()); - this.socket = new Socket(hostname, port); + this.socket = new Socket(asteriskServer.getHostname(),asteriskServer.getPort()); bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); @@ -565,7 +564,7 @@ public class DefaultManagerConnection im disconnect(); // notify event listeners - dispatchEvent(new DisconnectEvent(this)); + dispatchEvent(new DisconnectEvent(this.asteriskServer)); // try to reconnect numTries = 0; @@ -675,10 +674,10 @@ public class DefaultManagerConnection im } } - /* (non-Javadoc) - * @see net.sf.asterisk.manager.ManagerConnection#getHostname() + /** + * @return Returns the asteriskServer. */ - public String getHostname() { - return hostname; + public AsteriskServer getAsteriskServer() { + return asteriskServer; } } \ No newline at end of file Index: ManagerConnection.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/ManagerConnection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- ManagerConnection.java 1 Feb 2005 17:20:34 -0000 1.6 +++ ManagerConnection.java 4 Feb 2005 18:54:03 -0000 1.7 @@ -121,9 +121,9 @@ public interface ManagerConnection void removeEventHandler(ManagerEventHandler eventHandler); /** - * Return hostname of connection + * Return Asterisk server of connection * */ - String getHostname() ; + AsteriskServer getAsteriskServer() ; } \ No newline at end of file Index: Channel.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/Channel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- Channel.java 4 Jan 2005 21:59:55 -0000 1.2 +++ Channel.java 4 Feb 2005 18:54:04 -0000 1.3 @@ -19,6 +19,7 @@ public class Channel implements Serializ { private static final long serialVersionUID = -6919877370396385380L; + private AsteriskServer asteriskServer ; private String id; private String name; private String callerId; @@ -32,6 +33,7 @@ public class Channel implements Serializ private Date dateOfCreation; private Channel linkedChannel; + /** * Creates a new channel. * @param name name of this channel, for example "SIP/1310-20da" @@ -43,6 +45,25 @@ public class Channel implements Serializ this.id = id; } + public Channel(String name, String id, AsteriskServer server) + { + this.name = name; + this.id = id; + this.asteriskServer = server ; + } + + /** + * @return Returns the asteriskServer. + */ + public AsteriskServer getAsteriskServer() { + return asteriskServer; + } + /** + * @param asteriskServer The asteriskServer to set. + */ + public void setAsteriskServer(AsteriskServer asteriskServer) { + this.asteriskServer = asteriskServer; + } /** * Returns the unique id of this channel, for example "1099015093.165". */ @@ -198,4 +219,5 @@ public class Channel implements Serializ { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } + } \ No newline at end of file Index: MultiAsterisksManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/MultiAsterisksManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- MultiAsterisksManager.java 1 Feb 2005 17:20:34 -0000 1.1 +++ MultiAsterisksManager.java 4 Feb 2005 18:54:04 -0000 1.2 @@ -48,7 +48,7 @@ public class MultiAsterisksManager imple public void addManagerConnection(ManagerConnection connection) { - managerConnections.put(connection.getHostname(),connection) ; + managerConnections.put(connection.getAsteriskServer(),connection) ; Hashtable initializedBoolean = new Hashtable(3,1) ; initializedBoolean.put("channelsInitialized", new Boolean(false)); @@ -56,7 +56,7 @@ public class MultiAsterisksManager imple initializedBoolean.put("queuesInitialized", new Boolean(true)); initializedBoolean.put("initialized", new Boolean(false)); - initialized.put(connection.getHostname(),initializedBoolean) ; + initialized.put(connection.getAsteriskServer(),initializedBoolean) ; } @@ -72,12 +72,6 @@ public class MultiAsterisksManager imple } } - public String originateCall(OriginateAction originateAction) throws TimeoutException, IOException - { -// TODO originateCall with multi servers - return null; - } - /** * Returns a map of all active channel by their unique id: "hostname:ChannelId". */ @@ -101,10 +95,10 @@ public class MultiAsterisksManager imple { System.out.println("received: " + event); - Hashtable initializedBoolean = (Hashtable) initialized.get(getConnectionSource(event).getHostname()) ; + Hashtable initializedBoolean = (Hashtable) initialized.get((AsteriskServer) event.getSource()) ; - if (! ((Boolean)initializedBoolean.get("initialized")).booleanValue()) + if (!((Boolean)initializedBoolean.get("initialized")).booleanValue()) { if (event instanceof StatusEvent) { @@ -183,14 +177,14 @@ public class MultiAsterisksManager imple } } - protected void addChannel(Channel channel, ManagerConnection connection) + protected void addChannel(Channel channel) { - channels.put(connection.getHostname()+":"+channel.getId(), channel); + channels.put(channel.getAsteriskServer().getHostname()+"/"+channel.getId(), channel); } - protected void removeChannel(Channel channel, ManagerConnection connection) + protected void removeChannel(Channel channel) { - channels.remove(connection.getHostname()+":"+channel.getId()); + channels.remove(channel.getAsteriskServer().getHostname()+"/"+channel.getId()); } protected void addQueue(Queue queue) @@ -208,10 +202,10 @@ public class MultiAsterisksManager imple Channel channel; boolean isNew = false; - channel = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId()); + channel = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId()); if (channel == null) { - channel = new Channel(event.getChannel(), event.getUniqueId()); + channel = new Channel(event.getChannel(), event.getUniqueId(), (AsteriskServer) event.getSource()); if (event.getSeconds() != null) { channel.setDateOfCreation(new Date(System.currentTimeMillis() @@ -244,15 +238,15 @@ public class MultiAsterisksManager imple if (isNew) { - log.info("Adding new channel " + channel.getName()); - addChannel(channel, getConnectionSource(event)); + log.info("Adding new channel " + channel.getName() + ", from server " + channel.getAsteriskServer().getHostname() ); + addChannel(channel); } } protected void handleStatusCompleteEvent(StatusCompleteEvent event) { log.info("Channels are now initialized"); - Hashtable initializedBoolean = (Hashtable) initialized.get(getConnectionSource(event).getHostname()) ; + Hashtable initializedBoolean = (Hashtable) initialized.get((AsteriskServer) event.getSource()) ; initializedBoolean.put("channelsInitialized", new Boolean(true)) ; } @@ -332,18 +326,18 @@ public class MultiAsterisksManager imple protected void handleNewChannelEvent(NewChannelEvent event) { - Channel channel = new Channel(event.getChannel(), event.getUniqueId()); + Channel channel = new Channel(event.getChannel(), event.getUniqueId(), (AsteriskServer) event.getSource()); channel.setCallerId(event.getCallerId()); channel.setState(ChannelStateEnum.getEnum(event.getState())); - log.info("Adding channel " + channel.getName()); - addChannel(channel, getConnectionSource(event)); + log.info("Adding channel " + channel.getName() + ", on server " + channel.getAsteriskServer().getHostname()); + addChannel(channel); } protected void handleNewExtenEvent(NewExtenEvent event) { - Channel channel = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId()); + Channel channel = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId()); if (channel == null) { log.error("Ignored NewExtenEvent for unknown channel " + event.getChannel()); @@ -362,7 +356,7 @@ public class MultiAsterisksManager imple protected void handleNewStateEvent(NewStateEvent event) { - Channel channel = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId()); + Channel channel = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId()); if (channel == null) { log.error("Ignored NewStateEvent for unknown channel " + event.getChannel()); @@ -374,7 +368,7 @@ public class MultiAsterisksManager imple protected void handleHangupEvent(HangupEvent event) { - Channel channel = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId()); + Channel channel = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId()); if (channel == null) { log.error("Ignored HangupEvent for unknown channel " + event.getChannel()); @@ -387,13 +381,13 @@ public class MultiAsterisksManager imple } log.info("Removing channel " + channel.getName() + " due to hangup"); - removeChannel(channel, getConnectionSource(event)); + removeChannel(channel); } protected void handleLinkEvent(LinkEvent event) { - Channel channel1 = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId1()); - Channel channel2 = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId2()); + Channel channel1 = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId1()); + Channel channel2 = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId2()); if (channel1 == null) { @@ -444,14 +438,17 @@ public class MultiAsterisksManager imple protected void handleRenameEvent(RenameEvent event) { - Channel channel = (Channel) channels.get(getConnectionSource(event).getHostname()+":"+event.getUniqueId()); + Channel channel = (Channel) channels.get(((AsteriskServer) event.getSource()).getHostname()+"/"+event.getUniqueId()); log.info("Renaming channel '" + channel.getName() + "' to '" + event.getNewname() + "'"); channel.setName(event.getNewname()); } - protected ManagerConnection getConnectionSource(ManagerEvent event) { - - return (ManagerConnection) event.getSource() ; + /* (non-Javadoc) + * @see net.sf.asterisk.manager.AsteriskManager#originateCall(net.sf.asterisk.manager.action.OriginateAction) + */ + public String originateCall(OriginateAction originateAction) throws TimeoutException, IOException { + // TODO Auto-generated method stub + return null; } } \ No newline at end of file Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- DefaultAsteriskManager.java 31 Jan 2005 01:18:04 -0000 1.8 +++ DefaultAsteriskManager.java 4 Feb 2005 18:54:04 -0000 1.9 @@ -75,7 +75,7 @@ public class DefaultAsteriskManager impl public void initialize() throws TimeoutException, IOException, AuthenticationFailedException { connection.addEventHandler(this); - //connection.login(); + connection.login(); connection.sendAction(new StatusAction()); connection.sendAction(new QueueStatusAction()); } |