/** * Returns a collection of all active AsteriskChannels. * * @return a collection of all active AsteriskChannels. */ Collection<AsteriskChannel> getChannels() { Collection<AsteriskChannel> copy; synchronized (channels) { copy = new ArrayList<AsteriskChannel>(channels.size() + 2); for (AsteriskChannel channel : channels) { if (channel.getState() != ChannelState.HUNGUP) { copy.add(channel); } } } return copy; }
/** * Returns the other side of a local channel. * * <p>Local channels consist of two sides, like "Local/1234@from-local-60b5,1" and * "Local/1234@from-local-60b5,2" (for Asterisk 1.4) or "Local/1234@from-local-60b5;1" and * "Local/1234@from-local-60b5;2" (for Asterisk 1.6) this method returns the other side. * * @param localChannel one side * @return the other side, or <code>null</code> if not available or if the given channel is not a * local channel. */ AsteriskChannelImpl getOtherSideOfLocalChannel(AsteriskChannel localChannel) { final String name; final char num; if (localChannel == null) { return null; } name = localChannel.getName(); if (name == null || !name.startsWith("Local/") || (name.charAt(name.length() - 2) != ',' && name.charAt(name.length() - 2) != ';')) { return null; } num = name.charAt(name.length() - 1); if (num == '1') { return getChannelImplByName(name.substring(0, name.length() - 1) + "2"); } else if (num == '2') { return getChannelImplByName(name.substring(0, name.length() - 1) + "1"); } else { return null; } }
/** Removes channels that have been hung more than {@link #REMOVAL_THRESHOLD} milliseconds. */ private void removeOldChannels() { Iterator<AsteriskChannelImpl> i; synchronized (channels) { i = channels.iterator(); while (i.hasNext()) { final AsteriskChannel channel = i.next(); final Date dateOfRemoval = channel.getDateOfRemoval(); if (channel.getState() == ChannelState.HUNGUP && dateOfRemoval != null) { final long diff = DateUtil.getDate().getTime() - dateOfRemoval.getTime(); if (diff >= REMOVAL_THRESHOLD) { i.remove(); } } } } }
private String getTraceId(AsteriskChannel channel) { String traceId; try { traceId = channel.getVariable(Constants.VARIABLE_TRACE_ID); } catch (Exception e) { traceId = null; } // logger.info("TraceId for channel " + channel.getName() + " is " + traceId); return traceId; }