use of org.apache.ignite.spi.IgniteSpiThread in project ignite by apache.
the class ServerImpl method threads.
/**
* {@inheritDoc}
*/
@Override
protected Collection<IgniteSpiThread> threads() {
Collection<IgniteSpiThread> threads;
synchronized (mux) {
threads = new ArrayList<>(readers.size() + clientMsgWorkers.size() + 4);
threads.addAll(readers);
}
for (ClientMessageWorker wrk : clientMsgWorkers.values()) {
Thread t = wrk.runner();
assert t instanceof IgniteSpiThread;
threads.add((IgniteSpiThread) t);
}
TcpServer tcpSrvr0 = tcpSrvr;
if (tcpSrvr0 != null) {
Thread tcpSrvThread = tcpSrvr0.runner();
if (tcpSrvThread != null) {
assert tcpSrvThread instanceof IgniteSpiThread;
threads.add((IgniteSpiThread) tcpSrvThread);
}
}
threads.add(ipFinderCleaner);
Thread msgWorkerThread = msgWorker.runner();
if (msgWorkerThread != null) {
assert msgWorkerThread instanceof IgniteSpiThread;
threads.add((IgniteSpiThread) msgWorkerThread);
}
threads.add(statsPrinter);
threads.removeAll(Collections.<IgniteSpiThread>singleton(null));
return threads;
}
use of org.apache.ignite.spi.IgniteSpiThread in project ignite by apache.
the class ClientImpl method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
spi.initLocalNode(0, true);
locNode = spi.locNode;
// Marshal credentials for backward compatibility and security.
marshalCredentials(locNode);
sockWriter = new SocketWriter();
sockWriter.start();
sockReader = new SocketReader();
sockReader.start();
if (spi.ipFinder.isShared() && spi.isForceServerMode())
registerLocalNodeAddress();
msgWorker = new MessageWorker(log);
new IgniteSpiThread(msgWorker.igniteInstanceName(), msgWorker.name(), log) {
@Override
protected void body() {
msgWorker.run();
}
}.start();
executorService.scheduleAtFixedRate(new MetricsSender(), spi.metricsUpdateFreq, spi.metricsUpdateFreq, MILLISECONDS);
try {
joinLatch.await();
IgniteSpiException err = joinErr.get();
if (err != null)
throw err;
} catch (InterruptedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
spi.printStartInfo();
}
use of org.apache.ignite.spi.IgniteSpiThread in project ignite by apache.
the class TcpCommunicationSpi method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
final Function<UUID, ClusterNode> nodeGetter = (nodeId) -> getSpiContext().node(nodeId);
final Supplier<ClusterNode> locNodeSupplier = () -> getSpiContext().localNode();
final Supplier<Ignite> igniteExSupplier = this::ignite;
final Function<UUID, Boolean> pingNode = (nodeId) -> getSpiContext().pingNode(nodeId);
final Supplier<FailureProcessor> failureProcessorSupplier = () -> ignite instanceof IgniteEx ? ((IgniteEx) ignite).context().failure() : null;
final Supplier<Boolean> isStopped = () -> getSpiContext().isStopping();
this.igniteInstanceName = igniteInstanceName;
cfg.failureDetectionTimeout(ignite.configuration().getFailureDetectionTimeout());
attributeNames = new AttributeNames(createSpiAttributeName(ATTR_PAIRED_CONN), createSpiAttributeName(ATTR_ADDRS), createSpiAttributeName(ATTR_HOST_NAMES), createSpiAttributeName(ATTR_EXT_ADDRS), createSpiAttributeName(ATTR_PORT), createSpiAttributeName(ATTR_FORCE_CLIENT_SERVER_CONNECTIONS));
boolean client = Boolean.TRUE.equals(ignite().configuration().isClientMode());
this.stateProvider = new ClusterStateProvider(ignite, locNodeSupplier, this, isStopped, () -> super.getSpiContext(), log, igniteExSupplier);
try {
cfg.localHost(U.resolveLocalHost(cfg.localAddress()));
} catch (IOException e) {
throw new IgniteSpiException("Failed to initialize local address: " + cfg.localAddress(), e);
}
if (cfg.connectionsPerNode() > 1)
connPlc = new RoundRobinConnectionPolicy(cfg);
else
connPlc = new FirstConnectionPolicy();
this.srvLsnr = resolve(ignite, new InboundConnectionHandler(log, cfg, nodeGetter, locNodeSupplier, stateProvider, clientPool, commWorker, connectGate, failureProcessorSupplier, attributeNames, metricsLsnr, nioSrvWrapper, ctxInitLatch, client, igniteExSupplier, new CommunicationListener<Message>() {
@Override
public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
notifyListener(nodeId, msg, msgC);
}
@Override
public void onDisconnected(UUID nodeId) {
if (lsnr != null)
lsnr.onDisconnected(nodeId);
}
}));
TcpHandshakeExecutor tcpHandshakeExecutor = resolve(ignite, new TcpHandshakeExecutor(log, stateProvider, cfg.directBuffer()));
this.nioSrvWrapper = resolve(ignite, new GridNioServerWrapper(log, cfg, attributeNames, tracing, nodeGetter, locNodeSupplier, connectGate, stateProvider, this::getExceptionRegistry, commWorker, ignite.configuration(), this.srvLsnr, getName(), getWorkersRegistry(ignite), ignite instanceof IgniteEx ? ((IgniteEx) ignite).context().metric() : null, this::createTcpClient, new CommunicationListenerEx<Message>() {
@Override
public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
notifyListener(nodeId, msg, msgC);
}
@Override
public void onDisconnected(UUID nodeId) {
if (lsnr != null)
lsnr.onDisconnected(nodeId);
}
@Override
public void onChannelOpened(UUID rmtNodeId, Message initMsg, Channel channel) {
if (lsnr instanceof CommunicationListenerEx)
((CommunicationListenerEx<Message>) lsnr).onChannelOpened(rmtNodeId, initMsg, channel);
}
}, tcpHandshakeExecutor));
this.srvLsnr.setNioSrvWrapper(nioSrvWrapper);
this.clientPool = resolve(ignite, new ConnectionClientPool(cfg, attributeNames, log, metricsLsnr, locNodeSupplier, nodeGetter, null, getWorkersRegistry(ignite), this, stateProvider, nioSrvWrapper, getName()));
this.srvLsnr.setClientPool(clientPool);
nioSrvWrapper.clientPool(clientPool);
discoLsnr = new CommunicationDiscoveryEventListener(clientPool, metricsLsnr);
try {
// This method potentially resets local port to the value
// local node was bound to.
nioSrvWrapper.nio(nioSrvWrapper.resetNioServer());
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to initialize TCP server: " + cfg.localHost(), e);
}
boolean forceClientToSrvConnections = forceClientToServerConnections() || cfg.localPort() == -1;
if (cfg.usePairedConnections() && forceClientToSrvConnections) {
throw new IgniteSpiException("Node using paired connections " + "is not allowed to start in forced client to server connections mode.");
}
assert cfg.localHost() != null;
// Start SPI start stopwatch.
startStopwatch();
if (log.isDebugEnabled()) {
log.debug(configInfo("locAddr", cfg.localAddress()));
log.debug(configInfo("locPort", cfg.localPort()));
log.debug(configInfo("locPortRange", cfg.localPortRange()));
log.debug(configInfo("idleConnTimeout", cfg.idleConnectionTimeout()));
log.debug(configInfo("directBuf", cfg.directBuffer()));
log.debug(configInfo("directSendBuf", cfg.directSendBuffer()));
log.debug(configInfo("selectorsCnt", cfg.selectorsCount()));
log.debug(configInfo("tcpNoDelay", cfg.tcpNoDelay()));
log.debug(configInfo("sockSndBuf", cfg.socketSendBuffer()));
log.debug(configInfo("sockRcvBuf", cfg.socketReceiveBuffer()));
log.debug(configInfo("msgQueueLimit", cfg.messageQueueLimit()));
log.debug(configInfo("connectionsPerNode", cfg.connectionsPerNode()));
if (failureDetectionTimeoutEnabled()) {
log.debug(configInfo("connTimeout", cfg.connectionTimeout()));
log.debug(configInfo("maxConnTimeout", cfg.maxConnectionTimeout()));
log.debug(configInfo("reconCnt", cfg.reconCount()));
} else
log.debug(configInfo("failureDetectionTimeout", failureDetectionTimeout()));
log.debug(configInfo("sockWriteTimeout", cfg.socketWriteTimeout()));
log.debug(configInfo("ackSndThreshold", cfg.ackSendThreshold()));
log.debug(configInfo("unackedMsgsBufSize", cfg.unackedMsgsBufferSize()));
}
if (!cfg.tcpNoDelay())
U.quietAndWarn(log, "'TCP_NO_DELAY' for communication is off, which should be used with caution " + "since may produce significant delays with some scenarios.");
if (cfg.slowClientQueueLimit() > 0 && cfg.messageQueueLimit() > 0 && cfg.slowClientQueueLimit() >= cfg.messageQueueLimit()) {
U.quietAndWarn(log, "Slow client queue limit is set to a value greater than or equal to message " + "queue limit (slow client queue limit will have no effect) [msgQueueLimit=" + cfg.messageQueueLimit() + ", slowClientQueueLimit=" + cfg.slowClientQueueLimit() + ']');
}
if (cfg.messageQueueLimit() == 0)
U.quietAndWarn(log, "Message queue limit is set to 0 which may lead to " + "potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes " + "due to message queues growth on sender and receiver sides.");
nioSrvWrapper.start();
this.commWorker = new CommunicationWorker(igniteInstanceName, log, cfg, attributeNames, clientPool, failureProcessorSupplier, nodeGetter, pingNode, this::getExceptionRegistry, nioSrvWrapper, getWorkersRegistry(ignite), getName());
this.srvLsnr.communicationWorker(commWorker);
this.nioSrvWrapper.communicationWorker(commWorker);
new IgniteSpiThread(igniteInstanceName, commWorker.name(), log) {
@Override
protected void body() {
commWorker.run();
}
}.start();
// Ack start.
if (log.isDebugEnabled())
log.debug(startInfo());
}
use of org.apache.ignite.spi.IgniteSpiThread in project ignite by apache.
the class ClientImpl method threads.
/**
* {@inheritDoc}
*/
@Override
protected Collection<IgniteSpiThread> threads() {
ArrayList<IgniteSpiThread> res = new ArrayList<>();
res.add(sockWriter);
MessageWorker msgWorker0 = msgWorker;
if (msgWorker0 != null) {
Thread runner = msgWorker0.runner();
if (runner instanceof IgniteSpiThread)
res.add((IgniteSpiThread) runner);
}
return res;
}
use of org.apache.ignite.spi.IgniteSpiThread in project ignite by apache.
the class UriDeploymentScannerManager method start.
/**
* Starts scanner.
*/
public void start() {
scannerThread = new IgniteSpiThread(igniteInstanceName, "grid-uri-scanner", log) {
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "BusyWait" })
@Override
protected void body() throws InterruptedException {
try {
while (!isInterrupted()) {
try {
scanner.scan(UriDeploymentScannerManager.this);
} catch (Exception e) {
log.error("Uncaught error in URI deployment scanner", e);
} finally {
// Do it in finally to avoid any hanging.
if (firstScan) {
firstScan = false;
lsnr.onFirstScanFinished();
}
}
Thread.sleep(freq);
}
} finally {
// Double check. If we were cancelled before anything has been scanned.
if (firstScan) {
firstScan = false;
lsnr.onFirstScanFinished();
}
}
}
};
scannerThread.start();
if (log.isDebugEnabled())
log.debug("Grid URI deployment scanner started: " + this);
}
Aggregations