Search in sources :

Example 6 with IgniteBiInClosure

use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.

the class GridCacheIoManager method handleMessage.

/**
 * @param nodeId Sender node ID.
 * @param cacheMsg Message.
 * @param msgHandlers Message handlers.
 * @param plc Message policy.
 */
@SuppressWarnings("unchecked")
private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg, MessageHandlers msgHandlers, byte plc) {
    Lock lock = rw.readLock();
    lock.lock();
    try {
        int msgIdx = cacheMsg.lookupIndex();
        IgniteBiInClosure<UUID, GridCacheMessage> c = null;
        if (msgIdx >= 0) {
            Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
            IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.handlerId());
            if (cacheClsHandlers != null)
                c = cacheClsHandlers[msgIdx];
        }
        if (c == null)
            c = msgHandlers.clsHandlers.get(new ListenerKey(cacheMsg.handlerId(), cacheMsg.getClass()));
        if (c == null) {
            if (processMissedHandler(nodeId, cacheMsg))
                return;
            IgniteLogger log = cacheMsg.messageLogger(cctx);
            StringBuilder msg0 = new StringBuilder("Received message without registered handler (will ignore) [");
            appendMessageInfo(cacheMsg, nodeId, msg0);
            msg0.append(", locTopVer=").append(cctx.exchange().readyAffinityVersion()).append(", msgTopVer=").append(cacheMsg.topologyVersion()).append(", desc=").append(descriptorForMessage(cacheMsg)).append(']');
            msg0.append(nl()).append("Registered listeners:");
            Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
            for (Map.Entry<Integer, IgniteBiInClosure[]> e : idxClsHandlers0.entrySet()) msg0.append(nl()).append(e.getKey()).append("=").append(Arrays.toString(e.getValue()));
            if (cctx.kernalContext().isStopping()) {
                if (log.isDebugEnabled())
                    log.debug(msg0.toString());
            } else {
                U.error(log, msg0.toString());
                try {
                    cacheMsg.onClassError(new IgniteCheckedException("Failed to find message handler for message: " + cacheMsg));
                    processFailedMessage(nodeId, cacheMsg, c, plc);
                } catch (Exception e) {
                    U.error(log, "Failed to process failed message: " + e, e);
                }
            }
            return;
        }
        onMessage0(nodeId, cacheMsg, c, plc);
    } finally {
        lock.unlock();
    }
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) StripedCompositeReadWriteLock(org.apache.ignite.internal.util.StripedCompositeReadWriteLock) Lock(java.util.concurrent.locks.Lock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID) IgniteLogger(org.apache.ignite.IgniteLogger) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 7 with IgniteBiInClosure

use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.

the class GridCacheIoManager method addOrderedHandler.

/**
 * Adds ordered message handler.
 *
 * @param cctx Context.
 * @param cacheGrp {@code True} if cache group message, {@code false} if cache message.
 * @param topic Topic.
 * @param c Handler.
 */
@SuppressWarnings({ "unchecked" })
private void addOrderedHandler(GridCacheSharedContext cctx, boolean cacheGrp, Object topic, IgniteBiInClosure<UUID, ? extends GridCacheMessage> c) {
    MessageHandlers msgHandlers = cacheGrp ? grpHandlers : cacheHandlers;
    IgniteLogger log0 = log;
    if (msgHandlers.orderedHandlers.putIfAbsent(topic, c) == null) {
        cctx.gridIO().addMessageListener(topic, new OrderedMessageListener((IgniteBiInClosure<UUID, GridCacheMessage>) c));
        if (log0 != null && log0.isTraceEnabled())
            log0.trace("Registered ordered cache communication handler [topic=" + topic + ", handler=" + c + ']');
    } else if (log0 != null)
        U.warn(log0, "Failed to register ordered cache communication handler because it is already " + "registered for this topic [topic=" + topic + ", handler=" + c + ']');
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 8 with IgniteBiInClosure

use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.

the class IgniteCacheStoreValueAbstractTest method cacheConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
    if (ccfg.getCacheMode() != CacheMode.LOCAL)
        assertEquals(1, ccfg.getBackups());
    assertTrue(ccfg.isCopyOnRead());
    ccfg.setCopyOnRead(cpyOnRead);
    assertEquals(FULL_SYNC, ccfg.getWriteSynchronizationMode());
    ccfg.setCacheStoreFactory(singletonFactory(new CacheStoreAdapter() {

        @Override
        public void loadCache(IgniteBiInClosure clo, Object... args) {
            clo.apply(new TestKey(100_000), new TestValue(30_000));
        }

        @Override
        public Object load(Object key) throws CacheLoaderException {
            return null;
        }

        @Override
        public void write(Cache.Entry entry) throws CacheWriterException {
        // No-op.
        }

        @Override
        public void delete(Object key) throws CacheWriterException {
        // No-op.
        }
    }));
    ccfg.setInterceptor(new TestInterceptor());
    return ccfg;
}
Also used : MutableEntry(javax.cache.processor.MutableEntry) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with IgniteBiInClosure

use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.

the class GridCacheIoManager method handleMessage.

/**
     * @param nodeId Sender node ID.
     * @param cacheMsg Message.
     */
@SuppressWarnings("unchecked")
private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg) {
    int msgIdx = cacheMsg.lookupIndex();
    IgniteBiInClosure<UUID, GridCacheMessage> c = null;
    if (msgIdx >= 0) {
        Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = idxClsHandlers;
        IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.cacheId());
        if (cacheClsHandlers != null)
            c = cacheClsHandlers[msgIdx];
    }
    if (c == null)
        c = clsHandlers.get(new ListenerKey(cacheMsg.cacheId(), cacheMsg.getClass()));
    if (c == null) {
        IgniteLogger log = cacheMsg.messageLogger(cctx);
        StringBuilder msg0 = new StringBuilder("Received message without registered handler (will ignore) [");
        appendMessageInfo(cacheMsg, nodeId, msg0);
        msg0.append(", locTopVer=").append(cctx.exchange().readyAffinityVersion()).append(", msgTopVer=").append(cacheMsg.topologyVersion()).append(", cacheDesc=").append(cctx.cache().cacheDescriptor(cacheMsg.cacheId())).append(']');
        msg0.append(U.nl()).append("Registered listeners:");
        Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = idxClsHandlers;
        for (Map.Entry<Integer, IgniteBiInClosure[]> e : idxClsHandlers0.entrySet()) msg0.append(U.nl()).append(e.getKey()).append("=").append(Arrays.toString(e.getValue()));
        if (cctx.kernalContext().isStopping()) {
            if (log.isDebugEnabled())
                log.debug(msg0.toString());
        } else
            U.error(log, msg0.toString());
        return;
    }
    onMessage0(nodeId, cacheMsg, c);
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) UUID(java.util.UUID) IgniteLogger(org.apache.ignite.IgniteLogger) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 10 with IgniteBiInClosure

use of org.apache.ignite.lang.IgniteBiInClosure in project ignite by apache.

the class GridCacheBalancingStoreSelfTest method doTestConcurrentLoadAll.

/**
 * @throws Exception If failed.
 */
private void doTestConcurrentLoadAll(int threads, final int threshold, final int keysCnt) throws Exception {
    final CyclicBarrier beforeBarrier = new CyclicBarrier(threads);
    ConcurrentVerifyStore store = new ConcurrentVerifyStore(keysCnt);
    final CacheStoreBalancingWrapper<Integer, Integer> wrapper = new CacheStoreBalancingWrapper<>(store, threshold);
    GridTestUtils.runMultiThreaded(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < keysCnt; i += threshold) {
                try {
                    beforeBarrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
                List<Integer> keys = new ArrayList<>(threshold);
                for (int j = i; j < i + threshold; j++) keys.add(j);
                info("Load keys: " + keys);
                wrapper.loadAll(keys, new IgniteBiInClosure<Integer, Integer>() {

                    @Override
                    public void apply(Integer integer, Integer integer2) {
                    // No-op.
                    }
                });
            }
        }
    }, threads, "load-thread");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) List(java.util.List) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) CyclicBarrier(java.util.concurrent.CyclicBarrier) CacheStoreBalancingWrapper(org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper)

Aggregations

IgniteBiInClosure (org.apache.ignite.lang.IgniteBiInClosure)16 IgniteException (org.apache.ignite.IgniteException)5 IgniteLogger (org.apache.ignite.IgniteLogger)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 Ignite (org.apache.ignite.Ignite)4 IgniteCache (org.apache.ignite.IgniteCache)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MutableEntry (javax.cache.processor.MutableEntry)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Cache (javax.cache.Cache)2 CacheEntryEvent (javax.cache.event.CacheEntryEvent)2