Search in sources :

Example 16 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class GridEventConsumeSelfTest method testResources.

/**
 * @throws Exception If failed.
 */
public void testResources() throws Exception {
    final Collection<UUID> nodeIds = new HashSet<>();
    final AtomicInteger cnt = new AtomicInteger();
    final CountDownLatch latch = new CountDownLatch(GRID_CNT);
    UUID consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {

        @IgniteInstanceResource
        private Ignite grid;

        @Override
        public boolean apply(UUID nodeId, Event evt) {
            info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
            assertEquals(EVT_JOB_STARTED, evt.type());
            assertNotNull(grid);
            nodeIds.add(nodeId);
            cnt.incrementAndGet();
            latch.countDown();
            return true;
        }
    }, new P1<Event>() {

        @IgniteInstanceResource
        private Ignite grid;

        @Override
        public boolean apply(Event evt) {
            assertNotNull(grid);
            return true;
        }
    }, EVT_JOB_STARTED);
    try {
        assertNotNull(consumeId);
        grid(0).compute().broadcast(F.noop());
        assert latch.await(2, SECONDS);
        assertEquals(GRID_CNT, nodeIds.size());
        assertEquals(GRID_CNT, cnt.get());
    } finally {
        grid(0).events().stopRemoteListen(consumeId);
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Example 17 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class GridBinaryAffinityKeySelfTest method testAffinityRun.

/**
 * @throws Exception If failed.
 */
public void testAffinityRun() throws Exception {
    Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 1000; i++) {
        nodeId.set(null);
        grid(0).compute().affinityRun(DEFAULT_CACHE_NAME, new TestObject(i), new IgniteRunnable() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void run() {
                nodeId.set(ignite.configuration().getNodeId());
            }
        });
        assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
        grid(0).compute().affinityRun(DEFAULT_CACHE_NAME, new AffinityKey(0, i), new IgniteRunnable() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void run() {
                nodeId.set(ignite.configuration().getNodeId());
            }
        });
        assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 18 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class GridBinaryAffinityKeySelfTest method testAffinityCall.

/**
 * @throws Exception If failed.
 */
public void testAffinityCall() throws Exception {
    Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
    for (int i = 0; i < 1000; i++) {
        nodeId.set(null);
        grid(0).compute().affinityCall(DEFAULT_CACHE_NAME, new TestObject(i), new IgniteCallable<Object>() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public Object call() {
                nodeId.set(ignite.configuration().getNodeId());
                return null;
            }
        });
        assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) Ignite(org.apache.ignite.Ignite)

Example 19 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class IgniteExecutorServiceTest method testExecute.

/**
 * @throws Exception Thrown in case of test failure.
 */
public void testExecute() throws Exception {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    ExecutorService srvc = createExecutorService(ignite);
    srvc.execute(new Runnable() {

        @IgniteInstanceResource
        private Ignite ignite;

        @Override
        public void run() {
            System.out.println("Test message.");
            assert this.ignite != null;
        }
    });
    srvc.execute(new TestRunnable());
    srvc.shutdown();
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) ExecutorService(java.util.concurrent.ExecutorService) Ignite(org.apache.ignite.Ignite)

Example 20 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class GridClusterStateProcessor method sendComputeCheckGlobalState.

/**
 *  Check cluster state.
 *
 *  @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
 */
private boolean sendComputeCheckGlobalState() {
    AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
    if (log.isInfoEnabled()) {
        log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon" + ctx.isDaemon() + "]");
    }
    IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
    return comp.call(new IgniteCallable<Boolean>() {

        @IgniteInstanceResource
        private Ignite ig;

        @Override
        public Boolean call() throws Exception {
            return ig.active();
        }
    });
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Aggregations

IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)46 Ignite (org.apache.ignite.Ignite)38 IgniteException (org.apache.ignite.IgniteException)18 IgniteCache (org.apache.ignite.IgniteCache)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 IgniteEx (org.apache.ignite.internal.IgniteEx)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteLogger (org.apache.ignite.IgniteLogger)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 LoggerResource (org.apache.ignite.resources.LoggerResource)6 Collection (java.util.Collection)5 List (java.util.List)5 Callable (java.util.concurrent.Callable)5 Cache (javax.cache.Cache)5 ScanQuery (org.apache.ignite.cache.query.ScanQuery)5