Revision: 1a6ccf989425
Author: deruelle_jean <deruelle_jean@8e71dc83-d81e-6649-80f2-80b843a9b2be>
Date: Wed Aug 1 03:00:34 2012
Log: Update Issue 9
Fixes http://java.net/jira/browse/JSIP-430
git-svn-id:
https://svn.java.net/svn/jsip~svn/branches/JAIN-SIP-NIO-year-2012@2137
8e71dc83-d81e-6649-80f2-80b843a9b2be
http://code.google.com/p/jain-sip/source/detail?r=1a6ccf989425
Added:
/src/gov/nist/javax/sip/stack/ByteBufferFactory.java
Modified:
/src/gov/nist/javax/sip/SipStackImpl.java
/src/gov/nist/javax/sip/stack/NioTlsMessageChannel.java
/src/gov/nist/javax/sip/stack/SSLStateMachine.java
=======================================
--- /dev/null
+++ /src/gov/nist/javax/sip/stack/ByteBufferFactory.java Wed Aug 1
03:00:34 2012
@@ -0,0 +1,69 @@
+/*
+ * Conditions Of Use
+ *
+ * This software was developed by employees of the National Institute of
+ * Standards and Technology (NIST), an agency of the Federal Government.
+ * Pursuant to title 15 Untied States Code Section 105, works of NIST
+ * employees are not subject to copyright protection in the United States
+ * and are considered to be in the public domain. As a result, a formal
+ * license is not needed to use the software.
+ *
+ * This software is provided by NIST as a service and is expressly
+ * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
+ * AND DATA ACCURACY. NIST does not warrant or make any representations
+ * regarding the use of the software or the results thereof, including but
+ * not limited to the correctness, accuracy, reliability or usefulness of
+ * the software.
+ *
+ * Permission to use this software is contingent upon your acceptance
+ * of the terms of this agreement
+ *
+ * .
+ *
+ */
+package gov.nist.javax.sip.stack;
+
+import gov.nist.core.CommonLogger;
+import gov.nist.core.LogWriter;
+import gov.nist.core.StackLogger;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Contributed by Alexander Saveliev, Avistar Communications for Issue
http://java.net/jira/browse/JSIP-430
+ * Allows to choose between direct vs non direct buffers
+ *
+ */
+public class ByteBufferFactory {
+
+ private static StackLogger logger =
CommonLogger.getLogger(ByteBufferFactory.class);
+
+ private static ByteBufferFactory instance = new ByteBufferFactory();
+
+ private boolean useDirect = true;
+
+ public static ByteBufferFactory getInstance() {
+ return instance;
+ }
+
+ public ByteBuffer allocateDirect(int capacity) {
+ if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
+ logger.logTrace("Allocating direct buffer " + capacity);
+ return useDirect ? ByteBuffer.allocateDirect(capacity) :
ByteBuffer.allocate(capacity);
+ }
+
+ public ByteBuffer allocate(int capacity) {
+ if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
+ logger.logTrace("Allocating buffer " + capacity);
+ return ByteBuffer.allocate(capacity);
+ }
+
+
+ public void setUseDirect(boolean useDirect) {
+ if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
+ logger.logTrace("Direct buffers are " +
(useDirect ? "enabled" : "disabled"));
+ this.useDirect = useDirect;
+ }
+}
=======================================
--- /src/gov/nist/javax/sip/SipStackImpl.java Fri Apr 13 08:43:43 2012
+++ /src/gov/nist/javax/sip/SipStackImpl.java Wed Aug 1 03:00:34 2012
@@ -340,6 +340,13 @@
* by the SIP RFC spec.
* </li>
*
+ * <li><b>gov.nist.javax.sip.stack.USE_DIRECT_BUFFERS = [true|false]</b>
<br/>
+ * Default is <it>true</it> If set to <it>false</it>, the NIO stack won't
use direct buffers.
+ * As Direct buffers reside outside of the heap memory, they can lead to
unforeseen out of memory exceptions
+ * as seen in http://java.net/jira/browse/JSIP-430. This flag allows to
use non direct buffers for better memory
+ * monitoring and management.
+ * </li>
+ *
* <li><b>gov.nist.javax.sip.COMPUTE_CONTENT_LENGTH_FROM_MESSAGE_BODY =
* [true|false] </b> <br/>
* Default is <it>false</it> If set to <it>true</it>, when you are
creating a
@@ -767,6 +774,11 @@
this.outboundProxy = configurationProperties
.getProperty("javax.sip.OUTBOUND_PROXY");
+ // http://java.net/jira/browse/JSIP-430
+ ByteBufferFactory.getInstance().setUseDirect(Boolean.valueOf(
+
configurationProperties.getProperty("gov.nist.javax.sip.stack.USE_DIRECT_BUFFERS",
+ Boolean.TRUE.toString())));
+
this.defaultRouter = new DefaultRouter(this, outboundProxy);
/** Retrieve the router path */
=======================================
--- /src/gov/nist/javax/sip/stack/NioTlsMessageChannel.java Thu Jul 19
14:20:11 2012
+++ /src/gov/nist/javax/sip/stack/NioTlsMessageChannel.java Wed Aug 1
03:00:34 2012
@@ -1,3 +1,28 @@
+/*
+ * Conditions Of Use
+ *
+ * This software was developed by employees of the National Institute of
+ * Standards and Technology (NIST), an agency of the Federal Government.
+ * Pursuant to title 15 Untied States Code Section 105, works of NIST
+ * employees are not subject to copyright protection in the United States
+ * and are considered to be in the public domain. As a result, a formal
+ * license is not needed to use the software.
+ *
+ * This software is provided by NIST as a service and is expressly
+ * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
+ * AND DATA ACCURACY. NIST does not warrant or make any representations
+ * regarding the use of the software or the results thereof, including but
+ * not limited to the correctness, accuracy, reliability or usefulness of
+ * the software.
+ *
+ * Permission to use this software is contingent upon your acceptance
+ * of the terms of this agreement
+ *
+ * .
+ *
+ */
package gov.nist.javax.sip.stack;
import gov.nist.core.CommonLogger;
@@ -170,9 +195,9 @@
if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
logger.logDebug("appBufferMax=" + appBufferMax + "
netBufferMax=" + netBufferMax);
}
- appFrameBuffer = ByteBuffer.allocateDirect(2*appBufferMax + 50);
-
- encryptedFrameBuffer = ByteBuffer.allocateDirect(netBufferMax);
+ appFrameBuffer =
ByteBufferFactory.getInstance().allocateDirect(2*appBufferMax + 50);
+
+ encryptedFrameBuffer =
ByteBufferFactory.getInstance().allocateDirect(netBufferMax);
}
public NioTlsMessageChannel(InetAddress inetAddress, int port,
=======================================
--- /src/gov/nist/javax/sip/stack/SSLStateMachine.java Fri Jul 6 15:35:32
2012
+++ /src/gov/nist/javax/sip/stack/SSLStateMachine.java Wed Aug 1 03:00:34
2012
@@ -1,20 +1,44 @@
+/*
+ * Conditions Of Use
+ *
+ * This software was developed by employees of the National Institute of
+ * Standards and Technology (NIST), an agency of the Federal Government.
+ * Pursuant to title 15 Untied States Code Section 105, works of NIST
+ * employees are not subject to copyright protection in the United States
+ * and are considered to be in the public domain. As a result, a formal
+ * license is not needed to use the software.
+ *
+ * This software is provided by NIST as a service and is expressly
+ * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
+ * AND DATA ACCURACY. NIST does not warrant or make any representations
+ * regarding the use of the software or the results thereof, including but
+ * not limited to the correctness, accuracy, reliability or usefulness of
+ * the software.
+ *
+ * Permission to use this software is contingent upon your acceptance
+ * of the terms of this agreement
+ *
+ * .
+ *
+ */
package gov.nist.javax.sip.stack;
import gov.nist.core.CommonLogger;
import gov.nist.core.LogWriter;
import gov.nist.core.StackLogger;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLEngineResult.HandshakeStatus;
+import javax.net.ssl.SSLEngineResult.Status;
+import javax.net.ssl.SSLException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLEngineResult;
-import javax.net.ssl.SSLEngineResult.Status;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLEngineResult.HandshakeStatus;
-
/**
* This is a helper state machine that negotiates the SSL connection
automatically
* without ever blocking any threads. It is important not to block here
because
@@ -178,7 +202,7 @@
if(tlsRecordBuffer == null) {
// Begin buffering, if there is already a buffer the normalization will
take of adding the bytes
- tlsRecordBuffer = ByteBuffer.allocateDirect(33270); // max record size
in other implementations
+ tlsRecordBuffer =
ByteBufferFactory.getInstance().allocateDirect(33270); // max record size
in other implementations
// Append the current buffer
tlsRecordBuffer.put(src);