Java Code Examples for org.apache.ignite.Ignite#queue()
The following examples show how to use
org.apache.ignite.Ignite#queue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteDistributedModelBuilder.java From ignite with Apache License 2.0 | 6 votes |
/** * Constructs a new instance of distributed inference model. * * @param ignite Ignite instance. * @param suffix Suffix that with correspondent templates formats service and queue names. * @param reader Inference model reader. * @param parser Inference model parser. * @param instances Number of service instances maintaining to make distributed inference. * @param maxPerNode Max per node number of instances. */ DistributedInfModel(Ignite ignite, String suffix, ModelReader reader, ModelParser<I, O, ?> parser, int instances, int maxPerNode) { this.ignite = ignite; this.suffix = suffix; reqQueue = ignite.queue(String.format(INFERENCE_REQUEST_QUEUE_NAME_PATTERN, suffix), QUEUE_CAPACITY, queueCfg); resQueue = ignite.queue(String.format(INFERENCE_RESPONSE_QUEUE_NAME_PATTERN, suffix), QUEUE_CAPACITY, queueCfg); startReceiver(); startService(reader, parser, instances, maxPerNode); running.set(true); }
Example 2
Source File: IgniteQueueExample.java From ignite with Apache License 2.0 | 6 votes |
/** * Initialize queue. * * @param ignite Ignite. * @param queueName Name of queue. * @return Queue. * @throws IgniteException If execution failed. */ private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName) throws IgniteException { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setCacheMode(PARTITIONED); // Initialize new FIFO queue. IgniteQueue<String> queue = ignite.queue(queueName, 0, colCfg); // Initialize queue items. // We will be use blocking operation and queue size must be appropriated. for (int i = 0; i < ignite.cluster().nodes().size() * RETRIES * 2; i++) queue.put(Integer.toString(i)); System.out.println("Queue size after initializing: " + queue.size()); return queue; }
Example 3
Source File: IgniteDistributedModelBuilder.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void init(ServiceContext ctx) { Ignite ignite = Ignition.localIgnite(); reqQueue = ignite.queue(String.format(INFERENCE_REQUEST_QUEUE_NAME_PATTERN, suffix), QUEUE_CAPACITY, queueCfg); resQueue = ignite.queue(String.format(INFERENCE_RESPONSE_QUEUE_NAME_PATTERN, suffix), QUEUE_CAPACITY, queueCfg); mdl = parser.parse(reader.read()); }
Example 4
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteQueue<Integer> q = ignite.queue(TEST_QUEUE_NAME, 0, colCfg); for (int i = 0; i < operationsPerTx; i++) { q.put(RAND.nextInt(MAX_INT)); long cnt = writes.incrementAndGet(); if (cnt % WRITE_LOG_MOD == 0) info("Performed " + cnt + " writes."); } }
Example 5
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteQueue<Integer> q = ignite.queue(TEST_QUEUE_NAME, 0, colCfg); for (int i = 0; i < operationsPerTx; i++) { q.peek(); long cnt = reads.incrementAndGet(); if (cnt % READ_LOG_MOD == 0) info("Performed " + cnt + " reads."); } }
Example 6
Source File: GridCacheQueueClientDisconnectTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testClientDisconnect() throws Exception { try { Ignite server = startGrid(0); Ignite client = startClientGrid(1); awaitPartitionMapExchange(); final IgniteQueue queue = client.queue( IGNITE_QUEUE_NAME, 0, collectionConfiguration(CacheAtomicityMode.ATOMIC)); final CountDownLatch latch = new CountDownLatch(1); GridTestUtils.runAsync(new Runnable() { @Override public void run() { try { Object value = queue.take(); } catch (IgniteClientDisconnectedException icd) { latch.countDown(); } catch (Exception e) { } } }); U.sleep(5000); server.close(); boolean countReachedZero = latch.await(FAILURE_DETECTION_TIMEOUT * 2, TimeUnit.MILLISECONDS); assertTrue("IgniteClientDisconnectedException was not thrown", countReachedZero); } finally { stopAllGrids(); } }
Example 7
Source File: IgniteClientReconnectCollectionsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param colCfg Collection configuration. * @throws Exception If failed. */ private void queueReconnectInProgress(final CollectionConfiguration colCfg) throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); final String setName = "queue-rmv" + colCfg.getAtomicityMode(); final IgniteQueue<String> clientQueue = client.queue(setName, 10, colCfg); final IgniteQueue<String> srvQueue = srv.queue(setName, 10, null); assertTrue(clientQueue.offer("1")); assertTrue(srvQueue.contains("1")); BlockTcpCommunicationSpi commSpi = commSpi(srv); if (colCfg.getAtomicityMode() == ATOMIC) commSpi.blockMessage(GridNearAtomicUpdateResponse.class); else commSpi.blockMessage(GridNearTxPrepareResponse.class); final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { @Override public Object call() throws Exception { try { clientQueue.add("2"); } catch (IgniteClientDisconnectedException e) { checkAndWait(e); return true; } return false; } }); // Check that client waiting operation. GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return fut.get(200); } }, IgniteFutureTimeoutCheckedException.class, null); assertNotDone(fut); commSpi.unblockMessage(); reconnectClientNode(client, srv, null); assertTrue("Future was not failed. Atomic mode: " + colCfg.getAtomicityMode() + ".", (Boolean)fut.get()); assertTrue(clientQueue.add("3")); assertEquals("1", clientQueue.poll()); }
Example 8
Source File: IgnitePersistentStoreDataStructuresTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testQueue() throws Exception { Ignite ignite = startGrids(4); ignite.active(true); IgniteQueue<Object> queue = ignite.queue("testQueue", 100, new CollectionConfiguration()); for (int i = 0; i < 100; i++) queue.offer(i); stopAllGrids(); ignite = startGrids(4); ignite.active(true); queue = ignite.queue("testQueue", 0, null); for (int i = 0; i < 100; i++) assertEquals(i, queue.poll()); }
Example 9
Source File: IgniteClientReconnectCollectionsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param colCfg Collection configuration. * @throws Exception If failed. */ private void serverNodeReconnect(CollectionConfiguration colCfg) throws Exception { final Ignite client = grid(serverCount()); final Ignite srv = ignite(0); assertNotNull(srv.queue("q", 0, colCfg)); assertNotNull(srv.set("s", colCfg)); reconnectClientNode(client, srv, null); IgniteQueue<Object> q = client.queue("q", 0, null); assertNotNull(q); }
Example 10
Source File: IgniteClientReconnectCollectionsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param colCfg Collection configuration. * @throws Exception If failed. */ private void queueReconnect(CollectionConfiguration colCfg) throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); final String setName = "queue-" + colCfg.getAtomicityMode(); IgniteQueue<String> clientQueue = client.queue(setName, 10, colCfg); final IgniteQueue<String> srvQueue = srv.queue(setName, 10, null); assertTrue(clientQueue.offer("1")); assertTrue(srvQueue.contains("1")); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { assertTrue(srvQueue.add("2")); } }); assertTrue(clientQueue.contains("2")); assertEquals("1", clientQueue.poll()); }
Example 11
Source File: IgniteClientReconnectCollectionsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param colCfg Collection configuration. * @throws Exception If failed. */ private void queueReconnectRemoved(CollectionConfiguration colCfg) throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); final String setName = "queue-rmv" + colCfg.getAtomicityMode(); final IgniteQueue<String> clientQueue = client.queue(setName, 10, colCfg); final IgniteQueue<String> srvQueue = srv.queue(setName, 10, null); assertTrue(clientQueue.add("1")); assertTrue(srvQueue.add("2")); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { srvQueue.close(); } }); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { clientQueue.add("fail"); return null; } }, IllegalStateException.class, null); IgniteQueue<String> newClientQueue = client.queue(setName, 10, colCfg); IgniteQueue<String> newSrvQueue = srv.queue(setName, 10, null); assertTrue(newClientQueue.add("1")); assertTrue(newSrvQueue.add("2")); }
Example 12
Source File: IgniteClientDataStructuresAbstractTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param creator Creator node. * @param other Other node. * @throws Exception If failed. */ private void testQueue(Ignite creator, final Ignite other) throws Exception { assertNull(creator.queue("q1", 0, null)); assertNull(other.queue("q1", 0, null)); try (IgniteQueue<Integer> queue = creator.queue("q1", 0, new CollectionConfiguration())) { assertNotNull(queue); queue.add(1); assertEquals(1, queue.poll().intValue()); IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() { @Override public Object call() throws Exception { U.sleep(1000); IgniteQueue<Integer> queue0 = other.queue("q1", 0, null); assertEquals(0, queue0.size()); log.info("Add in queue."); queue0.add(2); return null; } }); log.info("Try take."); assertEquals(2, queue.take().intValue()); log.info("Finished take."); fut.get(); } assertNull(creator.queue("q1", 0, null)); assertNull(other.queue("q1", 0, null)); }