use of org.jgroups.blocks.cs.NioServer in project JGroups by belaban.
the class ServerUnitTest method create.
protected static BaseServer create(boolean nio, int port) {
try {
BaseServer retval = nio ? new NioServer(bind_addr, port).maxSendBuffers(1024) : new TcpServer(bind_addr, port);
retval.usePeerConnections(true);
retval.start();
return retval;
} catch (Exception ex) {
return null;
}
}
use of org.jgroups.blocks.cs.NioServer in project JGroups by belaban.
the class NioServerTest method init.
@BeforeMethod
protected void init() throws Exception {
srv = new NioServer(Util.getLoopback(), 0);
srv.sendBufferSize(send_buf_size).receiveBufferSize(recv_buf_size);
srv.start();
client = new NioClient(null, 0, Util.getLoopback(), ((IpAddress) srv.localAddress()).getPort());
client.sendBufferSize(send_buf_size).receiveBufferSize(recv_buf_size);
client.maxSendBuffers(1000);
client.start();
for (int i = 0; i < senders.length; i++) {
senders[i] = new Sender(counter, latch, client);
senders[i].start();
}
}
use of org.jgroups.blocks.cs.NioServer in project JGroups by belaban.
the class ServerUnitTest method testAsyncConnectThenSend.
public void testAsyncConnectThenSend() throws Exception {
try (NioServer a = (NioServer) create(true, 0);
NioServer b = (NioServer) create(true, 0)) {
a.start();
b.start();
Address target = b.localAddress();
MyReceiver r = new MyReceiver(b, 2, false);
b.receiver(r);
// now send 2 msgs from A to B: this will connect async, buffer the 2 msgs, then send when connected
byte[] buffer = "hello world".getBytes();
send(buffer, a, target);
send(buffer, a, target);
r.waitForCompletion(20000);
assert r.getNumReceived() == 2;
}
}
use of org.jgroups.blocks.cs.NioServer in project JGroups by belaban.
the class TCP_NIO2 method start.
public void start() throws Exception {
server = new NioServer(getThreadFactory(), getSocketFactory(), bind_addr, bind_port, bind_port + port_range, external_addr, external_port, recv_buf_size);
server.receiver(this).timeService(time_service).socketConnectionTimeout(sock_conn_timeout).tcpNodelay(tcp_nodelay).linger(linger).clientBindAddress(client_bind_addr).clientBindPort(client_bind_port).deferClientBinding(defer_client_bind_addr).log(this.log).logDetails(log_details);
server.maxSendBuffers(max_send_buffers).usePeerConnections(true);
server.copyOnPartialWrite(this.copy_on_partial_write).readerIdleTime(this.reader_idle_time);
if (send_buf_size > 0)
server.sendBufferSize(send_buf_size);
if (recv_buf_size > 0)
server.receiveBufferSize(recv_buf_size);
if (reaper_interval > 0 || conn_expire_time > 0) {
if (reaper_interval == 0) {
reaper_interval = 5000;
log.warn("reaper_interval was 0, set it to %d", reaper_interval);
}
if (conn_expire_time == 0) {
conn_expire_time = (long) 1000 * 60 * 5;
log.warn("conn_expire_time was 0, set it to %d", conn_expire_time);
}
server.connExpireTimeout(conn_expire_time).reaperInterval(reaper_interval);
}
if (max_length > 0)
server.setMaxLength(max_length);
super.start();
}
Aggregations