Search in sources :

Example 1 with GridIoMessage

use of org.apache.ignite.internal.managers.communication.GridIoMessage in project ignite by apache.

the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
            if (getSpiContext().localNode().id().equals(failingNodeId)) {
                if (ignoredMessage((GridIoMessage) msg) && ignoreMsgNodeIds != null) {
                    for (UUID ignored : ignoreMsgNodeIds) {
                        if (node.id().equals(ignored))
                            return;
                    }
                }
            }
            super.sendMessage(node, msg, ackClosure);
        }
    });
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Example 2 with GridIoMessage

use of org.apache.ignite.internal.managers.communication.GridIoMessage in project ignite by apache.

the class IgniteCachePartitionedQuerySelfTest method testScanQueryPagination.

/**
     * @throws Exception If failed.
     */
public void testScanQueryPagination() throws Exception {
    final int pageSize = 5;
    final AtomicInteger pages = new AtomicInteger(0);
    IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
    for (int i = 0; i < 50; i++) cache.put(i, i);
    CommunicationSpi spi = ignite().configuration().getCommunicationSpi();
    assert spi instanceof TestTcpCommunicationSpi;
    TestTcpCommunicationSpi commSpi = (TestTcpCommunicationSpi) spi;
    commSpi.filter = new IgniteInClosure<Message>() {

        @Override
        public void apply(Message msg) {
            if (!(msg instanceof GridIoMessage))
                return;
            Message msg0 = ((GridIoMessage) msg).message();
            if (msg0 instanceof GridCacheQueryRequest) {
                assertEquals(pageSize, ((GridCacheQueryRequest) msg0).pageSize());
                pages.incrementAndGet();
            } else if (msg0 instanceof GridCacheQueryResponse)
                assertTrue(((GridCacheQueryResponse) msg0).data().size() <= pageSize);
        }
    };
    try {
        ScanQuery<Integer, Integer> qry = new ScanQuery<Integer, Integer>();
        qry.setPageSize(pageSize);
        List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
        assertTrue(pages.get() > ignite().cluster().forDataNodes(DEFAULT_CACHE_NAME).nodes().size());
        assertEquals(50, all.size());
    } finally {
        commSpi.filter = null;
    }
}
Also used : GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ScanQuery(org.apache.ignite.cache.query.ScanQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryResponse(org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryRequest(org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest)

Example 3 with GridIoMessage

use of org.apache.ignite.internal.managers.communication.GridIoMessage in project ignite by apache.

the class TestRecordingCommunicationSpi method sendMessage.

/** {@inheritDoc} */
@Override
public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
    if (msg instanceof GridIoMessage) {
        GridIoMessage ioMsg = (GridIoMessage) msg;
        Message msg0 = ioMsg.message();
        synchronized (this) {
            boolean record = (recordClasses != null && recordClasses.contains(msg0.getClass())) || (recordP != null && recordP.apply(node, msg0));
            if (record)
                recordedMsgs.add(msg0);
            boolean block = false;
            if (blockP != null && blockP.apply(node, msg0))
                block = true;
            else {
                Set<String> blockNodes = blockCls.get(msg0.getClass());
                if (blockNodes != null) {
                    String nodeName = (String) node.attributes().get(ATTR_IGNITE_INSTANCE_NAME);
                    block = blockNodes.contains(nodeName);
                }
            }
            if (block) {
                ignite.log().info("Block message [node=" + node.id() + ", msg=" + ioMsg.message() + ']');
                blockedMsgs.add(new T2<>(node, ioMsg));
                notifyAll();
                return;
            } else if (record)
                notifyAll();
        }
    }
    super.sendMessage(node, msg, ackC);
}
Also used : GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message)

Example 4 with GridIoMessage

use of org.apache.ignite.internal.managers.communication.GridIoMessage in project ignite by apache.

the class IgniteTxOriginatingNodeFailureAbstractSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
            if (!F.eq(ignoreMsgNodeId, node.id()) || !ignoredMessage((GridIoMessage) msg))
                super.sendMessage(node, msg, ackClosure);
        }
    });
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(OPTIMISTIC);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Aggregations

GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)3 IgniteException (org.apache.ignite.IgniteException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)2 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 GridCacheQueryRequest (org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest)1 GridCacheQueryResponse (org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse)1 CommunicationSpi (org.apache.ignite.spi.communication.CommunicationSpi)1