Skip to content

Commit

Permalink
Merge pull request #424 from evgeny-pasynkov/master
Browse files Browse the repository at this point in the history
Create Nio2Session using Nio2ServiceFactory
  • Loading branch information
tomaswolf authored Oct 14, 2023
2 parents 76ae2bd + 32ed7c2 commit e023eb7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@
*/
public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
protected final Map<SocketAddress, AsynchronousServerSocketChannel> channels = new ConcurrentHashMap<>();
private final Nio2ServiceFactory nio2ServiceFactory;
private int backlog;

public Nio2Acceptor(PropertyResolver propertyResolver, IoHandler handler, AsynchronousChannelGroup group,
public Nio2Acceptor(Nio2ServiceFactory nio2ServiceFactory, PropertyResolver propertyResolver, IoHandler handler, AsynchronousChannelGroup group,
ExecutorService resumeTasks) {
super(propertyResolver, handler, group, resumeTasks);
this.nio2ServiceFactory = nio2ServiceFactory;
backlog = CoreModuleProperties.SOCKET_BACKLOG.getRequired(propertyResolver);
}

Expand Down Expand Up @@ -354,7 +356,7 @@ protected Nio2Session createSession(
if (log.isTraceEnabled()) {
log.trace("createNio2Session({}) address={}", acceptor, address);
}
return new Nio2Session(acceptor, propertyResolver, handler, channel, address);
return nio2ServiceFactory.createSession(acceptor, handler, channel, address);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class Nio2Connector extends Nio2Service implements IoConnector {
public Nio2Connector(PropertyResolver propertyResolver, IoHandler handler, AsynchronousChannelGroup group,
private final Nio2ServiceFactory nio2ServiceFactory;

public Nio2Connector(Nio2ServiceFactory nio2ServiceFactory, PropertyResolver propertyResolver, IoHandler handler, AsynchronousChannelGroup group,
ExecutorService resumeTasks) {
super(propertyResolver, handler, group, resumeTasks);
this.nio2ServiceFactory = nio2ServiceFactory;
}

@Override
Expand Down Expand Up @@ -276,7 +279,6 @@ protected void onFailed(Throwable exc, Object attachment) {
protected Nio2Session createSession(
PropertyResolver propertyResolver, IoHandler handler, AsynchronousSocketChannel socket)
throws Throwable {
return new Nio2Session(this, propertyResolver, handler, socket, null);
return nio2ServiceFactory.createSession(this, handler, socket, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.apache.sshd.common.io.nio2;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.TimeUnit;

import org.apache.sshd.common.FactoryManager;
Expand Down Expand Up @@ -56,12 +58,18 @@ public Nio2ServiceFactory(FactoryManager factoryManager, CloseableExecutorServic

@Override
public IoConnector createConnector(IoHandler handler) {
return autowireCreatedService(new Nio2Connector(getFactoryManager(), handler, group, resuming));
return autowireCreatedService(new Nio2Connector(this, getFactoryManager(), handler, group, resuming));
}

@Override
public IoAcceptor createAcceptor(IoHandler handler) {
return autowireCreatedService(new Nio2Acceptor(getFactoryManager(), handler, group, resuming));
return autowireCreatedService(new Nio2Acceptor(this, getFactoryManager(), handler, group, resuming));
}

public Nio2Session createSession(
Nio2Service service, IoHandler handler, AsynchronousSocketChannel socket, SocketAddress address)
throws Throwable {
return new Nio2Session(service, getFactoryManager(), handler, socket, address);
}

@Override
Expand Down

0 comments on commit e023eb7

Please sign in to comment.