Search in sources :

Example 21 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession in project ignite by apache.

the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method communicationSession.

/**
     * @param spi SPI.
     * @return Session.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
private GridNioSession communicationSession(TcpCommunicationSpi spi) throws Exception {
    final GridNioServer srv = U.field(spi, "nioSrvr");
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
            return !sessions.isEmpty();
        }
    }, 5000);
    Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
    assertEquals(1, sessions.size());
    return sessions.iterator().next();
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Collection(java.util.Collection) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer)

Example 22 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession in project ignite by apache.

the class IgniteCacheMessageRecoveryAbstractTest method closeSessions.

/**
     * @param ignite Node.
     * @throws Exception If failed.
     * @return {@code True} if closed at least one session.
     */
static boolean closeSessions(Ignite ignite) throws Exception {
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ignite.configuration().getCommunicationSpi();
    Map<UUID, GridCommunicationClient[]> clients = U.field(commSpi, "clients");
    boolean closed = false;
    for (GridCommunicationClient[] clients0 : clients.values()) {
        for (GridCommunicationClient client : clients0) {
            if (client != null) {
                GridTcpNioCommunicationClient client0 = (GridTcpNioCommunicationClient) client;
                GridNioSession ses = client0.session();
                ses.close();
                closed = true;
            }
        }
    }
    return closed;
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Example 23 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession in project ignite by apache.

the class SqlListenerProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    IgniteConfiguration cfg = ctx.config();
    OdbcConfiguration odbcCfg = cfg.getOdbcConfiguration();
    if (odbcCfg != null) {
        try {
            HostAndPortRange hostPort;
            if (F.isEmpty(odbcCfg.getEndpointAddress())) {
                hostPort = new HostAndPortRange(OdbcConfiguration.DFLT_TCP_HOST, OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO);
            } else {
                hostPort = HostAndPortRange.parse(odbcCfg.getEndpointAddress(), OdbcConfiguration.DFLT_TCP_PORT_FROM, OdbcConfiguration.DFLT_TCP_PORT_TO, "Failed to parse ODBC endpoint address");
            }
            assertParameter(odbcCfg.getThreadPoolSize() > 0, "threadPoolSize > 0");
            odbcExecSvc = new IgniteThreadPoolExecutor("odbc", cfg.getIgniteInstanceName(), odbcCfg.getThreadPoolSize(), odbcCfg.getThreadPoolSize(), 0, new LinkedBlockingQueue<Runnable>());
            InetAddress host;
            try {
                host = InetAddress.getByName(hostPort.host());
            } catch (Exception e) {
                throw new IgniteCheckedException("Failed to resolve ODBC host: " + hostPort.host(), e);
            }
            Exception lastErr = null;
            for (int port = hostPort.portFrom(); port <= hostPort.portTo(); port++) {
                try {
                    GridNioFilter[] filters = new GridNioFilter[] { new GridNioAsyncNotifyFilter(ctx.igniteInstanceName(), odbcExecSvc, log) {

                        @Override
                        public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException {
                            proceedSessionOpened(ses);
                        }
                    }, new GridNioCodecFilter(new SqlListenerBufferedParser(), log, false) };
                    GridNioServer<byte[]> srv0 = GridNioServer.<byte[]>builder().address(host).port(port).listener(new SqlListenerNioListener(ctx, busyLock, odbcCfg.getMaxOpenCursors())).logger(log).selectorCount(DFLT_SELECTOR_CNT).igniteInstanceName(ctx.igniteInstanceName()).serverName("odbc").tcpNoDelay(DFLT_TCP_NODELAY).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(odbcCfg.getSocketSendBufferSize()).socketReceiveBufferSize(odbcCfg.getSocketReceiveBufferSize()).filters(filters).directMode(false).idleTimeout(Long.MAX_VALUE).build();
                    srv0.start();
                    srv = srv0;
                    ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
                    log.info("ODBC processor has started on TCP port " + port);
                    lastErr = null;
                    break;
                } catch (Exception e) {
                    lastErr = e;
                }
            }
            assert (srv != null && lastErr == null) || (srv == null && lastErr != null);
            if (lastErr != null)
                throw new IgniteCheckedException("Failed to bind to any [host:port] from the range [" + "address=" + hostPort + ", lastErr=" + lastErr + ']');
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start ODBC processor.", e);
        }
    }
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) HostAndPortRange(org.apache.ignite.internal.util.HostAndPortRange) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNioAsyncNotifyFilter(org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) OdbcConfiguration(org.apache.ignite.configuration.OdbcConfiguration) InetAddress(java.net.InetAddress)

Example 24 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession in project ignite by apache.

the class TcpCommunicationSpi method createTcpClient.

/**
     * Establish TCP connection to remote node and returns client.
     *
     * @param node Remote node.
     * @param connIdx Connection index.
     * @return Client.
     * @throws IgniteCheckedException If failed.
     */
protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
    Collection<String> rmtAddrs0 = node.attribute(createSpiAttributeName(ATTR_ADDRS));
    Collection<String> rmtHostNames0 = node.attribute(createSpiAttributeName(ATTR_HOST_NAMES));
    Integer boundPort = node.attribute(createSpiAttributeName(ATTR_PORT));
    Collection<InetSocketAddress> extAddrs = node.attribute(createSpiAttributeName(ATTR_EXT_ADDRS));
    boolean isRmtAddrsExist = (!F.isEmpty(rmtAddrs0) && boundPort != null);
    boolean isExtAddrsExist = !F.isEmpty(extAddrs);
    if (!isRmtAddrsExist && !isExtAddrsExist)
        throw new IgniteCheckedException("Failed to send message to the destination node. Node doesn't have any " + "TCP communication addresses or mapped external addresses. Check configuration and make sure " + "that you use the same communication SPI on all nodes. Remote node id: " + node.id());
    LinkedHashSet<InetSocketAddress> addrs;
    // Try to connect first on bound addresses.
    if (isRmtAddrsExist) {
        List<InetSocketAddress> addrs0 = new ArrayList<>(U.toSocketAddresses(rmtAddrs0, rmtHostNames0, boundPort));
        boolean sameHost = U.sameMacs(getSpiContext().localNode(), node);
        Collections.sort(addrs0, U.inetAddressesComparator(sameHost));
        addrs = new LinkedHashSet<>(addrs0);
    } else
        addrs = new LinkedHashSet<>();
    // Then on mapped external addresses.
    if (isExtAddrsExist)
        addrs.addAll(extAddrs);
    Set<InetAddress> allInetAddrs = U.newHashSet(addrs.size());
    for (InetSocketAddress addr : addrs) {
        // Skip unresolved as addr.getAddress() can return null.
        if (!addr.isUnresolved())
            allInetAddrs.add(addr.getAddress());
    }
    List<InetAddress> reachableInetAddrs = U.filterReachable(allInetAddrs);
    if (reachableInetAddrs.size() < allInetAddrs.size()) {
        LinkedHashSet<InetSocketAddress> addrs0 = U.newLinkedHashSet(addrs.size());
        List<InetSocketAddress> unreachableInetAddr = new ArrayList<>(allInetAddrs.size() - reachableInetAddrs.size());
        for (InetSocketAddress addr : addrs) {
            if (reachableInetAddrs.contains(addr.getAddress()))
                addrs0.add(addr);
            else
                unreachableInetAddr.add(addr);
        }
        addrs0.addAll(unreachableInetAddr);
        addrs = addrs0;
    }
    if (log.isDebugEnabled())
        log.debug("Addresses to connect for node [rmtNode=" + node.id() + ", addrs=" + addrs.toString() + ']');
    boolean conn = false;
    GridCommunicationClient client = null;
    IgniteCheckedException errs = null;
    int connectAttempts = 1;
    for (InetSocketAddress addr : addrs) {
        long connTimeout0 = connTimeout;
        int attempt = 1;
        IgniteSpiOperationTimeoutHelper timeoutHelper = new IgniteSpiOperationTimeoutHelper(this, !node.isClient());
        while (!conn) {
            // Reconnection on handshake timeout.
            try {
                SocketChannel ch = SocketChannel.open();
                ch.configureBlocking(true);
                ch.socket().setTcpNoDelay(tcpNoDelay);
                ch.socket().setKeepAlive(true);
                if (sockRcvBuf > 0)
                    ch.socket().setReceiveBufferSize(sockRcvBuf);
                if (sockSndBuf > 0)
                    ch.socket().setSendBufferSize(sockSndBuf);
                if (getSpiContext().node(node.id()) == null) {
                    U.closeQuiet(ch);
                    throw new ClusterTopologyCheckedException("Failed to send message " + "(node left topology): " + node);
                }
                ConnectionKey connKey = new ConnectionKey(node.id(), connIdx, -1);
                GridNioRecoveryDescriptor recoveryDesc = outRecoveryDescriptor(node, connKey);
                if (!recoveryDesc.reserve()) {
                    U.closeQuiet(ch);
                    return null;
                }
                long rcvCnt = -1;
                Map<Integer, Object> meta = new HashMap<>();
                GridSslMeta sslMeta = null;
                try {
                    ch.socket().connect(addr, (int) timeoutHelper.nextTimeoutChunk(connTimeout));
                    if (isSslEnabled()) {
                        meta.put(SSL_META.ordinal(), sslMeta = new GridSslMeta());
                        SSLEngine sslEngine = ignite.configuration().getSslContextFactory().create().createSSLEngine();
                        sslEngine.setUseClientMode(true);
                        sslMeta.sslEngine(sslEngine);
                    }
                    Integer handshakeConnIdx = connIdx;
                    rcvCnt = safeHandshake(ch, recoveryDesc, node.id(), timeoutHelper.nextTimeoutChunk(connTimeout0), sslMeta, handshakeConnIdx);
                    if (rcvCnt == -1)
                        return null;
                } finally {
                    if (recoveryDesc != null && rcvCnt == -1)
                        recoveryDesc.release();
                }
                try {
                    meta.put(CONN_IDX_META, connKey);
                    if (recoveryDesc != null) {
                        recoveryDesc.onHandshake(rcvCnt);
                        meta.put(-1, recoveryDesc);
                    }
                    GridNioSession ses = nioSrvr.createSession(ch, meta).get();
                    client = new GridTcpNioCommunicationClient(connIdx, ses, log);
                    conn = true;
                } finally {
                    if (!conn) {
                        if (recoveryDesc != null)
                            recoveryDesc.release();
                    }
                }
            } catch (HandshakeTimeoutException | IgniteSpiOperationTimeoutException e) {
                if (client != null) {
                    client.forceClose();
                    client = null;
                }
                if (failureDetectionTimeoutEnabled() && (e instanceof HandshakeTimeoutException || timeoutHelper.checkFailureTimeoutReached(e))) {
                    String msg = "Handshake timed out (failure detection timeout is reached) " + "[failureDetectionTimeout=" + failureDetectionTimeout() + ", addr=" + addr + ']';
                    onException(msg, e);
                    if (log.isDebugEnabled())
                        log.debug(msg);
                    if (errs == null)
                        errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " + "Make sure that each ComputeTask and cache Transaction has a timeout set " + "in order to prevent parties from waiting forever in case of network issues " + "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
                    errs.addSuppressed(new IgniteCheckedException("Failed to connect to address: " + addr, e));
                    break;
                }
                assert !failureDetectionTimeoutEnabled();
                onException("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", addr=" + addr + ']', e);
                if (log.isDebugEnabled())
                    log.debug("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", addr=" + addr + ", err=" + e + ']');
                if (attempt == reconCnt || connTimeout0 > maxConnTimeout) {
                    if (log.isDebugEnabled())
                        log.debug("Handshake timedout (will stop attempts to perform the handshake) " + "[timeout=" + connTimeout0 + ", maxConnTimeout=" + maxConnTimeout + ", attempt=" + attempt + ", reconCnt=" + reconCnt + ", err=" + e.getMessage() + ", addr=" + addr + ']');
                    if (errs == null)
                        errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " + "Make sure that each ComputeTask and cache Transaction has a timeout set " + "in order to prevent parties from waiting forever in case of network issues " + "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
                    errs.addSuppressed(new IgniteCheckedException("Failed to connect to address: " + addr, e));
                    break;
                } else {
                    attempt++;
                    connTimeout0 *= 2;
                // Continue loop.
                }
            } catch (Exception e) {
                if (client != null) {
                    client.forceClose();
                    client = null;
                }
                onException("Client creation failed [addr=" + addr + ", err=" + e + ']', e);
                if (log.isDebugEnabled())
                    log.debug("Client creation failed [addr=" + addr + ", err=" + e + ']');
                boolean failureDetThrReached = timeoutHelper.checkFailureTimeoutReached(e);
                if (failureDetThrReached)
                    LT.warn(log, "Connect timed out (consider increasing 'failureDetectionTimeout' " + "configuration property) [addr=" + addr + ", failureDetectionTimeout=" + failureDetectionTimeout() + ']');
                else if (X.hasCause(e, SocketTimeoutException.class))
                    LT.warn(log, "Connect timed out (consider increasing 'connTimeout' " + "configuration property) [addr=" + addr + ", connTimeout=" + connTimeout + ']');
                if (errs == null)
                    errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " + "Make sure that each ComputeTask and cache Transaction has a timeout set " + "in order to prevent parties from waiting forever in case of network issues " + "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
                errs.addSuppressed(new IgniteCheckedException("Failed to connect to address: " + addr, e));
                // Reconnect for the second time, if connection is not established.
                if (!failureDetThrReached && connectAttempts < 2 && (e instanceof ConnectException || X.hasCause(e, ConnectException.class))) {
                    connectAttempts++;
                    continue;
                }
                break;
            }
        }
        if (conn)
            break;
    }
    if (client == null) {
        assert errs != null;
        if (X.hasCause(errs, ConnectException.class))
            LT.warn(log, "Failed to connect to a remote node " + "(make sure that destination node is alive and " + "operating system firewall is disabled on local and remote hosts) " + "[addrs=" + addrs + ']');
        if (getSpiContext().node(node.id()) != null && (CU.clientNode(node) || !CU.clientNode(getLocalNode())) && X.hasCause(errs, ConnectException.class, SocketTimeoutException.class, HandshakeTimeoutException.class, IgniteSpiOperationTimeoutException.class)) {
            LT.warn(log, "TcpCommunicationSpi failed to establish connection to node, node will be dropped from " + "cluster [" + "rmtNode=" + node + ", err=" + errs + ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']');
            getSpiContext().failNode(node.id(), "TcpCommunicationSpi failed to establish connection to node [" + "rmtNode=" + node + ", errs=" + errs + ", connectErrs=" + Arrays.toString(errs.getSuppressed()) + ']');
        }
        throw errs;
    }
    return client;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SocketChannel(java.nio.channels.SocketChannel) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) ArrayList(java.util.ArrayList) GridSslMeta(org.apache.ignite.internal.util.nio.ssl.GridSslMeta) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) ConnectException(java.net.ConnectException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SSLException(javax.net.ssl.SSLException) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketTimeoutException(java.net.SocketTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ConnectException(java.net.ConnectException) IpcOutOfSystemResourcesException(org.apache.ignite.internal.util.ipc.shmem.IpcOutOfSystemResourcesException) IOException(java.io.IOException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteSpiOperationTimeoutHelper(org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper) SocketTimeoutException(java.net.SocketTimeoutException) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) IgniteSpiTimeoutObject(org.apache.ignite.spi.IgniteSpiTimeoutObject) InetAddress(java.net.InetAddress) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 25 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession in project ignite by apache.

the class TcpCommunicationSpi method resetNioServer.

/**
     * Recreates tpcSrvr socket instance.
     *
     * @return Server instance.
     * @throws IgniteCheckedException Thrown if it's not possible to create server.
     */
private GridNioServer<Message> resetNioServer() throws IgniteCheckedException {
    if (boundTcpPort >= 0)
        throw new IgniteCheckedException("Tcp NIO server was already created on port " + boundTcpPort);
    IgniteCheckedException lastEx = null;
    // If configured TCP port is busy, find first available in range.
    int lastPort = locPortRange == 0 ? locPort : locPort + locPortRange - 1;
    for (int port = locPort; port <= lastPort; port++) {
        try {
            MessageFactory msgFactory = new MessageFactory() {

                private MessageFactory impl;

                @Nullable
                @Override
                public Message create(short type) {
                    if (impl == null)
                        impl = getSpiContext().messageFactory();
                    assert impl != null;
                    return impl.create(type);
                }
            };
            GridNioMessageReaderFactory readerFactory = new GridNioMessageReaderFactory() {

                private MessageFormatter formatter;

                @Override
                public MessageReader reader(GridNioSession ses, MessageFactory msgFactory) throws IgniteCheckedException {
                    if (formatter == null)
                        formatter = getSpiContext().messageFormatter();
                    assert formatter != null;
                    ConnectionKey key = ses.meta(CONN_IDX_META);
                    return key != null ? formatter.reader(key.nodeId(), msgFactory) : null;
                }
            };
            GridNioMessageWriterFactory writerFactory = new GridNioMessageWriterFactory() {

                private MessageFormatter formatter;

                @Override
                public MessageWriter writer(GridNioSession ses) throws IgniteCheckedException {
                    if (formatter == null)
                        formatter = getSpiContext().messageFormatter();
                    assert formatter != null;
                    ConnectionKey key = ses.meta(CONN_IDX_META);
                    return key != null ? formatter.writer(key.nodeId()) : null;
                }
            };
            GridDirectParser parser = new GridDirectParser(log.getLogger(GridDirectParser.class), msgFactory, readerFactory);
            IgnitePredicate<Message> skipRecoveryPred = new IgnitePredicate<Message>() {

                @Override
                public boolean apply(Message msg) {
                    return msg instanceof RecoveryLastReceivedMessage;
                }
            };
            boolean clientMode = Boolean.TRUE.equals(ignite.configuration().isClientMode());
            IgniteBiInClosure<GridNioSession, Integer> queueSizeMonitor = !clientMode && slowClientQueueLimit > 0 ? new CI2<GridNioSession, Integer>() {

                @Override
                public void apply(GridNioSession ses, Integer qSize) {
                    checkClientQueueSize(ses, qSize);
                }
            } : null;
            GridNioFilter[] filters;
            if (isSslEnabled()) {
                GridNioSslFilter sslFilter = new GridNioSslFilter(ignite.configuration().getSslContextFactory().create(), true, ByteOrder.nativeOrder(), log);
                sslFilter.directMode(true);
                sslFilter.wantClientAuth(true);
                sslFilter.needClientAuth(true);
                filters = new GridNioFilter[] { new GridNioCodecFilter(parser, log, true), new GridConnectionBytesVerifyFilter(log), sslFilter };
            } else
                filters = new GridNioFilter[] { new GridNioCodecFilter(parser, log, true), new GridConnectionBytesVerifyFilter(log) };
            GridNioServer<Message> srvr = GridNioServer.<Message>builder().address(locHost).port(port).listener(srvLsnr).logger(log).selectorCount(selectorsCnt).igniteInstanceName(igniteInstanceName).serverName("tcp-comm").tcpNoDelay(tcpNoDelay).directBuffer(directBuf).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(sockSndBuf).socketReceiveBufferSize(sockRcvBuf).sendQueueLimit(msgQueueLimit).directMode(true).metricsListener(metricsLsnr).writeTimeout(sockWriteTimeout).selectorSpins(selectorSpins).filters(filters).writerFactory(writerFactory).skipRecoveryPredicate(skipRecoveryPred).messageQueueSizeListener(queueSizeMonitor).readWriteSelectorsAssign(usePairedConnections).build();
            boundTcpPort = port;
            // Ack Port the TCP server was bound to.
            if (log.isInfoEnabled()) {
                log.info("Successfully bound communication NIO server to TCP port " + "[port=" + boundTcpPort + ", locHost=" + locHost + ", selectorsCnt=" + selectorsCnt + ", selectorSpins=" + srvr.selectorSpins() + ", pairedConn=" + usePairedConnections + ']');
            }
            srvr.idleTimeout(idleConnTimeout);
            return srvr;
        } catch (IgniteCheckedException e) {
            if (X.hasCause(e, SSLException.class))
                throw new IgniteSpiException("Failed to create SSL context. SSL factory: " + ignite.configuration().getSslContextFactory() + '.', e);
            lastEx = e;
            if (log.isDebugEnabled())
                log.debug("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + locHost + ']');
            onException("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + locHost + ']', e);
        }
    }
    // If free port wasn't found.
    throw new IgniteCheckedException("Failed to bind to any port within range [startPort=" + locPort + ", portRange=" + locPortRange + ", locHost=" + locHost + ']', lastEx);
}
Also used : GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) Message(org.apache.ignite.plugin.extensions.communication.Message) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MessageFormatter(org.apache.ignite.plugin.extensions.communication.MessageFormatter) GridNioSslFilter(org.apache.ignite.internal.util.nio.ssl.GridNioSslFilter) SSLException(javax.net.ssl.SSLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDirectParser(org.apache.ignite.internal.util.nio.GridDirectParser) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridNioMessageWriterFactory(org.apache.ignite.internal.util.nio.GridNioMessageWriterFactory) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridConnectionBytesVerifyFilter(org.apache.ignite.internal.util.nio.GridConnectionBytesVerifyFilter) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) GridNioMessageReaderFactory(org.apache.ignite.internal.util.nio.GridNioMessageReaderFactory)

Aggregations

GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)26 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)11 ByteBuffer (java.nio.ByteBuffer)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridNioServer (org.apache.ignite.internal.util.nio.GridNioServer)8 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)8 IgniteException (org.apache.ignite.IgniteException)7 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)7 Nullable (org.jetbrains.annotations.Nullable)5 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)4 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)4 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)4 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)4 GridNioRecoveryDescriptor (org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)4 IOException (java.io.IOException)3 BindException (java.net.BindException)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3