Permalink
Browse files

Add example. Fix synchronization of transaction when starting timer.

  • Loading branch information...
ranganathanm committed Oct 16, 2009
1 parent 2aeb36b commit 45de8085189dfcfa03f26b02617bbf1b04ddf299
@@ -3,9 +3,9 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="ant-tasks/src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
<classpathentry kind="lib" path="lib/junit-3.8.1.jar"/>
<classpathentry kind="lib" path="ant-tasks/lib/jdom.jar"/>
<classpathentry kind="lib" path="ant-tasks/lib/ant.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
@@ -1 +1 @@
Mon Oct 12 10:49:06 GMT-05:00 2009
Fri Oct 16 11:06:04 GMT-05:00 2009
@@ -4,7 +4,7 @@ javac.target=1.5
javac.deprecation=true
javac.optimize=off
javac.debuglevel=lines,vars,source
log4j=lib/log4j-1.2.8.jar
log4j=lib/log4j-1.2.15.jar
# JUNIT ONLY REQUIRED FOR TESTING. NOT REQUIRED FOR jain-sip RI
junit=lib/junit-3.8.1.jar
# dom.jar AND ant.jar ONLY REQUIRED FOR BUILDING ANT EXTENSION TASK. NOT REQUIRED FOR jain-SIP RI.
@@ -168,6 +168,7 @@ public void execute() throws BuildException {
bw.write("jain-sip-all-tar=jain-sip-1.2." +(localVersion + 1) + ".tar.gz\n");
bw.write("jain-sip-tck-jar=jain-sip-tck-1.2."+(localVersion + 1) + ".jar\n");
bw.write("sdp_jar=jain-sdp-1.0."+(localVersion + 1) + ".jar\n");
bw.write("jain-sip-sctp-1.2"+(localVersion + 1) + ".jar\n");
bw.write("unit_test_jar=jain-sip-unit-test-1.2." + (localVersion+1) + ".jar\n");
bw.flush();
bw.close();
@@ -1,11 +1,10 @@
jain-sip-ri-jar=jain-sip-ri-1.2.124.jar
jain-sip-sdp-jar=jain-sip-sdp-1.2.124.jar
jain-sip-src-tar=jain-sip-src-1.2.124.tar.gz
jain-sip-javadoc-tar=jain-sip-javadoc-1.2.124.tar.gz
jain-sip-all-tar=jain-sip-1.2.124.tar.gz
jain-sip-tck-jar=jain-sip-tck-1.2.124.jar
sdp_jar=jain-sdp-1.0.124.jar
unit_test_jar=jain-sip-unit-test-1.2.124.jar
jain-sip-ri-jar=jain-sip-ri-1.2.125.jar
jain-sip-sdp-jar=jain-sip-sdp-1.2.125.jar
jain-sip-src-tar=jain-sip-src-1.2.125.tar.gz
jain-sip-javadoc-tar=jain-sip-javadoc-1.2.125.tar.gz
jain-sip-all-tar=jain-sip-1.2.125.tar.gz
jain-sip-tck-jar=jain-sip-tck-1.2.125.jar
sdp_jar=jain-sdp-1.0.125.jar
unit_test_jar=jain-sip-unit-test-1.2.125.jar
# JvB: please leave this one in for SCTP
jain-sip-sctp-jar=jain-sip-sctp-1.2.124.jar
jain-sip-sctp-jar=jain-sip-sctp-1.2.125.jar
BIN +383 KB lib/log4j-1.2.15.jar
Binary file not shown.
BIN -344 KB lib/log4j-1.2.8.jar
Binary file not shown.
@@ -0,0 +1,15 @@
package examples.nistgoodies.pluggablelogger;
import gov.nist.javax.sip.LogRecord;
import gov.nist.javax.sip.LogRecordFactory;
public class LogRecordFactoryImpl implements LogRecordFactory {
public LogRecord createLogRecord(String message, String source,
String destination, long timeStamp, boolean isSender,
String firstLine, String tid, String callId, long timestampVal) {
return new LogRecordImpl(message,source,destination,timeStamp,isSender,firstLine,tid,callId,timestampVal);
}
}
@@ -0,0 +1,71 @@
package examples.nistgoodies.pluggablelogger;
import gov.nist.javax.sip.LogRecord;
public class LogRecordImpl implements LogRecord {
private String message;
private String source;
private String destination;
private long timeStamp;
private String tid;
private String firstLine;
private String callId;
private long timestampVal;
/**
* Constructor for our custom log record
*
* @param message --
* the message to log
* @param source --
* the source
* @param destination --
* the destination
* @param timeStamp --
* the reception time
* @param isSender --
* the flag indicates whether we are sending or recieving the
* record
* @param firstLine --
* the messge first line
* @param tid --
* the transaction id
* @param callId --
* the callId
* @param timestampVal --
* the timestamp Header value.
*/
public LogRecordImpl(String message, String source, String destination,
long timeStamp, boolean isSender, String firstLine, String tid,
String callId, long timestampVal) {
this.message = message;
this.source = source;
this.destination = destination;
this.timeStamp = timeStamp;
this.firstLine = firstLine;
this.tid = tid;
this.callId = callId;
this.timestampVal = timestampVal;
}
public boolean equals(Object other) {
if (!(other instanceof LogRecordImpl)) {
return false;
} else {
LogRecordImpl otherLog = (LogRecordImpl) other;
return otherLog.message.equals(message)
&& otherLog.timeStamp == timeStamp;
}
}
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append("------------ Message BEGIN ----------- \n");
sbuf.append("timeStamp = " + this.timeStamp + "\n");
sbuf.append(this.message);
return sbuf.toString();
}
}
@@ -0,0 +1,40 @@
This example of a NIST only feature (not part of the JAIN-SIP standard)
shows how you can register a log factory with the stack to configure
logging. The log factory allows you to generate customized logging records
that can record envioronment conditions into the logging stream. This
facility is useful for logging, monitoring and debugging.
The stack property gov.nist.javax.sip.LOG_FACTORY points to a class which
SipStackImpl creates when it starts up. Each time a message is recieved
by the stack or sent out by the stack, the registered log factory is
called to generate a logging record.
How to run it and what to look for
----------------------------------
How to run it
-------------
Run this example from two command prompts using
ant shootme
from another command prompt
ant shootist
What to look at
---------------
Then examine the log generated in shootistlog.txt
Compare it with the custom log record LogRecordImpl.java
Take a look at the configuration setup in Shootist.java
Take a look at the code in LogFactoryImpl.java
Take a look at the code in StackLoggerImpl.java
Take a look at the code in ServerLoggerImpl.java
Thanks to Jean Deruelle for providing support for a pluggable logger.
@@ -0,0 +1,83 @@
package examples.nistgoodies.pluggablelogger;
import java.util.Properties;
import javax.sip.SipStack;
import javax.sip.header.TimeStampHeader;
import gov.nist.core.ServerLogger;
import gov.nist.javax.sip.LogRecord;
import gov.nist.javax.sip.LogRecordFactory;
import gov.nist.javax.sip.SipStackImpl;
import gov.nist.javax.sip.header.CallID;
import gov.nist.javax.sip.message.SIPMessage;
public class ServerLoggerImpl implements ServerLogger {
private SipStackImpl sipStack;
private LogRecordFactory logRecordFactory;
public ServerLoggerImpl() {
this.logRecordFactory = new LogRecordFactoryImpl();
}
@Override
public void closeLogFile() {
}
@Override
public void logException(Exception exception) {
sipStack.getStackLogger().logStackTrace();
}
@Override
public void logMessage(SIPMessage message, String source, String destination, boolean isSender, long timeStamp) {
String firstLine = message.getFirstLine();
String tid = message.getTransactionId();
String callId = message.getCallId().getCallId();
LogRecord logRecord = logRecordFactory.createLogRecord(message.encode(), source, destination, timeStamp, isSender, firstLine, tid, callId,
0);
sipStack.getStackLogger().logInfo(logRecord.toString());
}
@Override
public void logMessage(SIPMessage message, String from, String to, String status, boolean sender) {
logMessage(message, from, to, status, sender, System.currentTimeMillis());
}
@Override
public void logMessage(SIPMessage message, String source, String destination, String status, boolean isSender,
long timeStamp) {
// TODO Auto-generated method stub
CallID cid = (CallID) message.getCallId();
String callId = null;
if (cid != null)
callId = cid.getCallId();
String firstLine = message.getFirstLine().trim();
String tid = message.getTransactionId();
TimeStampHeader tshdr = (TimeStampHeader) message.getHeader(TimeStampHeader.NAME);
long tsval = tshdr == null ? 0 : tshdr.getTime();
LogRecord logRecord = logRecordFactory.createLogRecord(message.encode(), source, destination, timeStamp, isSender, firstLine, tid, callId,
tsval);
sipStack.getStackLogger().logInfo(logRecord.toString());
}
@Override
public void setSipStack(SipStack sipStack) {
this.sipStack = (SipStackImpl) sipStack;
}
@Override
public void setStackProperties(Properties properties) {
}
}
Oops, something went wrong.

0 comments on commit 45de808

Please sign in to comment.