This commit is contained in:
@@ -12,6 +12,7 @@ import java.nio.channels.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import org.redkale.util.AnyValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议底层Server
|
* 协议底层Server
|
||||||
@@ -53,7 +54,7 @@ public abstract class ProtocolServer {
|
|||||||
//最大连接数,小于1表示无限制
|
//最大连接数,小于1表示无限制
|
||||||
protected int maxconns;
|
protected int maxconns;
|
||||||
|
|
||||||
public abstract void open() throws IOException;
|
public abstract void open(AnyValue config) throws IOException;
|
||||||
|
|
||||||
public abstract void bind(SocketAddress local, int backlog) throws IOException;
|
public abstract void bind(SocketAddress local, int backlog) throws IOException;
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ public abstract class ProtocolServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open() throws IOException {
|
public void open(AnyValue config) throws IOException {
|
||||||
DatagramChannel ch = DatagramChannel.open();
|
DatagramChannel ch = DatagramChannel.open();
|
||||||
ch.configureBlocking(true);
|
ch.configureBlocking(true);
|
||||||
this.serverChannel = ch;
|
this.serverChannel = ch;
|
||||||
@@ -203,14 +204,9 @@ public abstract class ProtocolServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open() throws IOException {
|
public void open(AnyValue config) throws IOException {
|
||||||
group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1);
|
group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1);
|
||||||
this.serverChannel = AsynchronousServerSocketChannel.open(group);
|
this.serverChannel = AsynchronousServerSocketChannel.open(group);
|
||||||
try {
|
|
||||||
if (supportTcpNoDelay()) this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
|
||||||
if (supportTcpKeepAlive()) this.serverChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -225,10 +225,13 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
this.context = this.createContext();
|
this.context = this.createContext();
|
||||||
this.prepare.init(this.context, config);
|
this.prepare.init(this.context, config);
|
||||||
this.serverChannel = ProtocolServer.create(this.protocol, context);
|
this.serverChannel = ProtocolServer.create(this.protocol, context);
|
||||||
this.serverChannel.open();
|
this.serverChannel.open(config);
|
||||||
if (this.serverChannel.supportedOptions().contains(StandardSocketOptions.TCP_NODELAY)) {
|
if (this.serverChannel.supportedOptions().contains(StandardSocketOptions.TCP_NODELAY)) {
|
||||||
this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||||
}
|
}
|
||||||
|
if (this.serverChannel.supportedOptions().contains(StandardSocketOptions.SO_KEEPALIVE)) {
|
||||||
|
this.serverChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
|
||||||
|
}
|
||||||
serverChannel.bind(address, backlog);
|
serverChannel.bind(address, backlog);
|
||||||
serverChannel.setMaxconns(this.maxconns);
|
serverChannel.setMaxconns(this.maxconns);
|
||||||
serverChannel.accept();
|
serverChannel.accept();
|
||||||
|
|||||||
Reference in New Issue
Block a user