}
return bm;
}
private NetServer setServer(int port, final String hostName, final AsyncResultHandler<Void> listenHandler) {
final NetServer server = vertx.createNetServer().connectHandler(new Handler<NetSocket>() {
public void handle(final NetSocket socket) {
final RecordParser parser = RecordParser.newFixed(4, null);
Handler<Buffer> handler = new Handler<Buffer>() {
int size = -1;
public void handle(Buffer buff) {
if (size == -1) {
size = buff.getInt(0);
parser.fixedSizeMode(size);
} else {
BaseMessage received = MessageFactory.read(buff);
if (received.type() == MessageFactory.TYPE_PING) {
// Send back a pong - a byte will do
socket.write(PONG);
} else {
receiveMessage(received);
}
parser.fixedSizeMode(4);
size = -1;
}
}
};
parser.setOutput(handler);
socket.dataHandler(parser);
}
});
server.listen(port, hostName, new AsyncResultHandler<NetServer>() {
@Override
public void handle(AsyncResult<NetServer> asyncResult) {
if (asyncResult.succeeded()) {
// If using a wilcard port (0) then we ask the server for the actual port:
DefaultEventBus.this.serverID = new ServerID(server.port(), hostName);
}
if (listenHandler != null) {
if (asyncResult.succeeded()) {
listenHandler.handle(new DefaultFutureResult<>((Void)null));
} else {