You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2008/06/09 16:36:09 UTC
svn commit: r665704 - in
/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr:
AprLibrary.java AprSession.java AprSocketSession.java
Author: jvermillard
Date: Mon Jun 9 07:36:09 2008
New Revision: 665704
URL: http://svn.apache.org/viewvc?rev=665704&view=rev
Log:
DIRMINA-594 javadoc on APR library singleton, APR abstract session and APR socket session. Still miss javadoc for APR datagram session and managing class (IO processor and accpetor/connector).
Modified:
mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprLibrary.java
mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSession.java
mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketSession.java
Modified: mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprLibrary.java
URL: http://svn.apache.org/viewvc/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprLibrary.java?rev=665704&r1=665703&r2=665704&view=diff
==============================================================================
--- mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprLibrary.java (original)
+++ mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprLibrary.java Mon Jun 9 07:36:09 2008
@@ -22,9 +22,16 @@
import org.apache.tomcat.jni.Library;
import org.apache.tomcat.jni.Pool;
+import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
+
/**
- * Internal singleton used for initializing corretcly the APR native library
- * and the associated memory pool.
+ * Internal singleton used for initializing correctly the APR native library
+ * and the associated root memory pool.
+ *
+ * It'll finalize nicely the native resources (libraries and memory pools).
+ *
+ * Each memory pool used in the APR transport module needs to be children of the
+ * root pool {@link AprLibrary#getRootPool()}.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
@@ -34,17 +41,29 @@
// is APR library was initialized (load of native libraries)
private static AprLibrary library = null;
+ /**
+ * get the shared instance of APR library, if none, initialize one
+ * @return the current APR library singleton
+ */
static synchronized AprLibrary getInstance() {
if (!isInitialized())
initialize();
return library;
}
- static synchronized void initialize() {
+ /**
+ * initialize the APR Library by loading the associated native libraries
+ * and creating the associated singleton
+ */
+ private static synchronized void initialize() {
if (library == null)
library = new AprLibrary();
}
+ /**
+ * is the APR library was initialized.
+ * @return
+ */
static synchronized boolean isInitialized() {
return library != null;
}
@@ -52,6 +71,11 @@
// APR memory pool (package wide mother pool)
private final long pool;
+ /**
+ * APR library singleton constructor. Called only when accessing the
+ * singleton the first time.
+ * It's initializing an APR memory pool for the whole package (a.k.a mother or root pool).
+ */
private AprLibrary() {
try {
Library.initialize(null);
@@ -68,6 +92,11 @@
Pool.destroy(pool);
}
+ /**
+ * get the package wide root pool, the mother of all the pool created
+ * in APR transport module.
+ * @return number identifying the root pool
+ */
long getRootPool() {
return pool;
}
Modified: mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSession.java
URL: http://svn.apache.org/viewvc/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSession.java?rev=665704&r1=665703&r2=665704&view=diff
==============================================================================
--- mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSession.java (original)
+++ mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSession.java Mon Jun 9 07:36:09 2008
@@ -29,33 +29,49 @@
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoSession;
import org.apache.tomcat.jni.Address;
+import org.apache.tomcat.jni.Poll;
import org.apache.tomcat.jni.Socket;
/**
- * {@link IoSession} for the {@link AprSocketConnector}
- *
+ * An abstract {@link IoSession} serving of base for APR based sessions.
+ *
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
public abstract class AprSession extends AbstractIoSession {
- private long descriptor;
+
+ // good old socket descriptor
+ private long descriptor;
+ // the service handling this session
private final IoService service;
+
+ // the processor processing this session
private final IoProcessor<AprSession> processor;
+ // the mandatory filter chain of this session
private final IoFilterChain filterChain = new DefaultIoFilterChain(this);
+
+ // handler listeneing this session event
private final IoHandler handler;
+ // the two endpoint addresses
private final InetSocketAddress remoteAddress;
private final InetSocketAddress localAddress;
+ // current polling results
private boolean readable = true;
private boolean writable = true;
private boolean interestedInRead;
private boolean interestedInWrite;
/**
- * Creates a new instance.
+ * Creates a new instance of {@link AprSession}. Need to be called by extending types
+ * @param service the {@link IoService} creating this session. Can be {@link AprSocketAcceptor} or
+ * {@link AprSocketConnector}
+ * @param processor the {@link AprIoProcessor} managing this session.
+ * @param descriptor the low level APR socket descriptor for this socket. {@see Socket#create(int, int, int, long)}
+ * @throws Exception exception produced during the setting of all the socket parameters.
*/
AprSession(
IoService service, IoProcessor<AprSession> processor, long descriptor) throws Exception {
@@ -71,6 +87,16 @@
this.localAddress = new InetSocketAddress(Address.getip(la), Address.getInfo(la).port);
}
+ /**
+ * Creates a new instance of {@link AprSession}. Need to be called by extending types.
+ * The constructor add remote address for UDP based sessions.
+ * @param service the {@link IoService} creating this session. Can be {@link AprSocketAcceptor} or
+ * {@link AprSocketConnector}
+ * @param processor the {@link AprIoProcessor} managing this session.
+ * @param descriptor the low level APR socket descriptor for this socket. {@see Socket#create(int, int, int, long)}
+ * @param remoteAddress the remote end-point
+ * @throws Exception exception produced during the setting of all the socket parameters.
+ */
AprSession(
IoService service, IoProcessor<AprSession> processor,
long descriptor, InetSocketAddress remoteAddress) throws Exception {
@@ -85,72 +111,137 @@
this.localAddress = new InetSocketAddress(Address.getip(la), Address.getInfo(la).port);
}
+ /**
+ * Get the socket descriptor {@see Socket#create(int, int, int, long)}.
+ * @return the low level APR socket descriptor
+ */
long getDescriptor() {
return descriptor;
}
+ /**
+ * Set the socket descriptor.
+ * @param desc the low level APR socket descriptor created by {@see Socket#create(int, int, int, long)}
+ */
void setDescriptor(long desc) {
this.descriptor = desc;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected IoProcessor<AprSession> getProcessor() {
return processor;
}
+ /**
+ * {@inheritDoc}
+ */
public InetSocketAddress getLocalAddress() {
return localAddress;
}
+ /**
+ * {@inheritDoc}
+ */
public InetSocketAddress getRemoteAddress() {
return remoteAddress;
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public IoFilterChain getFilterChain() {
return filterChain;
}
+ /**
+ * {@inheritDoc}
+ */
public IoHandler getHandler() {
return handler;
}
+ /**
+ * {@inheritDoc}
+ */
public IoService getService() {
return service;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public InetSocketAddress getServiceAddress() {
return (InetSocketAddress) super.getServiceAddress();
}
+ /**
+ * Is this session was tagged are readable after a call to {@link Socket#pool(long)}.
+ * @return true if this session is ready for read operations
+ */
boolean isReadable() {
return readable;
}
+ /**
+ * Set if this session is readable after a call to {@link Socket#pool(long)}.
+ * @param readable true for set this session ready for read operations
+ */
void setReadable(boolean readable) {
this.readable = readable;
}
+ /**
+ * Is this session is tagged writable after a call to {@link Socket#pool(long)}.
+ * @return true if this session is ready for write operations
+ */
boolean isWritable() {
return writable;
}
+ /**
+ * Set if this session is writable after a call to {@link Socket#pool(long)}.
+ * @param writable true for set this session ready for write operations
+ */
void setWritable(boolean writable) {
this.writable = writable;
}
-
+
+ /**
+ * Does this session needs to be registered for read events.
+ * Used for building poll set {@see Poll}.
+ * @return true if registered
+ */
boolean isInterestedInRead() {
return interestedInRead;
}
+ /**
+ * Set if this session needs to be registered for read events.
+ * Used for building poll set {@see Poll}.
+ * @param isOpRead true if need to be registered
+ */
void setInterestedInRead(boolean isOpRead) {
this.interestedInRead = isOpRead;
}
+ /**
+ * Does this session needs to be registered for write events.
+ * Used for building poll set {@see Poll}.
+ * @return true if registered
+ */
boolean isInterestedInWrite() {
return interestedInWrite;
}
+ /**
+ * Set if this session needs to be registered for write events.
+ * Used for building poll set {@see Poll}.
+ * @param isOpWrite true if need to be registered
+ */
void setInterestedInWrite(boolean isOpWrite) {
this.interestedInWrite = isOpWrite;
}
Modified: mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketSession.java
URL: http://svn.apache.org/viewvc/mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketSession.java?rev=665704&r1=665703&r2=665704&view=diff
==============================================================================
--- mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketSession.java (original)
+++ mina/trunk/transport-apr/src/main/java/org/apache/mina/transport/socket/apr/AprSocketSession.java Mon Jun 9 07:36:09 2008
@@ -25,6 +25,8 @@
import org.apache.mina.common.IoBuffer;
import org.apache.mina.common.IoProcessor;
import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.RuntimeIoException;
import org.apache.mina.common.TransportMetadata;
import org.apache.mina.transport.socket.AbstractSocketSessionConfig;
@@ -33,13 +35,15 @@
import org.apache.tomcat.jni.Socket;
/**
- * TODO Add documentation
+ * An {@link IoSession} for APR socket based session.
+ * It's implementing the usual common features for {@SocketSession}.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
class AprSocketSession extends AprSession implements SocketSession {
+
static final TransportMetadata METADATA =
new DefaultTransportMetadata(
"apr", "socket", false, true,
@@ -49,24 +53,39 @@
private final SocketSessionConfig config = new SessionConfigImpl();
+ /**
+ * Create an instance of {@link AprSocketSession}.
+ *
+ * {@inheritDoc}
+ */
AprSocketSession(
IoService service, IoProcessor<AprSession> processor, long descriptor) throws Exception {
super(service, processor, descriptor);
this.config.setAll(service.getSessionConfig());
}
-
+ /**
+ * {@inheritDoc}
+ */
public SocketSessionConfig getConfig() {
return config;
}
+ /**
+ * {@inheritDoc}
+ */
public TransportMetadata getTransportMetadata() {
return METADATA;
}
-
+ /**
+ * The implementation for the {@link IoSessionConfig} related to APR socket.
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ */
private class SessionConfigImpl extends AbstractSocketSessionConfig {
-
+ /**
+ * {@inheritDoc}
+ */
public boolean isKeepAlive() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_SO_KEEPALIVE) == 1;
@@ -74,18 +93,32 @@
throw new RuntimeIoException("Failed to get SO_KEEPALIVE.", e);
}
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public void setKeepAlive(boolean on) {
Socket.optSet(getDescriptor(), Socket.APR_SO_KEEPALIVE, on ? 1 : 0);
}
+ /**
+ * {@inheritDoc}
+ * not supported for the moment
+ */
public boolean isOobInline() {
return false;
}
+ /**
+ * {@inheritDoc}
+ * not supported for the moment
+ */
public void setOobInline(boolean on) {
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isReuseAddress() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_SO_REUSEADDR) == 1;
@@ -94,10 +127,16 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public void setReuseAddress(boolean on) {
Socket.optSet(getDescriptor(), Socket.APR_SO_REUSEADDR, on ? 1 : 0);
}
+ /**
+ * {@inheritDoc}
+ */
public int getSoLinger() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_SO_LINGER);
@@ -106,11 +145,17 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public void setSoLinger(int linger) {
// TODO: Figure out how to disable this.
Socket.optSet(getDescriptor(), Socket.APR_SO_LINGER, linger);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isTcpNoDelay() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_TCP_NODELAY) == 1;
@@ -119,17 +164,29 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public void setTcpNoDelay(boolean on) {
Socket.optSet(getDescriptor(), Socket.APR_TCP_NODELAY, on ? 1 : 0);
}
+ /**
+ * {@inheritDoc}
+ */
public int getTrafficClass() {
return 0;
}
+ /**
+ * {@inheritDoc}
+ */
public void setTrafficClass(int tc) {
}
+ /**
+ * {@inheritDoc}
+ */
public int getSendBufferSize() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_SO_SNDBUF);
@@ -137,11 +194,17 @@
throw new RuntimeException("APR Exception", e);
}
}
-
+
+ /**
+ * {@inheritDoc}
+ */
public void setSendBufferSize(int size) {
Socket.optSet(getDescriptor(), Socket.APR_SO_SNDBUF, size);
}
+ /**
+ * {@inheritDoc}
+ */
public int getReceiveBufferSize() {
try {
return Socket.optGet(getDescriptor(), Socket.APR_SO_RCVBUF);
@@ -150,6 +213,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public void setReceiveBufferSize(int size) {
Socket.optSet(getDescriptor(), Socket.APR_SO_RCVBUF, size);
}