You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2013/03/22 14:49:19 UTC
[1/5] git commit: o The channel is declared in the AbstractIoChannel
as a SelectableChannel o Casting the channel to reflect its nature in
NioTcpSession and NioUdpSession o Added a processSessionCreated() method in
AbstractIoChannel
Updated Branches:
refs/heads/trunk fa342bb4b -> abe194309
o The channel is declared in the AbstractIoChannel as a
SelectableChannel
o Casting the channel to reflect its nature in NioTcpSession and
NioUdpSession
o Added a processSessionCreated() method in AbstractIoChannel
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/02f02e72
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/02f02e72
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/02f02e72
Branch: refs/heads/trunk
Commit: 02f02e72c0386404d603c5202c382c7b98049939
Parents: fa342bb
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Fri Mar 22 14:02:24 2013 +0100
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Fri Mar 22 14:02:24 2013 +0100
----------------------------------------------------------------------
.../org/apache/mina/session/AbstractIoSession.java | 36 ++++++++-
.../apache/mina/transport/nio/NioTcpSession.java | 24 +++---
.../apache/mina/transport/nio/NioUdpSession.java | 63 +++++++++++++--
3 files changed, 100 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/02f02e72/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/session/AbstractIoSession.java b/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
index 9afd2ac..28f9b9e 100644
--- a/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
+++ b/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
@@ -20,6 +20,7 @@
package org.apache.mina.session;
import java.nio.ByteBuffer;
+import java.nio.channels.SelectableChannel;
import java.util.Collections;
import java.util.Queue;
import java.util.Set;
@@ -62,6 +63,9 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon
/** The logger for this class */
private static final Logger LOG = LoggerFactory.getLogger(AbstractIoSession.class);
+ /** the NIO channel for this session */
+ protected final SelectableChannel channel;
+
/** unique identifier generator */
private static final AtomicInteger NEXT_ID = new AtomicInteger(0);
@@ -148,7 +152,7 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon
* @param service the service this session is associated with
* @param selectorLoop the selector loop in charge of processing this session read/write events
*/
- public AbstractIoSession(final IoService service, final IdleChecker idleChecker) {
+ public AbstractIoSession(final IoService service, SelectableChannel channel, final IdleChecker idleChecker) {
// generated a unique id
id = NEXT_ID.getAndIncrement();
creationTime = System.currentTimeMillis();
@@ -156,6 +160,7 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon
this.chain = service.getFilters();
this.idleChecker = idleChecker;
this.config = service.getSessionConfig();
+ this.channel = channel;
LOG.debug("Created new session with id : {}", id);
@@ -739,6 +744,35 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon
}
/**
+ * process session open event using the filter chain. To be called by the session {@link SelectorLoop} .
+ */
+ public void processSessionCreated() {
+ LOG.debug("processing session open event");
+
+ try {
+
+ for (final IoFilter filter : chain) {
+ filter.sessionOpened(this);
+ }
+
+ final IoHandler handler = getService().getIoHandler();
+
+ if (handler != null) {
+ IoHandlerExecutor executor = getService().getIoHandlerExecutor();
+ if (executor != null) {
+ // asynchronous event
+ executor.execute(new OpenEvent(this));
+ } else {
+ // synchronous call (in the I/O loop)
+ handler.sessionOpened(this);
+ }
+ }
+ } catch (final RuntimeException e) {
+ processException(e);
+ }
+ }
+
+ /**
* process session closed event using the filter chain. To be called by the session {@link SelectorLoop} .
*/
public void processSessionClosed() {
http://git-wip-us.apache.org/repos/asf/mina/blob/02f02e72/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java b/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
index 7dbb324..26dfc5c 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioTcpSession.java
@@ -52,9 +52,6 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
private static final Logger LOG = LoggerFactory.getLogger(NioTcpSession.class);
- /** the NIO socket channel for this TCP session */
- private final SocketChannel channel;
-
/** the selector loop in charge of generating read/write events for this session */
private final SelectorLoop selectorLoop;
@@ -73,10 +70,9 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
/** The size of the buffer configured in the socket to send data */
private int sendBufferSize;
- NioTcpSession(final IoService service, final SocketChannel channel, final SelectorLoop selectorLoop,
- final IdleChecker idleChecker) {
- super(service, idleChecker);
- this.channel = channel;
+ /* No qualifier*/NioTcpSession(final IoService service, final SocketChannel channel,
+ final SelectorLoop selectorLoop, final IdleChecker idleChecker) {
+ super(service, channel, idleChecker);
this.selectorLoop = selectorLoop;
this.configuration = new ProxyTcpSessionConfig(channel.socket());
sendBufferSize = configuration.getSendBufferSize();
@@ -93,7 +89,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
* @return the socket channel used by this session
*/
SocketChannel getSocketChannel() {
- return channel;
+ return (SocketChannel) channel;
}
/**
@@ -104,7 +100,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
if (channel == null) {
return null;
}
- final Socket socket = channel.socket();
+ final Socket socket = ((SocketChannel) channel).socket();
if (socket == null) {
return null;
@@ -122,7 +118,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
return null;
}
- final Socket socket = channel.socket();
+ final Socket socket = ((SocketChannel) channel).socket();
if (socket == null) {
return null;
@@ -158,7 +154,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
// Check that we can write into the channel
if (!isRegisteredForWrite()) {
// We don't have pending writes
- return channel.write((ByteBuffer) message);
+ return ((SocketChannel) channel).write((ByteBuffer) message);
} else {
return -1;
}
@@ -298,7 +294,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
readBuffer.clear();
// Read everything we can up to the buffer size
- final int readCount = channel.read(readBuffer);
+ final int readCount = ((SocketChannel) channel).read(readBuffer);
LOG.debug("read {} bytes", readCount);
@@ -366,7 +362,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
// Try to write the data, and get back the number of bytes
// actually written
- final int written = channel.write(buf);
+ final int written = ((SocketChannel) channel).write(buf);
LOG.debug("wrote {} bytes to {}", written, this);
if (written > 0) {
@@ -446,7 +442,7 @@ public class NioTcpSession extends AbstractIoSession implements SelectorListener
if (connect) {
try {
- boolean isConnected = channel.finishConnect();
+ boolean isConnected = ((SocketChannel) channel).finishConnect();
if (!isConnected) {
LOG.error("unable to connect session {}", this);
http://git-wip-us.apache.org/repos/asf/mina/blob/02f02e72/core/src/main/java/org/apache/mina/transport/nio/NioUdpSession.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioUdpSession.java b/core/src/main/java/org/apache/mina/transport/nio/NioUdpSession.java
index 25006e2..12d80a8 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioUdpSession.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioUdpSession.java
@@ -19,15 +19,18 @@
package org.apache.mina.transport.nio;
+import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
import org.apache.mina.api.IoFuture;
import org.apache.mina.api.IoService;
-import org.apache.mina.api.IoSessionConfig;
import org.apache.mina.service.idlechecker.IdleChecker;
import org.apache.mina.session.AbstractIoSession;
import org.apache.mina.session.WriteRequest;
+import org.apache.mina.transport.udp.UdpSessionConfig;
import org.apache.mina.util.AbstractIoFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +40,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class NioUdpSession extends AbstractIoSession {
+public class NioUdpSession extends AbstractIoSession implements SelectorListener {
private static final Logger LOG = LoggerFactory.getLogger(NioUdpSession.class);
@@ -45,6 +48,9 @@ public class NioUdpSession extends AbstractIoSession {
private final SocketAddress remoteAddress;
+ /** the socket configuration */
+ private final UdpSessionConfig configuration;
+
/** we pre-allocate a close future for lock-less {@link #close(boolean)} */
private final IoFuture<Void> closeFuture = new AbstractIoFuture<Void>() {
@@ -63,11 +69,13 @@ public class NioUdpSession extends AbstractIoSession {
* @param writeProcessor
* @param idleChecker
*/
- public NioUdpSession(IoService service, IdleChecker idleChecker, SocketAddress localAddress,
- SocketAddress remoteAddress) {
- super(service, idleChecker);
+ /* No qualifier*/NioUdpSession(IoService service, IdleChecker idleChecker, DatagramChannel datagramChannel,
+ SocketAddress localAddress, SocketAddress remoteAddress) {
+ super(service, datagramChannel, idleChecker);
this.localAddress = localAddress;
this.remoteAddress = remoteAddress;
+ this.config = service.getSessionConfig();
+ this.configuration = (UdpSessionConfig) this.config;
}
/**
@@ -187,8 +195,8 @@ public class NioUdpSession extends AbstractIoSession {
* {@inheritDoc}
*/
@Override
- public IoSessionConfig getConfig() {
- return null;
+ public UdpSessionConfig getConfig() {
+ return configuration;
}
/**
@@ -206,7 +214,20 @@ public class NioUdpSession extends AbstractIoSession {
*/
@Override
protected int writeDirect(Object message) {
- return 0;
+ try {
+ // Check that we can write into the channel
+ if (!isRegisteredForWrite()) {
+ // We don't have pending writes
+ return ((DatagramChannel) channel).write((ByteBuffer) message);
+ } else {
+ return -1;
+ }
+ } catch (final IOException e) {
+ LOG.error("Exception while reading : ", e);
+ processException(e);
+
+ return -1;
+ }
}
/**
@@ -216,4 +237,30 @@ public class NioUdpSession extends AbstractIoSession {
protected ByteBuffer convertToDirectBuffer(WriteRequest writeRequest, boolean createNew) {
return (ByteBuffer) writeRequest.getMessage();
}
+
+ void setSelectionKey(SelectionKey key) {
+ //this.selectionKey = key;
+ }
+
+ /**
+ * Set this session status as connected. To be called by the processor selecting/polling this session.
+ */
+ void setConnected() {
+ if (!isCreated()) {
+ throw new RuntimeException("Trying to open a non created session");
+ }
+
+ state = SessionState.CONNECTED;
+
+ /*if (connectFuture != null) {
+ connectFuture.complete(this);
+ connectFuture = null; // free some memory
+ }*/
+
+ processSessionOpen();
+ }
+
+ @Override
+ public void ready(boolean accept, boolean connect, boolean read, ByteBuffer readBuffer, boolean write) {
+ }
}
[2/5] git commit: o Removed some final keyword o Implemented the
first part of the NioUdpServer : handling new session
Posted by el...@apache.org.
o Removed some final keyword
o Implemented the first part of the NioUdpServer : handling new session
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/6426f182
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/6426f182
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/6426f182
Branch: refs/heads/trunk
Commit: 6426f182d8092d925864f8a76e7d170f82c66e46
Parents: 02f02e7
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Fri Mar 22 14:04:48 2013 +0100
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Fri Mar 22 14:04:48 2013 +0100
----------------------------------------------------------------------
.../apache/mina/transport/nio/NioTcpServer.java | 24 ++--
.../apache/mina/transport/nio/NioUdpServer.java | 122 ++++++++-------
2 files changed, 80 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/6426f182/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java b/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
index 97601dd..46e7931 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioTcpServer.java
@@ -260,11 +260,11 @@ public class NioTcpServer extends AbstractTcpServer implements SelectorListener
}
}
- private void createSession(final SocketChannel clientSocket) throws IOException {
+ private void createSession(SocketChannel clientSocket) throws IOException {
LOG.debug("create session");
- final SocketChannel socketChannel = clientSocket;
- final TcpSessionConfig config = getSessionConfig();
- final SelectorLoop readWriteSelectorLoop = readWriteSelectorPool.getSelectorLoop();
+ SocketChannel socketChannel = clientSocket;
+ TcpSessionConfig config = getSessionConfig();
+ SelectorLoop readWriteSelectorLoop = readWriteSelectorPool.getSelectorLoop();
final NioTcpSession session = new NioTcpSession(this, socketChannel, readWriteSelectorLoop, idleChecker);
socketChannel.configureBlocking(false);
@@ -275,49 +275,49 @@ public class NioTcpServer extends AbstractTcpServer implements SelectorListener
config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
// apply the default service socket configuration
- final Boolean keepAlive = config.isKeepAlive();
+ Boolean keepAlive = config.isKeepAlive();
if (keepAlive != null) {
session.getConfig().setKeepAlive(keepAlive);
}
- final Boolean oobInline = config.isOobInline();
+ Boolean oobInline = config.isOobInline();
if (oobInline != null) {
session.getConfig().setOobInline(oobInline);
}
- final Boolean reuseAddress = config.isReuseAddress();
+ Boolean reuseAddress = config.isReuseAddress();
if (reuseAddress != null) {
session.getConfig().setReuseAddress(reuseAddress);
}
- final Boolean tcpNoDelay = config.isTcpNoDelay();
+ Boolean tcpNoDelay = config.isTcpNoDelay();
if (tcpNoDelay != null) {
session.getConfig().setTcpNoDelay(tcpNoDelay);
}
- final Integer receiveBufferSize = config.getReadBufferSize();
+ Integer receiveBufferSize = config.getReadBufferSize();
if (receiveBufferSize != null) {
session.getConfig().setReadBufferSize(receiveBufferSize);
}
- final Integer sendBufferSize = config.getSendBufferSize();
+ Integer sendBufferSize = config.getSendBufferSize();
if (sendBufferSize != null) {
session.getConfig().setSendBufferSize(sendBufferSize);
}
- final Integer trafficClass = config.getTrafficClass();
+ Integer trafficClass = config.getTrafficClass();
if (trafficClass != null) {
session.getConfig().setTrafficClass(trafficClass);
}
- final Integer soLinger = config.getSoLinger();
+ Integer soLinger = config.getSoLinger();
if (soLinger != null) {
session.getConfig().setSoLinger(soLinger);
http://git-wip-us.apache.org/repos/asf/mina/blob/6426f182/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java b/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
index 2366e1a..9390bf5 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioUdpServer.java
@@ -28,6 +28,7 @@ import java.nio.channels.SelectionKey;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.mina.api.IdleStatus;
import org.apache.mina.service.executor.IoHandlerExecutor;
import org.apache.mina.service.executor.OrderedHandlerExecutor;
import org.apache.mina.service.idlechecker.IdleChecker;
@@ -64,19 +65,15 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
// list of all the sessions by remote socket address
private final Map<SocketAddress /* remote socket address */, NioUdpSession> sessions = new ConcurrentHashMap<SocketAddress, NioUdpSession>();
- /** The selector loop used to accept incoming connection */
- private final SelectorLoop acceptSelectorLoop;
-
- /** The read/write selectorPool */
- private final SelectorLoopPool readWriteSelectorPool;
+ /** The selector loop used to incoming data */
+ private final SelectorLoop readSelectorLoop;
/**
* Create an UDP server with a new selector pool of default size and a {@link IoHandlerExecutor} of default type (
* {@link OrderedHandlerExecutor})
*/
public NioUdpServer() {
- this(new NioSelectorLoop("accept", 0), new FixedSelectorLoopPool("Server", Runtime.getRuntime()
- .availableProcessors() + 1), null);
+ this(new NioSelectorLoop("accept", 0), null);
}
/**
@@ -86,37 +83,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
* @param sessionConfig The configuration to use for this server
*/
public NioUdpServer(UdpSessionConfig config) {
- this(config, new NioSelectorLoop("accept", 0), new FixedSelectorLoopPool("Server", Runtime.getRuntime()
- .availableProcessors() + 1), null);
- }
-
- /**
- * Create a UDP server with provided selector loops pool. We will use one SelectorLoop get from the pool to manage
- * the OP_ACCEPT events. If the pool contains only one SelectorLoop, then all the events will be managed by the same
- * Selector.
- *
- * @param selectorLoopPool the selector loop pool for handling all I/O events (accept, read, write)
- * @param ioHandlerExecutor used for executing IoHandler event in another pool of thread (not in the low level I/O
- * one). Use <code>null</code> if you don't want one. Be careful, the IoHandler processing will block the I/O
- * operations.
- */
- public NioUdpServer(SelectorLoopPool selectorLoopPool, IoHandlerExecutor handlerExecutor) {
- this(selectorLoopPool.getSelectorLoop(), selectorLoopPool, handlerExecutor);
- }
-
- /**
- * Create a UDP server with provided selector loops pool. We will use one SelectorLoop get from the pool to manage
- * the OP_ACCEPT events. If the pool contains only one SelectorLoop, then all the events will be managed by the same
- * Selector.
- *
- * @param sessionConfig The configuration to use for this server
- * @param selectorLoopPool the selector loop pool for handling all I/O events (accept, read, write)
- * @param ioHandlerExecutor used for executing IoHandler event in another pool of thread (not in the low level I/O
- * one). Use <code>null</code> if you don't want one. Be careful, the IoHandler processing will block the I/O
- * operations.
- */
- public NioUdpServer(UdpSessionConfig config, SelectorLoopPool selectorLoopPool, IoHandlerExecutor handlerExecutor) {
- this(config, selectorLoopPool.getSelectorLoop(), selectorLoopPool, handlerExecutor);
+ this(config, new NioSelectorLoop("accept", 0), null);
}
/**
@@ -128,11 +95,9 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
* one). Use <code>null</code> if you don't want one. Be careful, the IoHandler processing will block the I/O
* operations.
*/
- public NioUdpServer(SelectorLoop acceptSelectorLoop, SelectorLoopPool readWriteSelectorLoop,
- IoHandlerExecutor handlerExecutor) {
+ public NioUdpServer(SelectorLoop readSelectorLoop, IoHandlerExecutor handlerExecutor) {
super(handlerExecutor);
- this.acceptSelectorLoop = acceptSelectorLoop;
- this.readWriteSelectorPool = readWriteSelectorLoop;
+ this.readSelectorLoop = readSelectorLoop;
}
/**
@@ -140,16 +105,13 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
*
* @param sessionConfig The configuration to use for this server
* @param acceptSelectorLoop the selector loop for handling accept events (connection of new session)
- * @param readWriteSelectorLoop the pool of selector loop for handling read/write events of connected sessions
* @param ioHandlerExecutor used for executing IoHandler event in another pool of thread (not in the low level I/O
* one). Use <code>null</code> if you don't want one. Be careful, the IoHandler processing will block the I/O
* operations.
*/
- public NioUdpServer(UdpSessionConfig config, SelectorLoop acceptSelectorLoop,
- SelectorLoopPool readWriteSelectorLoop, IoHandlerExecutor handlerExecutor) {
+ public NioUdpServer(UdpSessionConfig config, SelectorLoop readSelectorLoop, IoHandlerExecutor handlerExecutor) {
super(config, handlerExecutor);
- this.acceptSelectorLoop = acceptSelectorLoop;
- this.readWriteSelectorPool = readWriteSelectorLoop;
+ this.readSelectorLoop = readSelectorLoop;
}
/**
@@ -201,7 +163,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
datagramChannel.socket().bind(address);
datagramChannel.configureBlocking(false);
- acceptSelectorLoop.register(false, false, true, false, this, datagramChannel, null);
+ readSelectorLoop.register(false, false, true, false, this, datagramChannel, null);
// it's the first address bound, let's fire the event
this.fireServiceActivated();
@@ -217,7 +179,7 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
throw new IllegalStateException("server not bound");
}
- acceptSelectorLoop.unregister(this, datagramChannel);
+ readSelectorLoop.unregister(this, datagramChannel);
datagramChannel.socket().close();
datagramChannel.close();
@@ -256,14 +218,17 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
LOG.debug("read {} bytes form {}", readBuffer.remaining(), source);
// let's find the corresponding session
+ if (source != null) {
+ NioUdpSession session = sessions.get(source);
- NioUdpSession session = sessions.get(source);
+ if (session == null) {
+ //session = new NioUdpSession(this, idleChecker, address, source);
- if (session == null) {
- session = new NioUdpSession(this, idleChecker, address, source);
- }
+ session = createSession(source, datagramChannel);
+ }
- session.receivedDatagram(readBuffer);
+ session.receivedDatagram(readBuffer);
+ }
} catch (final IOException ex) {
LOG.error("IOException while reading the socket", ex);
}
@@ -273,4 +238,53 @@ public class NioUdpServer extends AbstractUdpServer implements SelectorListener
}
}
+ private NioUdpSession createSession(SocketAddress remoteAddress, DatagramChannel datagramChannel)
+ throws IOException {
+ LOG.debug("create session");
+ UdpSessionConfig config = getSessionConfig();
+ final NioUdpSession session = new NioUdpSession(this, idleChecker, datagramChannel,
+ datagramChannel.getLocalAddress(), remoteAddress);
+
+ // apply idle configuration
+ session.getConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
+ session.getConfig().setIdleTimeInMillis(IdleStatus.WRITE_IDLE,
+ config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
+
+ // apply the default service socket configuration
+
+ Boolean reuseAddress = config.isReuseAddress();
+
+ if (reuseAddress != null) {
+ session.getConfig().setReuseAddress(reuseAddress);
+ }
+
+ Integer readBufferSize = config.getReadBufferSize();
+
+ if (readBufferSize != null) {
+ session.getConfig().setReadBufferSize(readBufferSize);
+ }
+
+ Integer sendBufferSize = config.getSendBufferSize();
+
+ if (sendBufferSize != null) {
+ session.getConfig().setSendBufferSize(sendBufferSize);
+ }
+
+ Integer trafficClass = config.getTrafficClass();
+
+ if (trafficClass != null) {
+ session.getConfig().setTrafficClass(trafficClass);
+ }
+
+ // Manage the Idle status
+ idleChecker.sessionRead(session, System.currentTimeMillis());
+ idleChecker.sessionWritten(session, System.currentTimeMillis());
+
+ sessions.put(remoteAddress, session);
+
+ // Inform the handler that the session has been created
+ session.setConnected();
+
+ return session;
+ }
}
\ No newline at end of file
[5/5] git commit: o Added the Mina3_udp and Netty3_udp type o Added
the Netty3 UDP client and server classes
Posted by el...@apache.org.
o Added the Mina3_udp and Netty3_udp type
o Added the Netty3 UDP client and server classes
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/abe19430
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/abe19430
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/abe19430
Branch: refs/heads/trunk
Commit: abe19430989b3a6aa6c84570ba494f10ab74bf9d
Parents: 587f4fd
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Fri Mar 22 14:16:54 2013 +0100
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Fri Mar 22 14:16:54 2013 +0100
----------------------------------------------------------------------
.../apache/mina/core/BenchmarkClientFactory.java | 3 +++
.../apache/mina/core/BenchmarkServerFactory.java | 3 +++
.../core/nio/udp/Netty3UdpBenchmarkClient.java | 4 ++--
.../core/nio/udp/Netty3UdpBenchmarkServer.java | 4 ++--
4 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/abe19430/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
----------------------------------------------------------------------
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
index 059651a..2330b6e 100755
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
@@ -22,6 +22,7 @@ package org.apache.mina.core;
import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
/**
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
@@ -38,6 +39,8 @@ public class BenchmarkClientFactory implements BenchmarkFactory<BenchmarkClient>
return new Mina3UdpBenchmarkClient();
case Netty3_tcp:
return new Netty3TcpBenchmarkClient();
+ case Netty3_udp:
+ return new Netty3UdpBenchmarkClient();
default:
throw new IllegalArgumentException("Invalid type " + type);
}
http://git-wip-us.apache.org/repos/asf/mina/blob/abe19430/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
----------------------------------------------------------------------
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
index 6377063..e2a7015 100755
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
@@ -22,6 +22,7 @@ package org.apache.mina.core;
import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkServer;
/**
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
@@ -41,6 +42,8 @@ public class BenchmarkServerFactory implements BenchmarkFactory<BenchmarkServer>
return new Mina3UdpBenchmarkServer();
case Netty3_tcp:
return new Netty3TcpBenchmarkServer();
+ case Netty3_udp:
+ return new Netty3UdpBenchmarkServer();
default:
throw new IllegalArgumentException("Invalid type " + type);
}
http://git-wip-us.apache.org/repos/asf/mina/blob/abe19430/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkClient.java b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkClient.java
index f7637cf..14177c6 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkClient.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkClient.java
@@ -24,7 +24,7 @@ import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import org.apache.mina.core.BenchmarkClient;
-import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelFactory;
@@ -55,7 +55,7 @@ public class Netty3UdpBenchmarkClient implements BenchmarkClient {
*/
public void start(final int port, final CountDownLatch counter, final byte[] data) throws IOException {
factory = new NioDatagramChannelFactory();
- ClientBootstrap bootstrap = new ClientBootstrap(factory);
+ ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new SimpleChannelUpstreamHandler() {
http://git-wip-us.apache.org/repos/asf/mina/blob/abe19430/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
----------------------------------------------------------------------
diff --git a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
index d6d89ac..e1f41d0 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
@@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.mina.core.BenchmarkServer;
-import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelFactory;
@@ -93,7 +93,7 @@ public class Netty3UdpBenchmarkServer implements BenchmarkServer {
*/
public void start(int port) throws IOException {
factory = new NioDatagramChannelFactory();
- ServerBootstrap bootstrap = new ServerBootstrap(factory);
+ ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new SimpleChannelUpstreamHandler() {
[3/5] git commit: o Switched from Channel to SelectableChannel
Posted by el...@apache.org.
o Switched from Channel to SelectableChannel
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/799a0dc8
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/799a0dc8
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/799a0dc8
Branch: refs/heads/trunk
Commit: 799a0dc83a08e0f3a6cececb3442733a30ff3adc
Parents: 6426f18
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Fri Mar 22 14:07:16 2013 +0100
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Fri Mar 22 14:07:16 2013 +0100
----------------------------------------------------------------------
.../apache/mina/transport/nio/NioSelectorLoop.java | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/799a0dc8/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java b/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
index 4f499ac..4bd0522 100644
--- a/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
+++ b/core/src/main/java/org/apache/mina/transport/nio/NioSelectorLoop.java
@@ -133,8 +133,8 @@ public class NioSelectorLoop implements SelectorLoop {
* {@inheritDoc}
*/
@Override
- public void modifyRegistration(final boolean accept, final boolean read, final boolean write,
- final SelectorListener listener, final SelectableChannel channel, boolean wakeup) {
+ public void modifyRegistration(boolean accept, boolean read, boolean write, final SelectorListener listener,
+ SelectableChannel channel, boolean wakeup) {
logger.debug("modifying registration : {} for accept : {}, read : {}, write : {}, channel : {}", new Object[] {
listener, accept, read, write, channel });
[4/5] git commit: As the AsbtractIoServer now take a
SelectableChannel parameter, fixed the tests accordingly
Posted by el...@apache.org.
As the AsbtractIoServer now take a SelectableChannel parameter, fixed
the tests accordingly
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/587f4fd3
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/587f4fd3
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/587f4fd3
Branch: refs/heads/trunk
Commit: 587f4fd3b7e7a222d2b33f9c5843e3a77f97a261
Parents: 799a0dc
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Fri Mar 22 14:08:25 2013 +0100
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Fri Mar 22 14:08:25 2013 +0100
----------------------------------------------------------------------
.../service/idlecheker/IndexedIdleChekerTest.java | 2 +-
.../apache/mina/session/AbstractIoSessionTest.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/587f4fd3/core/src/test/java/org/apache/mina/service/idlecheker/IndexedIdleChekerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mina/service/idlecheker/IndexedIdleChekerTest.java b/core/src/test/java/org/apache/mina/service/idlecheker/IndexedIdleChekerTest.java
index 96a5a94..7cffd92 100644
--- a/core/src/test/java/org/apache/mina/service/idlecheker/IndexedIdleChekerTest.java
+++ b/core/src/test/java/org/apache/mina/service/idlecheker/IndexedIdleChekerTest.java
@@ -93,7 +93,7 @@ public class IndexedIdleChekerTest {
int writeIdleCount = 0;
private DummySession(IoService service, IdleChecker checker) {
- super(service, checker);
+ super(service, null, checker);
}
@Override
http://git-wip-us.apache.org/repos/asf/mina/blob/587f4fd3/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java b/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
index 48f6b21..c49ab9c 100644
--- a/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
+++ b/core/src/test/java/org/apache/mina/session/AbstractIoSessionTest.java
@@ -53,7 +53,7 @@ public class AbstractIoSessionTest {
private class DummySession extends AbstractIoSession {
private DummySession(final IoService service) {
- super(service, null);
+ super(service, null, null);
}
@Override