use of org.apache.ignite.internal.util.nio.GridNioParser in project ignite by apache.
the class GridTcpRestProtocol method start.
/** {@inheritDoc} */
@SuppressWarnings("BusyWait")
@Override
public void start(final GridRestProtocolHandler hnd) throws IgniteCheckedException {
assert hnd != null;
ConnectorConfiguration cfg = ctx.config().getConnectorConfiguration();
assert cfg != null;
lsnr = new GridTcpRestNioListener(log, this, hnd, ctx);
GridNioParser parser = new GridTcpRestParser(false);
try {
host = resolveRestTcpHost(ctx.config());
SSLContext sslCtx = null;
if (cfg.isSslEnabled()) {
Factory<SSLContext> igniteFactory = ctx.config().getSslContextFactory();
Factory<SSLContext> factory = cfg.getSslFactory();
// This factory deprecated and will be removed.
GridSslContextFactory depFactory = cfg.getSslContextFactory();
if (factory == null && depFactory == null && igniteFactory == null)
// Thrown SSL exception instead of IgniteCheckedException for writing correct warning message into log.
throw new SSLException("SSL is enabled, but SSL context factory is not specified.");
if (factory != null)
sslCtx = factory.create();
else if (depFactory != null)
sslCtx = depFactory.createSslContext();
else
sslCtx = igniteFactory.create();
}
int startPort = cfg.getPort();
int portRange = cfg.getPortRange();
int lastPort = portRange == 0 ? startPort : startPort + portRange - 1;
for (int port0 = startPort; port0 <= lastPort; port0++) {
if (startTcpServer(host, port0, lsnr, parser, sslCtx, cfg)) {
port = port0;
if (log.isInfoEnabled())
log.info(startInfo());
return;
}
}
U.warn(log, "Failed to start TCP binary REST server (possibly all ports in range are in use) " + "[firstPort=" + cfg.getPort() + ", lastPort=" + lastPort + ", host=" + host + ']');
} catch (SSLException e) {
U.warn(log, "Failed to start " + name() + " protocol on port " + port + ": " + e.getMessage(), "Failed to start " + name() + " protocol on port " + port + ". Check if SSL context factory is " + "properly configured.");
} catch (IOException e) {
U.warn(log, "Failed to start " + name() + " protocol on port " + port + ": " + e.getMessage(), "Failed to start " + name() + " protocol on port " + port + ". " + "Check restTcpHost configuration property.");
}
}
use of org.apache.ignite.internal.util.nio.GridNioParser 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