use of org.apache.ignite.internal.util.nio.GridBufferedParser in project ignite by apache.
the class SocketStreamer method start.
/**
* Starts streamer.
*
* @throws IgniteException If failed.
*/
public void start() {
A.ensure(getSingleTupleExtractor() != null || getMultipleTupleExtractor() != null, "tupleExtractor (single or multiple)");
A.notNull(getStreamer(), "streamer");
A.notNull(getIgnite(), "ignite");
A.ensure(threads > 0, "threads > 0");
log = getIgnite().log();
GridNioServerListener<byte[]> lsnr = new GridNioServerListenerAdapter<byte[]>() {
@Override
public void onConnected(GridNioSession ses) {
assert ses.accepted();
if (log.isDebugEnabled())
log.debug("Accepted connection: " + ses.remoteAddress());
}
@Override
public void onDisconnected(GridNioSession ses, @Nullable Exception e) {
if (e != null)
log.error("Connection failed with exception", e);
}
@Override
public void onMessage(GridNioSession ses, byte[] msg) {
addMessage(converter.convert(msg));
}
};
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
GridNioParser parser = F.isEmpty(delim) ? new GridBufferedParser(directMode, byteOrder) : new GridDelimitedParser(delim, directMode);
if (converter == null)
converter = new DefaultConverter<>(getIgnite().name());
GridNioFilter codec = new GridNioCodecFilter(parser, log, directMode);
GridNioFilter[] filters = new GridNioFilter[] { codec };
try {
srv = new GridNioServer.Builder<byte[]>().address(addr == null ? InetAddress.getLocalHost() : addr).serverName("sock-streamer").port(port).listener(lsnr).logger(log).selectorCount(threads).byteOrder(byteOrder).filters(filters).build();
} catch (IgniteCheckedException | UnknownHostException e) {
throw new IgniteException(e);
}
srv.start();
if (log.isDebugEnabled())
log.debug("Socket streaming server started on " + addr + ':' + port);
}
Aggregations