[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/manager DefaultAsteriskManager.java,
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-08-15 12:34:22
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14217/src/java/net/sf/asterisk/manager Modified Files: DefaultAsteriskManager.java Channel.java Log Message: Added callerid name to Channel Index: DefaultAsteriskManager.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/DefaultAsteriskManager.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -p -r1.17 -r1.18 --- DefaultAsteriskManager.java 8 Aug 2005 05:36:57 -0000 1.17 +++ DefaultAsteriskManager.java 15 Aug 2005 12:34:13 -0000 1.18 @@ -416,22 +416,34 @@ public class DefaultAsteriskManager protected void addChannel(Channel channel) { - channels.put(channel.getId(), channel); + synchronized (channels) + { + channels.put(channel.getId(), channel); + } } protected void removeChannel(Channel channel) { - channels.remove(channel.getId()); + synchronized (channels) + { + channels.remove(channel.getId()); + } } protected void addQueue(Queue queue) { - queues.put(queue.getName(), queue); + synchronized (queues) + { + queues.put(queue.getName(), queue); + } } protected void removeQueue(Queue queue) { - queues.remove(queue.getName()); + synchronized (queues) + { + queues.remove(queue.getName()); + } } protected void handleStatusEvent(StatusEvent event) @@ -440,7 +452,7 @@ public class DefaultAsteriskManager Extension extension; boolean isNew = false; - channel = (Channel) channels.get(event.getUniqueId()); + channel = getChannelById(event.getUniqueId()); if (channel == null) { channel = new Channel(event.getChannel(), event.getUniqueId()); @@ -466,6 +478,7 @@ public class DefaultAsteriskManager synchronized (channel) { channel.setCallerId(event.getCallerId()); + channel.setCallerIdName(event.getCallerIdName()); channel.setAccount(event.getAccount()); channel.setState(ChannelStateEnum.getEnum(event.getState())); channel.addExtension(extension); @@ -499,11 +512,11 @@ public class DefaultAsteriskManager { // reset version information as it might have changed while Asterisk // restarted - this.version = null; - this.versions = null; + version = null; + versions = null; - this.channels.clear(); - this.queues.clear(); + channels.clear(); + queues.clear(); } /** @@ -591,7 +604,7 @@ public class DefaultAsteriskManager * @param name name of the channel to return * @return the channel with the given name */ - private Channel getChannelByName(String name) + public Channel getChannelByName(String name) { Channel channel = null; @@ -610,11 +623,29 @@ public class DefaultAsteriskManager return channel; } + /** + * Returns a channel by its unique id. + * + * @param id the unique id of the channel to return + * @return the channel with the given unique id + */ + public Channel getChannelById(String id) + { + Channel channel = null; + + synchronized (channels) + { + channel = (Channel) channels.get(id); + } + return channel; + } + protected void handleNewChannelEvent(NewChannelEvent event) { Channel channel = new Channel(event.getChannel(), event.getUniqueId()); channel.setCallerId(event.getCallerId()); + channel.setCallerIdName(event.getCallerIdName()); channel.setState(ChannelStateEnum.getEnum(event.getState())); logger.info("Adding channel " + channel.getName()); @@ -626,7 +657,7 @@ public class DefaultAsteriskManager Channel channel; Extension extension; - channel = (Channel) channels.get(event.getUniqueId()); + channel = getChannelById(event.getUniqueId()); if (channel == null) { logger.error("Ignored NewExtenEvent for unknown channel " @@ -646,7 +677,7 @@ public class DefaultAsteriskManager protected void handleNewStateEvent(NewStateEvent event) { - Channel channel = (Channel) channels.get(event.getUniqueId()); + Channel channel = getChannelById(event.getUniqueId()); if (channel == null) { @@ -660,7 +691,7 @@ public class DefaultAsteriskManager protected void handleHangupEvent(HangupEvent event) { - Channel channel = (Channel) channels.get(event.getUniqueId()); + Channel channel = getChannelById(event.getUniqueId()); if (channel == null) { logger.error("Ignored HangupEvent for unknown channel " @@ -737,7 +768,15 @@ public class DefaultAsteriskManager protected void handleRenameEvent(RenameEvent event) { - Channel channel = (Channel) channels.get(event.getUniqueId()); + Channel channel = getChannelById(event.getUniqueId()); + + if (channel == null) + { + logger + .error("Ignored RenameEvent for unknown channel with uniqueId " + + event.getUniqueId()); + return; + } logger.info("Renaming channel '" + channel.getName() + "' to '" + event.getNewname() + "'"); Index: Channel.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/Channel.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- Channel.java 9 Aug 2005 00:08:48 -0000 1.9 +++ Channel.java 15 Aug 2005 12:34:13 -0000 1.10 @@ -50,6 +50,11 @@ public class Channel implements Serializ private String callerId; /** + * Caller ID Name of this channel. + */ + private String callerIdName; + + /** * State of this channel. */ private ChannelStateEnum state; @@ -161,7 +166,7 @@ public class Channel implements Serializ /** * Sets the caller id of this channel. * - * @param callerId the calleid id of this channel. + * @param callerId the caller id of this channel. */ public final void setCallerId(final String callerId) { @@ -169,6 +174,26 @@ public class Channel implements Serializ } /** + * Returns the caller id name of this channel. + * + * @return the caller id name of this channel. + */ + public final String getCallerIdName() + { + return callerIdName; + } + + /** + * Sets the caller id of this channel. + * + * @param callerIdName the caller id name of this channel. + */ + public final void setCallerIdName(final String callerIdName) + { + this.callerIdName = callerIdName; + } + + /** * Returns the state of this channel. * * @return the state of this channel. |