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();
}
}
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 + ']');
}
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;
}
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);
}
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");
}
Aggregations