/** * @param queueName Queue name. * @param hdr Queue hdr. * @param cctx Cache context. */ protected GridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?, ?> cctx) { this.cctx = cctx; this.queueName = queueName; id = hdr.id(); cap = hdr.capacity(); collocated = hdr.collocated(); queueKey = new GridCacheQueueHeaderKey(queueName); cache = cctx.kernalContext().cache().internalCache(cctx.name()); this.compute = cctx.kernalContext().grid().compute(); log = cctx.logger(getClass()); readSem = new Semaphore(hdr.size(), true); writeSem = bounded() ? new Semaphore(hdr.capacity() - hdr.size(), true) : null; }
@Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) { if (!busyLock.enterBusy()) return; try { for (CacheEntryEvent<?, ?> e : evts) { GridCacheQueueHeaderKey key = (GridCacheQueueHeaderKey)e.getKey(); GridCacheQueueHeader hdr = (GridCacheQueueHeader)e.getValue(); for (final GridCacheQueueProxy queue : queuesMap.values()) { if (queue.name().equals(key.queueName())) { if (e.getEventType() == REMOVED) { GridCacheQueueHeader oldHdr = (GridCacheQueueHeader)e.getOldValue(); assert oldHdr != null; if (oldHdr.id().equals(queue.delegate().id())) { queue.delegate().onRemoved(false); queuesMap.remove(queue.delegate().id()); } } else queue.delegate().onHeaderChanged(hdr); } } } } finally { busyLock.leaveBusy(); } } },
@Override public void applyx(GridCacheQueueHeader hdr) throws IgniteCheckedException { hdr = (GridCacheQueueHeader) cctx.cache().withNoRetries().getAndRemove(new GridCacheQueueHeaderKey(name)); if (hdr == null || hdr.empty()) return; GridCacheQueueAdapter.removeKeys(cctx.cache(), hdr.id(), name, hdr.collocated(), hdr.head(), hdr.tail(), 0); } };
@Override public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) { if (!busyLock.enterBusy()) return; try { for (CacheEntryEvent<?, ?> e : evts) { GridCacheQueueHeaderKey key = (GridCacheQueueHeaderKey)e.getKey(); GridCacheQueueHeader hdr = (GridCacheQueueHeader)e.getValue(); for (final GridCacheQueueProxy queue : queuesMap.values()) { if (queue.name().equals(key.queueName())) { if (e.getEventType() == REMOVED) { GridCacheQueueHeader oldHdr = (GridCacheQueueHeader)e.getOldValue(); assert oldHdr != null; if (oldHdr.id().equals(queue.delegate().id())) { queue.delegate().onRemoved(false); queuesMap.remove(queue.delegate().id()); } } else queue.delegate().onHeaderChanged(hdr); } } } } finally { busyLock.leaveBusy(); } } },
GridCacheQueueHeaderKey key = new GridCacheQueueHeaderKey(name);
/** * @throws Exception If failed. */ @SuppressWarnings("unchecked") @Test public void testInternalKeysPreloading() throws Exception { try { IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < ENTRY_CNT; i++) cache.put(new GridCacheQueueHeaderKey("queue" + i), 1); startGrid(GRID_CNT); // Start additional node. for (int i = 0; i < ENTRY_CNT; i++) { GridCacheQueueHeaderKey internalKey = new GridCacheQueueHeaderKey("queue" + i); Collection<ClusterNode> nodes = grid(0).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(internalKey); for (ClusterNode n : nodes) { Ignite g = findGridForNodeId(n.id()); assertNotNull(g); assertTrue("Affinity node doesn't contain internal key [key=" + internalKey + ", node=" + n + ']', ((GridNearCacheAdapter)((IgniteKernal)g).internalCache(DEFAULT_CACHE_NAME)).dht().containsKey(internalKey)); } } } finally { stopGrid(GRID_CNT); } }
ClusterNode node = grid(0).affinity(queueCacheName).mapKeyToNode(new GridCacheQueueHeaderKey(QUEUE_NAME1));
/** * @param queueName Queue name. * @param hdr Queue hdr. * @param cctx Cache context. */ @SuppressWarnings("unchecked") protected GridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?, ?> cctx) { this.cctx = cctx; this.queueName = queueName; id = hdr.id(); cap = hdr.capacity(); collocated = hdr.collocated(); queueKey = new GridCacheQueueHeaderKey(queueName); cache = cctx.kernalContext().cache().internalCache(cctx.name()); this.compute = cctx.kernalContext().grid().compute(); log = cctx.logger(getClass()); readSem = new Semaphore(hdr.size(), true); writeSem = bounded() ? new Semaphore(hdr.capacity() - hdr.size(), true) : null; }
@Override public void applyx(GridCacheQueueHeader hdr) throws IgniteCheckedException { hdr = (GridCacheQueueHeader) cctx.cache().withNoRetries().getAndRemove(new GridCacheQueueHeaderKey(name)); if (hdr == null || hdr.empty()) return; GridCacheQueueAdapter.removeKeys(cctx.cache(), hdr.id(), name, hdr.collocated(), hdr.head(), hdr.tail(), 0); } };
GridCacheQueueHeaderKey key = new GridCacheQueueHeaderKey(name);