Search in sources :

Example 1 with IgniteInstanceResource

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

the class MessagingExample method startListening.

/**
     * Start listening to messages on remote cluster nodes.
     *
     * @param msg Ignite messaging.
     */
private static void startListening(IgniteMessaging msg) {
    // Add ordered message listener.
    msg.remoteListen(EXAMPLE_TOPIC.ORDERED, new IgniteBiPredicate<UUID, String>() {

        @IgniteInstanceResource
        private Ignite ignite;

        @Override
        public boolean apply(UUID nodeId, String msg) {
            System.out.println("Received ordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
            try {
                ignite.message(ignite.cluster().forNodeId(nodeId)).send(EXAMPLE_TOPIC.ORDERED, msg);
            } catch (IgniteException e) {
                e.printStackTrace();
            }
            // Return true to continue listening.
            return true;
        }
    });
    // Add unordered message listener.
    msg.remoteListen(EXAMPLE_TOPIC.UNORDERED, new IgniteBiPredicate<UUID, String>() {

        @IgniteInstanceResource
        private Ignite ignite;

        @Override
        public boolean apply(UUID nodeId, String msg) {
            System.out.println("Received unordered message [msg=" + msg + ", fromNodeId=" + nodeId + ']');
            try {
                ignite.message(ignite.cluster().forNodeId(nodeId)).send(EXAMPLE_TOPIC.UNORDERED, msg);
            } catch (IgniteException e) {
                e.printStackTrace();
            }
            // Return true to continue listening.
            return true;
        }
    });
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Example 2 with IgniteInstanceResource

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

the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByField.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByField() throws Exception {
    secondary = new TestBaseSecondaryFsMock() {

        @FileSystemResource
        private IgfsImpl igfs;

        @LoggerResource
        private IgniteLogger log;

        @IgniteInstanceResource
        private Ignite ig;

        @Override
        boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
            return igfs == primary && log instanceof IgniteLogger && ig == ignite;
        }
    };
    Ignite ig = startGrid(0);
    IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
    assert secondary.checkInjection(ig, igfs);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Ignite(org.apache.ignite.Ignite) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) FileSystemResource(org.apache.ignite.resources.FileSystemResource) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 3 with IgniteInstanceResource

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

the class IgfsSecondaryFileSystemInjectionSelfTest method testInjectPrimaryByMethods.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "UnusedDeclaration" })
public void testInjectPrimaryByMethods() throws Exception {
    secondary = new TestBaseSecondaryFsMock() {

        /**
         * Ignite instance.
         */
        private Ignite ig;

        /**
         * IGFS instance.
         */
        private IgniteFileSystem igfs;

        /**
         * Logger injected flag
         */
        private boolean logSet;

        /**
         * @param igfs Primary IGFS.
         */
        @FileSystemResource
        void setPrimaryIgfs(IgfsImpl igfs) {
            this.igfs = igfs;
        }

        /**
         * @param log Ignite logger.
         */
        @LoggerResource
        void setIgLogger(IgniteLogger log) {
            logSet = log instanceof IgniteLogger;
        }

        /**
         * @param ig Ignite instance.
         */
        @IgniteInstanceResource
        void setIgniteInst(Ignite ig) {
            this.ig = ig;
        }

        @Override
        boolean checkInjection(Ignite ignite, IgniteFileSystem primary) {
            return ignite == ig && primary == igfs && logSet;
        }
    };
    Ignite ig = startGrid(0);
    IgniteFileSystem igfs = ig.fileSystem(IGFS_NAME);
    assert secondary.checkInjection(ig, igfs);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Ignite(org.apache.ignite.Ignite) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) FileSystemResource(org.apache.ignite.resources.FileSystemResource) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 4 with IgniteInstanceResource

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

the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicSequenceInitialization.

/**
 * @throws Exception If failed.
 */
public void testAtomicSequenceInitialization() throws Exception {
    int threadCnt = 3;
    final AtomicInteger idx = new AtomicInteger(gridCount());
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {

        @Override
        public void apply() {
            int id = idx.getAndIncrement();
            try {
                log.info("Start node: " + id);
                startGrid(id);
                Thread.sleep(1000);
            } catch (Exception e) {
                throw F.wrap(e);
            } finally {
                stopGrid(id);
                info("Thread finished.");
            }
        }
    }, threadCnt, "test-thread");
    while (!fut.isDone()) {
        grid(0).compute().call(new IgniteCallable<Object>() {

            /**
             */
            @IgniteInstanceResource
            private Ignite g;

            @Override
            public Object call() throws Exception {
                IgniteAtomicSequence seq = g.atomicSequence(STRUCTURE_NAME, 1, true);
                assert seq != null;
                for (int i = 0; i < 1000; i++) seq.getAndIncrement();
                return null;
            }
        });
    }
    fut.get();
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) CA(org.apache.ignite.internal.util.typedef.CA) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 5 with IgniteInstanceResource

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

the class PlatformCacheEntryFilterImpl method setIgniteInstance.

/**
 * @param ignite Ignite instance.
 */
@IgniteInstanceResource
public void setIgniteInstance(Ignite ignite) {
    ctx = PlatformUtils.platformContext(ignite);
    if (ptr != 0)
        return;
    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();
        BinaryRawWriterEx writer = ctx.writer(out);
        writer.writeObject(pred);
        out.synchronize();
        ptr = ctx.gateway().cacheEntryFilterCreate(mem.pointer());
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource)

Aggregations

IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)59 Ignite (org.apache.ignite.Ignite)48 Test (org.junit.Test)40 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)28 IgniteException (org.apache.ignite.IgniteException)24 IgniteEx (org.apache.ignite.internal.IgniteEx)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 IgniteCache (org.apache.ignite.IgniteCache)15 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)11 List (java.util.List)9 UUID (java.util.UUID)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 IgniteLogger (org.apache.ignite.IgniteLogger)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 Callable (java.util.concurrent.Callable)6