package net.home;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetServerOptions;
import io.vertx.core.net.SocketAddress;
import net.home.vertxLogger.LogRecord;
import net.home.vertxLogger.ParserHandler;
public class AsyncLogger extends AbstractVerticle{
private NetServer socketListener;
private int buffersRecv = 0;
private int bytesRecv = 0;
@Override
public void start() throws Exception {
int port = 11112;
NetServerOptions opts = new NetServerOptions().setPort(port).setHost("localhost");
socketListener = vertx.createNetServer(opts);
// setup the handler
socketListener.connectHandler(socket ->
{
SocketAddress address = socket.remoteAddress();
System.out.println("connection from: " + address.toString());
socket.handler(buffer -> {
// do something
buffersRecv += 1;
bytesRecv += buffer.length();
if (buffersRecv % 100000 == 0)
{
System.out.println("got 1k buffers, total bytes: " + bytesRecv);
Future<Void> resetFuture = Future.future();
resetFuture.setHandler(rf -> {
System.out.println("reset");
bytesRecv = 0;
});
resetFuture.complete();
}
});
socket.closeHandler( closeHandler -> {
});
});
// tell it to listen
socketListener.listen(res -> {
if (res.succeeded()) {
System.out.println("Server is now listening");
} else {
System.out.println("failed to listen");
}
});
}
}