idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
32,300
protected synchronized void disconnect ( ) { if ( socket != null ) { logger . info ( "Closing socket." ) ; try { socket . close ( ) ; } catch ( IOException ex ) { logger . warn ( "Unable to close socket: " + ex . getMessage ( ) ) ; } socket = null ; } protocolIdentifier . reset ( ) ; }
Closes the socket connection .
32,301
public ManagerResponse sendAction ( ManagerAction action , long timeout ) throws IOException , TimeoutException , IllegalArgumentException , IllegalStateException { ResponseHandlerResult result = new ResponseHandlerResult ( ) ; SendActionCallback callbackHandler = new DefaultSendActionCallback ( result ) ; sendAction (...
Implements synchronous sending of simple actions .
32,302
private String createInternalActionId ( ) { final StringBuilder sb ; sb = new StringBuilder ( ) ; sb . append ( this . hashCode ( ) ) ; sb . append ( "_" ) ; sb . append ( actionIdCounter . getAndIncrement ( ) ) ; return sb . toString ( ) ; }
Creates a new unique internal action id based on the hash code of this connection and a sequence .
32,303
public void dispatchEvent ( ManagerEvent event ) { if ( event == null ) { logger . error ( "Unable to dispatch null event. This should never happen. Please file a bug." ) ; return ; } dispatchLegacyEventIfNeeded ( event ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Dispatching event:\n" + event . toString ...
This method is called by the reader whenever a ManagerEvent is received . The event is dispatched to all registered ManagerEventHandlers .
32,304
private void dispatchLegacyEventIfNeeded ( ManagerEvent event ) { if ( event instanceof DialBeginEvent ) { DialEvent legacyEvent = new DialEvent ( ( DialBeginEvent ) event ) ; dispatchEvent ( legacyEvent ) ; } }
Enro 2015 - 03 Workaround to continue having Legacy Events from Asterisk 13 .
32,305
@ SuppressWarnings ( "unchecked" ) public void addServiceAgiScript ( Class < ? extends ServiceAgiScript > handler ) throws DuplicateScriptException , InstantiationException , IllegalAccessException { logger . info ( "loading agi handler {}" + handler . getCanonicalName ( ) ) ; ServiceAgiScript tmpHandler = handler . ne...
this will be a pluggable extension system for the agi core it s still a work in progress and is not useable
32,306
protected ScriptEngine getScriptEngine ( File file ) { final String extension = getExtension ( file . getName ( ) ) ; if ( extension == null ) { return null ; } return getScriptEngineManager ( ) . getEngineByExtension ( extension ) ; }
Searches for a ScriptEngine that can handle the given file .
32,307
protected ClassLoader getClassLoader ( ) { final ClassLoader parentClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; final List < URL > jarFileUrls = new ArrayList < > ( ) ; if ( libPath == null || libPath . length == 0 ) { return parentClassLoader ; } for ( String libPathEntry : libPath ) { final ...
Returns the ClassLoader to use for the ScriptEngineManager . Adds all jar files in the lib subdirectory of the current directory to the class path . Override this method to provide your own ClassLoader .
32,308
protected File searchFile ( String scriptName , String [ ] path ) { if ( scriptName == null || path == null ) { return null ; } for ( String pathElement : path ) { final File pathElementDir = new File ( pathElement ) ; if ( ! pathElementDir . isDirectory ( ) ) { continue ; } final File file = new File ( pathElementDir ...
Searches for the file with the given name on the path .
32,309
public void onManagerEvent ( final org . asteriskjava . manager . event . ManagerEvent event ) { boolean wanted = false ; synchronized ( this . globalEvents ) { Class < ? extends ManagerEvent > shadowEvent = CoherentEventFactory . getShadowEvent ( event ) ; if ( this . globalEvents . contains ( shadowEvent ) ) { wanted...
handles manager events passed to us in our role as a listener . We queue the event so that it can be read by the run method of this class and subsequently passed on to the original listener .
32,310
public void dispatchEvent ( final ManagerEvent event ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "dispatch=" + event . toString ( ) ) ; } final List < FilteredManagerListenerWrapper > listenerCopy ; synchronized ( this . listeners ) { listenerCopy = this . listeners . getCopyAsList ( ) ; } try { final Log...
Events are sent here from the CoherentManagerEventQueue after being converted from a ManagerEvent to an ManagerEvent . This method is called from a dedicated thread attached to the event queue which it uses for dispatching events .
32,311
public void addListener ( final FilteredManagerListener < ManagerEvent > listener ) { synchronized ( this . listeners ) { this . listeners . addListener ( listener ) ; synchronized ( this . globalEvents ) { Collection < Class < ? extends ManagerEvent > > expandEvents = expandEvents ( listener . requiredEvents ( ) ) ; t...
Adds a listener which will be sent all events that its filterEvent handler will accept . All events are dispatch by way of a shared queue which is read via a thread which is shared by all listeners . Whilst poor performance of you listener can affect other listeners you can t affect the read thread which takes events f...
32,312
Collection < Class < ? extends ManagerEvent > > expandEvents ( Collection < Class < ? extends ManagerEvent > > events ) { Collection < Class < ? extends ManagerEvent > > requiredEvents = new HashSet < > ( ) ; for ( Class < ? extends ManagerEvent > event : events ) { requiredEvents . add ( event ) ; if ( event . equals ...
in order to get Bridge Events we must subscribe to Link and Unlink events for asterisk 1 . 4 so we automatically add them if the Bridge Event is required
32,313
public void transferListeners ( CoherentManagerEventQueue eventQueue ) { synchronized ( this . listeners ) { synchronized ( eventQueue . listeners ) { Iterator < FilteredManagerListenerWrapper > itr = eventQueue . listeners . iterator ( ) ; while ( itr . hasNext ( ) ) { FilteredManagerListenerWrapper listener = itr . n...
transfers the listeners from one queue to another .
32,314
public CallImpl join ( OperandChannel originatingOperand , Call rhs , OperandChannel acceptingOperand , CallDirection direction ) throws PBXException { CallImpl joinTo = ( CallImpl ) rhs ; Channel originatingParty = null ; Channel acceptingParty = null ; originatingParty = this . getOperandChannel ( originatingOperand ...
Joins a specific channel from this call with a specific channel from another call which results in a new Call object being created . Channels that do not participate in the join are left in their original Call .
32,315
public Call split ( OperandChannel channelToSplit ) throws PBXException { Channel channel = this . getOperandChannel ( channelToSplit ) ; channel . removeListener ( this ) ; CallDirection direction = CallDirection . INBOUND ; if ( this . getLocalParty ( ) != null && this . getLocalParty ( ) . isSame ( channel ) ) { dir...
Splits a channel out of a call into a separate call . This method should only be called from the SplitActivity .
32,316
public boolean addHangupListener ( CallHangupListener listener ) { boolean callStillUp = true ; if ( ( this . _originatingParty != null && this . _originatingParty . isLive ( ) ) || ( this . _acceptingParty != null && this . _acceptingParty . isLive ( ) ) || ( this . _transferTargetParty != null && this . _transferTarg...
Call this method to get a notification when this call hangs up .
32,317
public boolean isLive ( ) { boolean live = false ; if ( ( this . _originatingParty != null && this . _originatingParty . isLive ( ) ) || ( this . _acceptingParty != null && this . _acceptingParty . isLive ( ) ) || ( this . _transferTargetParty != null && this . _transferTargetParty . isLive ( ) ) ) live = true ; return...
returns true if the call has any active channels .
32,318
public List < Channel > getChannels ( ) { List < Channel > channels = new LinkedList < > ( ) ; if ( _acceptingParty != null ) channels . add ( _acceptingParty ) ; if ( _originatingParty != null ) channels . add ( _originatingParty ) ; if ( _transferTargetParty != null ) channels . add ( _transferTargetParty ) ; return ...
Returns all of the Channels associated with this call .
32,319
public void masquerade ( ChannelProxy cloneProxy ) throws InvalidChannelName { ChannelImpl originalChannel = this . _channel ; ChannelImpl cloneChannel = cloneProxy . _channel ; cloneChannel . masquerade ( this . _channel ) ; originalChannel . removeListener ( this ) ; cloneChannel . removeListener ( cloneProxy ) ; thi...
Used to handle a MasqueradeEvent . We essentially swap the two underlying channels between the two proxies .
32,320
public static boolean isClassAvailable ( String s ) { final ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; try { classLoader . loadClass ( s ) ; return true ; } catch ( ClassNotFoundException e ) { return false ; } }
Checks if the class is available on the current thread s context class loader .
32,321
public static Object newInstance ( String s ) { final ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; try { Class < ? > clazz = classLoader . loadClass ( s ) ; Constructor < ? > constructor = clazz . getConstructor ( ) ; return constructor . newInstance ( ) ; } catch ( ClassNotFoundEx...
Creates a new instance of the given class . The class is loaded using the current thread s context class loader and instantiated using its default constructor .
32,322
private static Set < String > getClassNamesFromPackage ( String packageName ) throws IOException , URISyntaxException { ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; Enumeration < URL > packageURLs ; Set < String > names = new HashSet < String > ( ) ; packageName = packageName . rep...
retrieve all the classes that can be found on the classpath for the specified packageName
32,323
@ SuppressWarnings ( "unchecked" ) public ManagerResponse buildResponse ( Class < ? extends ManagerResponse > responseClass , Map < String , Object > attributes ) { final ManagerResponse response ; final String responseType = ( String ) attributes . get ( RESPONSE_KEY ) ; if ( RESPONSE_TYPE_ERROR . equalsIgnoreCase ( r...
Asterisk 14 . 3 . 0
32,324
private synchronized void handleEvent ( final StatusCompleteEvent event ) { for ( final Peer peer : this . peerList ) { peer . endSweep ( ) ; } PeerMonitor . logger . debug ( "Channel Mark and Sweep complete" ) ; }
We receive the StatusComplete event once the Mark and Sweep channel operation has completed . We now call endSweep which will remove any channels that were not marked during the operation .
32,325
public void startSweep ( ) { PeerMonitor . logger . debug ( "Starting channel mark and sweep" ) ; synchronized ( PeerMonitor . class ) { for ( final Peer peer : this . peerList ) { peer . startSweep ( ) ; } } final StatusAction sa = new StatusAction ( ) ; try { AsteriskPBX pbx = ( AsteriskPBX ) PBXFactory . getActivePB...
Check every channel to make certain they are still active . We do this in case we missed a hangup event along the way somewhere . This allows us to cleanup any old channels . We start by clearing the mark on all channels and then generates a Asterisk status message for every active channel . At the end of the process a...
32,326
private synchronized Map < String , String [ ] > parseParameters ( String s ) { Map < String , List < String > > parameterMap ; Map < String , String [ ] > result ; StringTokenizer st ; parameterMap = new HashMap < > ( ) ; result = new HashMap < > ( ) ; if ( s == null ) { return result ; } st = new StringTokenizer ( s ...
Parses the given parameter string and caches the result .
32,327
protected AgiChannel getChannel ( ) { AgiChannel threadBoundChannel ; if ( channel != null ) { return channel ; } threadBoundChannel = AgiConnectionHandler . getChannel ( ) ; if ( threadBoundChannel == null ) { throw new IllegalStateException ( "Trying to send command from an invalid thread" ) ; } return threadBoundCha...
Returns the channel to operate on .
32,328
public ManagerConnection connect ( final AsteriskSettings asteriskSettings ) throws IOException , AuthenticationFailedException , TimeoutException , IllegalStateException { checkIfAsteriskRunning ( asteriskSettings ) ; this . makeConnection ( asteriskSettings ) ; return this . managerConnection ; }
Establishes a Asterisk ManagerConnection as well as performing the login required by Asterisk .
32,329
private void checkIfAsteriskRunning ( AsteriskSettings asteriskSettings ) throws UnknownHostException , IOException { try ( Socket socket = new Socket ( ) ) { socket . setSoTimeout ( 2000 ) ; InetSocketAddress asteriskHost = new InetSocketAddress ( asteriskSettings . getAsteriskIP ( ) , asteriskSettings . getManagerPor...
This method will try to make a simple tcp connection to the asterisk manager to establish it is up . We do this as the default makeConnection doesn t have a timeout and will sit trying to connect for a minute or so . By using method when the user realises they have a problem on start up they can go to the asterisk pane...
32,330
synchronized private MeetmeRoom findMeetmeRoom ( final String roomNumber ) { MeetmeRoom foundRoom = null ; for ( final MeetmeRoom room : this . rooms ) { if ( room . getRoomNumber ( ) . compareToIgnoreCase ( roomNumber ) == 0 ) { foundRoom = room ; break ; } } return foundRoom ; }
Returns the MeetmeRoom for the given room number . The room number will be an integer value offset from the meetme base address .
32,331
public static AsteriskVersion getDetermineVersionFromString ( String coreLine ) { for ( AsteriskVersion version : knownVersions ) { for ( Pattern pattern : version . patterns ) { if ( pattern . matcher ( coreLine ) . matches ( ) ) { return version ; } } } return null ; }
Determine the Asterisk version from the string returned by Asterisk . The string should contain Asterisk followed by a version number .
32,332
void updateQueue ( String queue ) throws ManagerCommunicationException { ResponseEvents re ; try { QueueStatusAction queueStatusAction = new QueueStatusAction ( ) ; queueStatusAction . setQueue ( queue ) ; re = server . sendEventGeneratingAction ( queueStatusAction ) ; } catch ( ManagerCommunicationException e ) { fina...
Method to ask for a Queue data update
32,333
private void handleQueueParamsEvent ( QueueParamsEvent event ) { AsteriskQueueImpl queue ; final String name = event . getQueue ( ) ; final Integer max = event . getMax ( ) ; final String strategy = event . getStrategy ( ) ; final Integer serviceLevel = event . getServiceLevel ( ) ; final Integer weight = event . getWe...
Called during initialization to populate the list of queues .
32,334
private void handleQueueMemberEvent ( QueueMemberEvent event ) { final AsteriskQueueImpl queue = getInternalQueueByName ( event . getQueue ( ) ) ; if ( queue == null ) { logger . error ( "Ignored QueueEntryEvent for unknown queue " + event . getQueue ( ) ) ; return ; } AsteriskQueueMemberImpl member = queue . getMember...
Called during initialization to populate the members of the queues .
32,335
void handleJoinEvent ( JoinEvent event ) { final AsteriskQueueImpl queue = getInternalQueueByName ( event . getQueue ( ) ) ; final AsteriskChannelImpl channel = channelManager . getChannelImplByName ( event . getChannel ( ) ) ; if ( queue == null ) { logger . error ( "Ignored JoinEvent for unknown queue " + event . get...
Called from AsteriskServerImpl whenever a new entry appears in a queue .
32,336
void handleLeaveEvent ( LeaveEvent event ) { final AsteriskQueueImpl queue = getInternalQueueByName ( event . getQueue ( ) ) ; final AsteriskChannelImpl channel = channelManager . getChannelImplByName ( event . getChannel ( ) ) ; if ( queue == null ) { logger . error ( "Ignored LeaveEvent for unknown queue " + event . ...
Called from AsteriskServerImpl whenever an enty leaves a queue .
32,337
void handleQueueMemberStatusEvent ( QueueMemberStatusEvent event ) { AsteriskQueueImpl queue = getInternalQueueByName ( event . getQueue ( ) ) ; if ( queue == null ) { logger . error ( "Ignored QueueMemberStatusEvent for unknown queue " + event . getQueue ( ) ) ; return ; } AsteriskQueueMemberImpl member = queue . getM...
Challange a QueueMemberStatusEvent . Called from AsteriskServerImpl whenever a member state changes .
32,338
AsteriskQueueImpl getQueueByName ( String queueName ) { refreshQueueIfForced ( queueName ) ; AsteriskQueueImpl queue = getInternalQueueByName ( queueName ) ; if ( queue == null ) { logger . error ( "Requested queue '" + queueName + "' not found!" ) ; } return queue ; }
Retrieves a queue by its name .
32,339
public void handleQueueMemberRemovedEvent ( QueueMemberRemovedEvent event ) { final AsteriskQueueImpl queue = getInternalQueueByName ( event . getQueue ( ) ) ; if ( queue == null ) { logger . error ( "Ignored QueueMemberRemovedEvent for unknown queue " + event . getQueue ( ) ) ; return ; } final AsteriskQueueMemberImpl...
Challange a QueueMemberRemovedEvent .
32,340
void fireNewEntry ( AsteriskQueueEntryImpl entry ) { synchronized ( listeners ) { for ( AsteriskQueueListener listener : listeners ) { try { listener . onNewEntry ( entry ) ; } catch ( Exception e ) { logger . warn ( "Exception in onNewEntry()" , e ) ; } } } }
Notifies all registered listener that an entry joins the queue .
32,341
void fireEntryLeave ( AsteriskQueueEntryImpl entry ) { synchronized ( listeners ) { for ( AsteriskQueueListener listener : listeners ) { try { listener . onEntryLeave ( entry ) ; } catch ( Exception e ) { logger . warn ( "Exception in onEntryLeave()" , e ) ; } } } }
Notifies all registered listener that an entry leaves the queue .
32,342
void fireMemberAdded ( AsteriskQueueMemberImpl member ) { synchronized ( listeners ) { for ( AsteriskQueueListener listener : listeners ) { try { listener . onMemberAdded ( member ) ; } catch ( Exception e ) { logger . warn ( "Exception in onMemberAdded()" , e ) ; } } } }
Notifies all registered listener that a member has been added to the queue .
32,343
void fireMemberRemoved ( AsteriskQueueMemberImpl member ) { synchronized ( listeners ) { for ( AsteriskQueueListener listener : listeners ) { try { listener . onMemberRemoved ( member ) ; } catch ( Exception e ) { logger . warn ( "Exception in onMemberRemoved()" , e ) ; } } } }
Notifies all registered listener that a member has been removed from the queue .
32,344
public Collection < AsteriskQueueMember > getMembers ( ) { List < AsteriskQueueMember > listOfMembers = new ArrayList < > ( members . size ( ) ) ; synchronized ( members ) { listOfMembers . addAll ( members . values ( ) ) ; } return listOfMembers ; }
Returns a collection of members of this queue .
32,345
AsteriskQueueMemberImpl getMember ( String location ) { synchronized ( members ) { if ( members . containsKey ( location ) ) { return members . get ( location ) ; } } return null ; }
Returns a member by its location .
32,346
void addMember ( AsteriskQueueMemberImpl member ) { synchronized ( members ) { if ( members . containsValue ( member ) ) { return ; } logger . info ( "Adding new member to the queue " + getName ( ) + ": " + member . toString ( ) ) ; members . put ( member . getLocation ( ) , member ) ; } fireMemberAdded ( member ) ; }
Add a new member to this queue .
32,347
AsteriskQueueMemberImpl getMemberByLocation ( String location ) { AsteriskQueueMemberImpl member ; synchronized ( members ) { member = members . get ( location ) ; } if ( member == null ) { logger . error ( "Requested member at location " + location + " not found!" ) ; } return member ; }
Retrieves a member by its location .
32,348
void fireMemberStateChanged ( AsteriskQueueMemberImpl member ) { synchronized ( listeners ) { for ( AsteriskQueueListener listener : listeners ) { try { listener . onMemberStateChange ( member ) ; } catch ( Exception e ) { logger . warn ( "Exception in onMemberStateChange()" , e ) ; } } } }
Notifies all registered listener that a queue member changes its state .
32,349
AsteriskQueueEntryImpl getEntry ( String channelName ) { synchronized ( entries ) { for ( AsteriskQueueEntryImpl entry : entries ) { if ( entry . getChannel ( ) . getName ( ) . equals ( channelName ) ) { return entry ; } } } return null ; }
Gets an entry of the queue by its channel name .
32,350
public void removeMember ( AsteriskQueueMemberImpl member ) { synchronized ( members ) { if ( ! members . containsValue ( member ) ) { return ; } logger . info ( "Remove member from the queue " + getName ( ) + ": " + member . toString ( ) ) ; members . remove ( member . getLocation ( ) ) ; } fireMemberRemoved ( member ...
Removes a member from this queue .
32,351
public boolean isSIP ( ) { return this . _tech == TechType . SIP || this . _tech == TechType . IAX || this . _tech == TechType . IAX2 ; }
For the purposes of asterisk IAX and SIP are both considered SIP .
32,352
public char getDigit ( ) { final String digit = agiReply . getAttribute ( "digit" ) ; if ( digit == null || digit . length ( ) == 0 ) { return 0x0 ; } return digit . charAt ( 0 ) ; }
Returns the DTMF digit that was received .
32,353
public int getNumberOfResults ( ) { final String numberOfResults = agiReply . getAttribute ( "results" ) ; return numberOfResults == null ? 0 : Integer . parseInt ( numberOfResults ) ; }
Returns how many results have been recoginized . Usually there is only one result but if multiple rules in the grammar match multiple results may be returned .
32,354
void performPostCreationTasks ( ) { StatusAction statusAction = new StatusAction ( ) ; try { ResponseEvents events = CoherentManagerConnection . sendEventGeneratingAction ( statusAction , 1000 ) ; for ( ResponseEvent event : events . getEvents ( ) ) { if ( event instanceof StatusEvent ) { } } } catch ( IllegalArgumentE...
Find all the channels that came into existence before startup . This can t be done during the Constructor call because it requires calls back to AsteriskPBX which isn t finished constructing until after the Constructor returns .
32,355
void mergeCalls ( CallTracker rhs ) { synchronized ( this . _associatedChannels ) { this . _associatedChannels . addAll ( rhs . _associatedChannels ) ; rhs . _associatedChannels . clear ( ) ; } }
Used to merge two calls into a single call . This is required as during a masquerade a new channel is created an initially we will create a CallTracker for it . When the masquerade event finally turns up we will realise it belongs to an existing CallTracker and as such we need to merge the two CallTrackers .
32,356
public void remove ( Channel channel ) { synchronized ( this . _associatedChannels ) { int index = findChannel ( channel ) ; if ( index != - 1 ) { if ( logger . isDebugEnabled ( ) ) logger . debug ( "CallTracker removing channel: " + this . toString ( ) + " " + channel . getExtendedChannelName ( ) ) ; this . _associate...
Remove a channel from the call .
32,357
ManagerEvent addMember ( BridgeEnterEvent event ) { List < BridgeEnterEvent > remaining = null ; synchronized ( members ) { if ( members . put ( event . getChannel ( ) , event ) == null && members . size ( ) == 2 ) { remaining = new ArrayList < > ( members . values ( ) ) ; } } if ( remaining == null ) { return null ; }...
if there are exactly 2 members in the bridge return a BridgeEvent
32,358
ManagerEvent removeMember ( BridgeLeaveEvent event ) { List < BridgeEnterEvent > remaining = null ; synchronized ( members ) { if ( members . remove ( event . getChannel ( ) ) != null && members . size ( ) == 2 ) { remaining = new ArrayList < > ( members . values ( ) ) ; } } if ( remaining == null ) { return null ; } r...
If there are exactly 2 members in the bridge return a BridgeEvent
32,359
public synchronized static Log getLog ( Class < ? > clazz ) { if ( slf4jLoggingAvailable == null ) { try { classLoader . loadClass ( "org.slf4j.Logger" ) ; slf4jLoggingAvailable = Boolean . TRUE ; } catch ( Exception e ) { slf4jLoggingAvailable = Boolean . FALSE ; } } if ( slf4jLoggingAvailable ) { try { return new Slf...
Returns an instance of Log suitable for logging from the given class .
32,360
public void handleEvent ( final MasqueradeEvent b ) { if ( this . isConnectedToSelf ( b . getClone ( ) ) ) { CallTracker original = findCall ( b . getOriginal ( ) ) ; CallTracker clone = findCall ( b . getClone ( ) ) ; if ( original != null && clone != null ) { clone . mergeCalls ( original ) ; clone . setState ( b . g...
We handle the masqurade event is it contains channel state information . During a masquerade we will have two channels for the one peer the original and the clone . As the clone is taking over from the original peer we now need to use that as true indicator of state .
32,361
public void handleEvent ( final NewChannelEvent b ) { if ( ( b . getChannel ( ) == null ) || ( b . getChannel ( ) . isConsole ( ) ) ) { return ; } if ( this . isConnectedToSelf ( b . getChannel ( ) ) ) { CallTracker call = this . registerChannel ( b . getChannel ( ) ) ; if ( call != null ) { call . setState ( b . getCh...
When a new channel comes up associated it with the peer . Be warned a peer can have multiple calls associated with it .
32,362
private void evaluateState ( ) { synchronized ( this . callList ) { PeerState newState = PeerState . NOTSET ; for ( CallTracker call : this . callList ) { if ( call . getState ( ) . getPriority ( ) > newState . getPriority ( ) ) newState = call . getState ( ) ; } this . _state = newState ; } }
Called each time the state of a call changes to determine the Peers overall state .
32,363
public final void registerEventClass ( String eventType , Class < ? extends ManagerEvent > clazz ) throws IllegalArgumentException { Constructor < ? > defaultConstructor ; if ( ! ManagerEvent . class . isAssignableFrom ( clazz ) ) { throw new IllegalArgumentException ( clazz + " is not a ManagerEvent" ) ; } if ( ( claz...
Registers a new event class for the event given by eventType .
32,364
public void masquerade ( Channel channel ) { if ( channel . hasCallerID ( ) ) { this . _callerID = channel . getCallerID ( ) ; } else if ( this . _callerID != null && ( ( ChannelImpl ) channel ) . _callerID != null ) { PBX pbx = PBXFactory . getActivePBX ( ) ; if ( this . _callerID != null ) { ( ( ChannelImpl ) channel...
designed for use by the ChannelProxy when a channel is being cloned as a result of Asterisk undertaking an Masquerade . This is not intended to be a complete clone just the key elements that we generally track on our side rather than getting directly from asterisk .
32,365
private void validateChannelName ( final String channelName ) throws InvalidChannelName { if ( ! this . _isConsole ) { if ( ! TechType . hasValidTech ( channelName ) ) { throw new InvalidChannelName ( "Invalid channelName: " + channelName + ". Unknown tech." ) ; } final int hypen = channelName . indexOf ( "-" ) ; if ( ...
validates the channel name . Validate is to be called after the channel has been cleaned .
32,366
public boolean sameUniqueID ( String uniqueID ) { boolean equals = false ; if ( ( this . _uniqueID . compareTo ( ChannelImpl . UNKNOWN_UNIQUE_ID ) != 0 ) && ( uniqueID . compareTo ( ChannelImpl . UNKNOWN_UNIQUE_ID ) != 0 ) ) { if ( this . _uniqueID . compareTo ( uniqueID ) == 0 ) { equals = true ; } } return equals ; }
Try to match a channel based solely on its unique ID
32,367
public void notifyHangupListeners ( Integer cause , String causeText ) { this . _isLive = false ; if ( this . hangupListener != null ) { this . hangupListener . channelHangup ( this , cause , causeText ) ; } else { logger . warn ( "Hangup listener is null" ) ; } }
Called by Peer when we have been hungup . This can happen when Peer receives a HangupEvent or during a periodic sweep done by PeerMonitor to find the status of all channels . Notify any listeners that this channel has been hung up .
32,368
public String getExtendedChannelName ( ) { final StringBuilder name = new StringBuilder ( ) ; if ( this . _isInAction ) { name . append ( this . _actionPrefix ) ; name . append ( "/" ) ; } name . append ( this . _channelName ) ; if ( this . _isMasqueraded ) { name . append ( ChannelImpl . MASQ ) ; } if ( this . _isZomb...
Returns the full channel name including the masquerade prefix and the zombie suffix .
32,369
@ SuppressWarnings ( "unchecked" ) protected AgiScript createAgiScriptInstance ( String className ) { Class < ? > tmpClass ; Class < AgiScript > agiScriptClass ; Constructor < AgiScript > constructor ; AgiScript agiScript ; agiScript = null ; try { tmpClass = getClassLoader ( ) . loadClass ( className ) ; } catch ( Cla...
Creates a new instance of an AGI script .
32,370
protected String escapeAndQuote ( String s ) { String tmp ; if ( s == null ) { return "\"\"" ; } tmp = s ; tmp = tmp . replaceAll ( "\\\\" , "\\\\\\\\" ) ; tmp = tmp . replaceAll ( "\\\"" , "\\\\\"" ) ; tmp = tmp . replaceAll ( "\\\n" , "" ) ; return "\"" + tmp + "\"" ; }
Escapes and quotes a given String according to the rules set by Asterisk s AGI .
32,371
public void setVariables ( Map < String , String > variables ) { if ( this . variables != null ) { this . variables . putAll ( variables ) ; } else { this . variables = variables ; } }
Sets the variables to set on the originated call .
32,372
public void setControlDigits ( String forwardDigit , String rewindDigit , String pauseDigit ) { this . forwardDigit = forwardDigit ; this . rewindDigit = rewindDigit ; this . pauseDigit = pauseDigit ; }
Sets the control digits for fast forward rewind and pause .
32,373
Collection < AsteriskChannel > getChannels ( ) { Collection < AsteriskChannel > copy ; synchronized ( channels ) { copy = new ArrayList < > ( channels . size ( ) + 2 ) ; for ( AsteriskChannel channel : channels . values ( ) ) { if ( channel . getState ( ) != ChannelState . HUNGUP ) { copy . add ( channel ) ; } } } retu...
Returns a collection of all active AsteriskChannels .
32,374
AsteriskChannelImpl getChannelImplByName ( String name ) { Date dateOfCreation = null ; AsteriskChannelImpl channel = null ; if ( name == null ) { return null ; } synchronized ( channels ) { for ( AsteriskChannelImpl tmp : channels . values ( ) ) { if ( name . equals ( tmp . getName ( ) ) ) { if ( dateOfCreation == nul...
Returns a channel from the ChannelManager s cache with the given name If multiple channels are found returns the most recently CREATED one . If two channels with the very same date exist avoid HUNGUP ones .
32,375
AsteriskChannelImpl getChannelImplByNameAndActive ( String name ) { AsteriskChannelImpl channel = null ; if ( name == null ) { return null ; } synchronized ( channels ) { for ( AsteriskChannelImpl tmp : channels . values ( ) ) { if ( name . equals ( tmp . getName ( ) ) && tmp . getState ( ) != ChannelState . HUNGUP ) {...
Returns a NON - HUNGUP channel from the ChannelManager s cache with the given name .
32,376
static private void syncDial ( ) { try { PBX pbx = PBXFactory . getActivePBX ( ) ; Trunk trunk = pbx . buildTrunk ( "default" ) ; EndPoint from = pbx . buildEndPoint ( TechType . SIP , "100" ) ; CallerID fromCallerID = pbx . buildCallerID ( "100" , "My Phone" ) ; CallerID toCallerID = pbx . buildCallerID ( "83208100" ,...
Simple synchronous dial . The dial method won t return until the dial starts . Using this method will lockup your UI until the dial starts . For better control use the async Dial method below .
32,377
public final Logger getLogger ( ) { if ( logger == null ) { logger = LoggerFactory . getLogger ( clazz ) ; } if ( logger instanceof LocationAwareLogger ) { return new LocationAwareWrapper ( FQCN , ( LocationAwareLogger ) logger ) ; } return this . logger ; }
Return the native Logger instance we are using .
32,378
void initialize ( ) throws ManagerCommunicationException { ResponseEvents re ; re = server . sendEventGeneratingAction ( new AgentsAction ( ) ) ; for ( ManagerEvent event : re . getEvents ( ) ) { if ( event instanceof AgentsEvent ) { logger . info ( event ) ; handleAgentsEvent ( ( AgentsEvent ) event ) ; } } }
Retrieves all agents registered at Asterisk server by sending an AgentsAction .
32,379
void handleAgentsEvent ( AgentsEvent event ) { AsteriskAgentImpl agent = new AsteriskAgentImpl ( server , event . getName ( ) , "Agent/" + event . getAgent ( ) , AgentState . valueOf ( event . getStatus ( ) ) ) ; logger . info ( "Adding agent " + agent . getName ( ) + "(" + agent . getAgentId ( ) + ")" ) ; addAgent ( a...
On AgentsEvent create a new Agent .
32,380
private void addAgent ( AsteriskAgentImpl agent ) { synchronized ( agents ) { agents . put ( agent . getAgentId ( ) , agent ) ; } server . fireNewAgent ( agent ) ; }
Add a new agent to the manager .
32,381
void handleAgentCalledEvent ( AgentCalledEvent event ) { AsteriskAgentImpl agent = getAgentByAgentId ( event . getAgentCalled ( ) ) ; if ( agent == null ) { logger . error ( "Ignored AgentCalledEvent for unknown agent " + event . getAgentCalled ( ) ) ; return ; } updateRingingAgents ( event . getChannelCalling ( ) , ag...
Update state if agent was called .
32,382
private void updateAgentState ( AsteriskAgentImpl agent , AgentState newState ) { logger . info ( "Set state of agent " + agent . getAgentId ( ) + " to " + newState ) ; synchronized ( agent ) { agent . updateState ( newState ) ; } }
Set state of agent .
32,383
private void updateRingingAgents ( String channelCalling , AsteriskAgentImpl agent ) { synchronized ( ringingAgents ) { if ( ringingAgents . containsKey ( channelCalling ) ) { updateAgentState ( ringingAgents . get ( channelCalling ) , AgentState . AGENT_IDLE ) ; } ringingAgents . put ( channelCalling , agent ) ; } }
Updates state of agent if the call in a queue was redirect to the next agent because the ringed agent doesn t answer the call . After reset state put the next agent in charge .
32,384
void handleAgentConnectEvent ( AgentConnectEvent event ) { AsteriskAgentImpl agent = getAgentByAgentId ( event . getChannel ( ) ) ; if ( agent == null ) { logger . error ( "Ignored AgentConnectEvent for unknown agent " + event . getChannel ( ) ) ; return ; } agent . updateState ( AgentState . AGENT_ONCALL ) ; }
Update state if agent was connected to channel .
32,385
Collection < AsteriskAgent > getAgents ( ) { Collection < AsteriskAgent > copy ; synchronized ( agents ) { copy = new ArrayList < AsteriskAgent > ( agents . values ( ) ) ; } return copy ; }
Return all agents registered at Asterisk server .
32,386
void handleAgentCompleteEvent ( AgentCompleteEvent event ) { AsteriskAgentImpl agent = getAgentByAgentId ( event . getChannel ( ) ) ; if ( agent == null ) { logger . error ( "Ignored AgentCompleteEvent for unknown agent " + event . getChannel ( ) ) ; return ; } agent . updateState ( AgentState . AGENT_IDLE ) ; }
Change state if connected call was terminated .
32,387
public void setReason ( String s ) { int spaceIdx ; if ( s == null ) { return ; } spaceIdx = s . indexOf ( ' ' ) ; if ( spaceIdx <= 0 ) { spaceIdx = s . length ( ) ; } try { this . reason = Integer . valueOf ( s . substring ( 0 , spaceIdx ) ) ; } catch ( NumberFormatException e ) { return ; } if ( s . length ( ) > spac...
Sets the reason for disabling logging .
32,388
private void fireChainListeners ( ManagerEvent event ) { synchronized ( this . chainListeners ) { for ( ManagerEventListener listener : this . chainListeners ) listener . onManagerEvent ( event ) ; } }
dispatch the event to the chainListener if they exist .
32,389
public static String getInternalActionId ( String actionId ) { final int delimiterIndex ; if ( actionId == null ) { return null ; } delimiterIndex = actionId . indexOf ( INTERNAL_ACTION_ID_DELIMITER ) ; if ( delimiterIndex > 0 ) { return actionId . substring ( 0 , delimiterIndex ) ; } return null ; }
Returns the internal action id contained in the given action id .
32,390
public static String stripInternalActionId ( String actionId ) { int delimiterIndex ; delimiterIndex = actionId . indexOf ( INTERNAL_ACTION_ID_DELIMITER ) ; if ( delimiterIndex > 0 ) { if ( actionId . length ( ) > delimiterIndex + 1 ) { return actionId . substring ( delimiterIndex + 1 ) ; } return null ; } return null ...
Strips the internal action id from the given action id .
32,391
public static String addInternalActionId ( String actionId , String internalActionId ) { if ( actionId == null ) { return internalActionId + INTERNAL_ACTION_ID_DELIMITER ; } return internalActionId + INTERNAL_ACTION_ID_DELIMITER + actionId ; }
Adds the internal action id to the given action id .
32,392
public static void main ( String [ ] args ) throws Exception { final AgiServer server ; server = new DefaultAgiServer ( ) ; server . startup ( ) ; }
Creates a new DefaultAgiServer and starts it .
32,393
public String getVariable ( final Channel channel , final String variableName ) { String value = "" ; final GetVarAction var = new GetVarAction ( channel , variableName ) ; try { PBX pbx = PBXFactory . getActivePBX ( ) ; if ( ! pbx . waitForChannelToQuiescent ( channel , 3000 ) ) throw new PBXException ( "Channel: " + ...
Retrieves and returns the value of a variable associated with a channel . If the variable is empty or null then an empty string is returned .
32,394
public static void sendActionNoWait ( final ManagerAction action ) { final Thread background = new Thread ( ) { public void run ( ) { try { CoherentManagerConnection . sendAction ( action , 5000 ) ; } catch ( final Exception e ) { CoherentManagerConnection . logger . error ( e , e ) ; } } } ; background . setName ( "se...
Allows the caller to send an action to asterisk without waiting for the response . You should only use this if you don t care whether the action actually succeeds .
32,395
public static ManagerResponse sendAction ( final ManagerAction action , final int timeout ) throws IllegalArgumentException , IllegalStateException , IOException , TimeoutException { if ( logger . isDebugEnabled ( ) ) CoherentManagerConnection . logger . debug ( "Sending Action: " + action . toString ( ) ) ; CoherentMa...
Sends an Asterisk action and waits for a ManagerRespose .
32,396
public Map < Integer , String > getCategories ( ) { if ( categories == null ) { categories = new TreeMap < > ( ) ; } Map < String , Object > responseMap = super . getAttributes ( ) ; for ( Entry < String , Object > response : responseMap . entrySet ( ) ) { String key = response . getKey ( ) ; if ( key . toLowerCase ( L...
Returns the map of category numbers to category names .
32,397
public Map < Integer , String > getLines ( int categoryNumber ) { if ( lines == null ) { lines = new TreeMap < > ( ) ; } Map < String , Object > responseMap = super . getAttributes ( ) ; for ( Entry < String , Object > response : responseMap . entrySet ( ) ) { String key = response . getKey ( ) ; if ( key . toLowerCase...
Returns the map of line number to line value for a given category .
32,398
protected void ping ( ManagerConnection c ) { try { if ( timeout <= 0 ) { c . sendAction ( new PingAction ( ) , null ) ; } else { final ManagerResponse response ; response = c . sendAction ( new PingAction ( ) , timeout ) ; logger . debug ( "Ping response '" + response + "' for " + c . toString ( ) ) ; } } catch ( Exce...
Sends a ping to Asterisk and logs any errors that may occur .
32,399
public void addCommand ( String action , String cat , String var , String value , String match ) { final String stringCounter = String . format ( "%06d" , this . actionCounter ) ; if ( action != null ) { actions . put ( "Action-" + stringCounter , action ) ; } if ( cat != null ) { actions . put ( "Cat-" + stringCounter...
Adds a command to update a config file while sparing you the details of the Manager s required syntax . If you want to omit one of the command s sections provide a null value to this method . The command index will be incremented even if you supply a null for all parameters though the map will be unaffected .