Hi Johan,
You didn’t start the executor service of the idleTimeoutFilter:
SessionTimeoutHandler timeoutHandler = new SessionTimeoutHandler(ConnectionEventType.START_POINT_CONNECTION_TIMED_OUT);
DelayedExecutor delayedExecutor = IdleTimeoutFilter.createDefaultIdleDelayedExecutor();
delayedExecutor.start();
// Keep it
mTimeoutFilterDelayedExecutorsMap.put(aSecurityLevel,delayedExecutor);
return new IdleTimeoutFilter(delayedExecutor,obtainConnectionTimeoutInMs(),TimeUnit.MILLISECONDS,timeoutHandler);
Don’t forget to stop it upon application termination.
Tiran Meltser
System Architect
Global Products & Operations
Comverse – Making Your Network Smarter
T +972-3-7678381
M +972-54-5639381
Tiran.Meltser_at_comverse.com <mailto:Tiran.Meltser_at_comverse.com>
www.comverse.com<
http://www.comverse.com/>
P Please think of the environment before printing this email
From: Johan Maasing [mailto:johan_at_zoom.nu]
Sent: Thursday, June 05, 2014 2:23 PM
To: users_at_grizzly.java.net
Subject: How to handle server that does not respond
I hope someone can help me understand how to handle servers that does not respond in time. I thought that maybe IdleTimeoutFilter would handle this but I don't see the connection close after the specified time. Am I misunderstanding what the Idle/ActivityCheck filters are supposed to do? What would be the correct way to set up the filters (or use something else) to give up on the connection after a while if the server does not respond?
This is my test-client (using 2.3.13):
public class TimeoutClient {
private TCPNIOTransport transport;
private static final long TIMEOUT_IN_MILLIS = 2000 ;
public static void main(String... args) throws IOException, InterruptedException {
TimeoutClient app = new TimeoutClient();
app.startup();
app.run();
}
private void run() throws InterruptedException {
Thread clientThread = new Thread(() -> {
final GrizzlyFuture<Connection> connectionGrizzlyFuture = transport.connect("127.0.0.1", 5431);
try {
final Connection connection = connectionGrizzlyFuture.get();
connection.write("");
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
);
clientThread.start();
Thread.sleep(TIMEOUT_IN_MILLIS * 10);
}
private void startup() throws IOException {
FilterChainBuilder clientFilterChainBuilder = FilterChainBuilder.stateless();
clientFilterChainBuilder.add(new TransportFilter());
clientFilterChainBuilder.add(new IdleTimeoutFilter(IdleTimeoutFilter.createDefaultIdleDelayedExecutor(), TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS));
clientFilterChainBuilder.add(new LogFilter());
clientFilterChainBuilder.add(new StringFilter(Charsets.UTF8_CHARSET));
transport = TCPNIOTransportBuilder.newInstance().build();
transport.setProcessor(clientFilterChainBuilder.build());
transport.start();
}
}
My test server is simply this:
public class DiscardServer {
boolean keepRunning = true;
public static void main(String[] args) throws Exception {
DiscardServer app = new DiscardServer();
app.run();
}
private void run() throws IOException {
ServerSocket ss = new ServerSocket(5431);
while (keepRunning) {
final Socket socket = ss.accept();
log("Server accepted a connection");
Thread clientThread = new Thread(new Runnable() {
@Override
public void run() {
try {
try {
log("Will sleep for a while") ;
Thread.sleep(20000);
} catch (InterruptedException e) {
keepRunning = false;
}
log("Closing socket") ;
socket.close();
} catch (IOException e) {
e.printStackTrace();
keepRunning = false;
}
}
});
clientThread.start();
}
}
private void log(final String msg) {
System.out.println(System.currentTimeMillis() + " : " + msg);
}
}
Cheers,
Johan
________________________________
“This e-mail message may contain confidential, commercial or privileged information that constitutes proprietary information of Comverse Inc. or its subsidiaries. If you are not the intended recipient of this message, you are hereby notified that any review, use or distribution of this information is absolutely prohibited and we request that you delete all copies and contact us by e-mailing to: security_at_comverse.com. Thank You.”