AsteriskChannelImpl getChannelImplById(String id) { if (id == null) { return null; } synchronized (channels) { for (AsteriskChannelImpl channel : channels) { if (id.equals(channel.getId())) { return channel; } } } return null; }
private AsteriskChannelImpl addNewChannel( String uniqueId, String name, Date dateOfCreation, String callerIdNumber, String callerIdName, ChannelState state, String account) { final AsteriskChannelImpl channel; final String traceId; channel = new AsteriskChannelImpl(server, name, uniqueId, dateOfCreation); channel.setCallerId(new CallerId(callerIdName, callerIdNumber)); channel.setAccount(account); channel.stateChanged(dateOfCreation, state); logger.info("Adding channel " + channel.getName() + "(" + channel.getId() + ")"); if (SLEEP_TIME_BEFORE_GET_VAR > 0) { try { Thread.sleep(SLEEP_TIME_BEFORE_GET_VAR); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } traceId = getTraceId(channel); channel.setTraceId(traceId); addChannel(channel); if (traceId != null && (!name.toLowerCase(Locale.ENGLISH).startsWith("local/") || (name.endsWith(",1") || name.endsWith(";1")))) { final OriginateCallbackData callbackData; callbackData = server.getOriginateCallbackDataByTraceId(traceId); if (callbackData != null && callbackData.getChannel() == null) { callbackData.setChannel(channel); try { callbackData.getCallback().onDialing(channel); } catch (Throwable t) { logger.warn("Exception dispatching originate progress.", t); } } } server.fireNewAsteriskChannel(channel); return channel; }
void handleNewCallerIdEvent(NewCallerIdEvent event) { AsteriskChannelImpl channel = getChannelImplById(event.getUniqueId()); if (channel == null) { // NewCallerIdEvent can occur for an existing channel that now has a different unique id // (originate with Local/) channel = getChannelImplByNameAndActive(event.getChannel()); if (channel != null) { logger.info( "Changing unique id for '" + channel.getName() + "' from " + channel.getId() + " to " + event.getUniqueId()); channel.idChanged(event.getDateReceived(), event.getUniqueId()); } if (channel == null) { // NewCallerIdEvent can occur before NewChannelEvent channel = addNewChannel( event.getUniqueId(), event.getChannel(), event.getDateReceived(), event.getCallerIdNum(), event.getCallerIdName(), ChannelState.DOWN, null /* account code not available */); } } synchronized (channel) { channel.setCallerId(new CallerId(event.getCallerIdName(), event.getCallerIdNum())); } }
void handleNewStateEvent(NewStateEvent event) { AsteriskChannelImpl channel = getChannelImplById(event.getUniqueId()); if (channel == null) { // NewStateEvent can occur for an existing channel that now has a different unique id // (originate with Local/) channel = getChannelImplByNameAndActive(event.getChannel()); if (channel != null) { logger.info( "Changing unique id for '" + channel.getName() + "' from " + channel.getId() + " to " + event.getUniqueId()); channel.idChanged(event.getDateReceived(), event.getUniqueId()); } if (channel == null) { logger.info( "Creating new channel due to NewStateEvent '" + event.getChannel() + "' unique id " + event.getUniqueId()); // NewStateEvent can occur instead of a NewChannelEvent channel = addNewChannel( event.getUniqueId(), event.getChannel(), event.getDateReceived(), event.getCallerIdNum(), event.getCallerIdName(), ChannelState.valueOf(event.getChannelState()), null /* account code not available */); } } // NewStateEvent can provide a new CallerIdNum or CallerIdName not previously received through a // NewCallerIdEvent. This happens at least on outgoing legs from the queue application to // agents. if (event.getCallerIdNum() != null || event.getCallerIdName() != null) { String cidnum = ""; String cidname = ""; CallerId currentCallerId = channel.getCallerId(); if (currentCallerId != null) { cidnum = currentCallerId.getNumber(); cidname = currentCallerId.getName(); } if (event.getCallerIdNum() != null) { cidnum = event.getCallerIdNum(); } if (event.getCallerIdName() != null) { cidname = event.getCallerIdName(); } CallerId newCallerId = new CallerId(cidname, cidnum); logger.debug("Updating CallerId (following NewStateEvent) to: " + newCallerId.toString()); channel.setCallerId(newCallerId); // Also, NewStateEvent can return a new channel name for the same channel uniqueid, indicating // the channel has been // renamed but no related RenameEvent has been received. // This happens with mISDN channels (see AJ-153) if (event.getChannel() != null && !event.getChannel().equals(channel.getName())) { logger.info( "Renaming channel (following NewStateEvent) '" + channel.getName() + "' to '" + event.getChannel() + "'"); synchronized (channel) { channel.nameChanged(event.getDateReceived(), event.getChannel()); } } } if (event.getChannelState() != null) { synchronized (channel) { channel.stateChanged( event.getDateReceived(), ChannelState.valueOf(event.getChannelState())); } } }