Skip to content

Commit

Permalink
reduce logging levels
Browse files Browse the repository at this point in the history
  • Loading branch information
rlsutton1 committed Aug 10, 2017
1 parent 6f0b240 commit 558d117
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
Expand Up @@ -16,16 +16,16 @@
*/
package org.asteriskjava.fastagi.internal;

import org.asteriskjava.fastagi.AgiWriter;
import org.asteriskjava.fastagi.AgiReader;
import org.asteriskjava.fastagi.AgiChannelFactory;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiChannelFactory;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiReader;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.AgiScript;
import org.asteriskjava.fastagi.AgiWriter;
import org.asteriskjava.fastagi.MappingStrategy;
import org.asteriskjava.fastagi.NamedAgiScript;
import org.asteriskjava.fastagi.command.VerboseCommand;
Expand All @@ -34,8 +34,7 @@

/**
* An AgiConnectionHandler is created and run by the AgiServer whenever a new
* AGI connection from an Asterisk Server is received.
* <br>
* AGI connection from an Asterisk Server is received. <br>
* It reads the request using an AgiReader and runs the AgiScript configured to
* handle this type of request. Finally it closes the AGI connection.
*
Expand All @@ -54,9 +53,8 @@ public abstract class AgiConnectionHandler implements Runnable
private AgiScript script = null;
private AgiChannelFactory agiChannelFactory;


public static final ConcurrentMap<AgiConnectionHandler, AgiChannel> AGI_CONNECTION_HANDLERS =
new ConcurrentHashMap<>(32);
public static final ConcurrentMap<AgiConnectionHandler, AgiChannel> AGI_CONNECTION_HANDLERS = new ConcurrentHashMap<>(
32);

/**
* The strategy to use to determine which script to run.
Expand All @@ -66,8 +64,10 @@ public abstract class AgiConnectionHandler implements Runnable
/**
* Creates a new AGIConnectionHandler to handle the given socket connection.
*
* @param mappingStrategy the strategy to use to determine which script to run.
* @param agiChannelFactory the AgiFactory, that is used to create new AgiChannel objects.
* @param mappingStrategy the strategy to use to determine which script to
* run.
* @param agiChannelFactory the AgiFactory, that is used to create new
* AgiChannel objects.
*/
protected AgiConnectionHandler(MappingStrategy mappingStrategy, AgiChannelFactory agiChannelFactory)
{
Expand Down Expand Up @@ -108,7 +108,9 @@ protected AgiScript getScript()
*/
public abstract void release();

@Override public void run() {
@Override
public void run()
{
AgiChannel channel = null;

try
Expand All @@ -134,14 +136,16 @@ protected AgiScript getScript()
{
final String errorMessage;

errorMessage = "No script configured for URL '" + request.getRequestURL() + "' (script '" + request.getScript() + "')";
errorMessage = "No script configured for URL '" + request.getRequestURL() + "' (script '"
+ request.getScript() + "')";
logger.error(errorMessage);

setStatusVariable(channel, AJ_AGISTATUS_NOT_FOUND);
logToAsterisk(channel, errorMessage);
}
else if (script != null) {
AGI_CONNECTION_HANDLERS.put(this, channel);
else if (script != null)
{
AGI_CONNECTION_HANDLERS.put(this, channel);
runScript(script, request, channel);
}
}
Expand All @@ -155,19 +159,20 @@ else if (script != null) {
setStatusVariable(channel, AJ_AGISTATUS_FAILED);
logger.error("Unexpected Exception while handling request", e);
}
finally {
AGI_CONNECTION_HANDLERS.remove(this);
finally
{
AGI_CONNECTION_HANDLERS.remove(this);
AgiConnectionHandler.channel.set(null);
release();
}
}//run
}// run

private void runScript(AgiScript script, AgiRequest request, AgiChannel channel)
{
String threadName;
threadName = Thread.currentThread().getName();

logger.info("Begin AgiScript " + getScriptName(script) + " on " + threadName);
logger.debug("Begin AgiScript " + getScriptName(script) + " on " + threadName);
try
{
script.service(request, channel);
Expand All @@ -183,7 +188,7 @@ private void runScript(AgiScript script, AgiRequest request, AgiChannel channel)
logger.error("Exception running AgiScript " + getScriptName(script) + " on " + threadName, e);
setStatusVariable(channel, AJ_AGISTATUS_FAILED);
}
logger.info("End AgiScript " + getScriptName(script) + " on " + threadName);
logger.debug("End AgiScript " + getScriptName(script) + " on " + threadName);
}

protected String getScriptName(AgiScript script)
Expand Down
Expand Up @@ -27,7 +27,11 @@ public void execute(AgiChannel channel, Channel ichannel) throws AgiException, I
callReachedAgi = true;
channel.answer();
channel.playMusicOnHold();
logger.info(ichannel + " is still on hold");
long secondsOnHold = Math.abs(System.currentTimeMillis() - timer) / 1000;
if (secondsOnHold > 600)
{
logger.info(ichannel + " is still on hold after " + secondsOnHold + " seconds");
}
if (latch.await(10, TimeUnit.SECONDS))
{
try
Expand All @@ -41,7 +45,6 @@ public void execute(AgiChannel channel, Channel ichannel) throws AgiException, I
}
else
{
long secondsOnHold = Math.abs(System.currentTimeMillis() - timer) / 1000;
if (channel.getName().startsWith("Local") && secondsOnHold > 3600)
{
// cleanup Local channels older than 1 hour
Expand Down
Expand Up @@ -51,10 +51,7 @@ public AgiScript determineScript(AgiRequest request, AgiChannel channel)
{
script = script.substring(0, script.indexOf("."));
}
else
{
logger.warn("scripts should be called as scriptname.agi");
}

if (script.startsWith("/"))
{
// this is specifically for the "FastAgiSimulator"
Expand Down

0 comments on commit 558d117

Please sign in to comment.