Examples of IExecutorService


Examples of com.hazelcast.core.IExecutorService

        config.setProperty(GroupProperties.PROP_OPERATION_CALL_TIMEOUT_MILLIS, String.valueOf(callTimeout));

        HazelcastInstance hz1 = factory.newHazelcastInstance(config);
        HazelcastInstance hz2 = factory.newHazelcastInstance(config);

        IExecutorService executor = hz1.getExecutorService("test");
        Future<Boolean> f = executor
                .submitToMember(new SleepingTask(callTimeout * 3), hz2.getCluster().getLocalMember());

        Boolean result = f.get(1, TimeUnit.MINUTES);
        assertTrue(result);
    }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    @Test
    public void testSubmitFailingCallableException_withExecutionCallback() throws ExecutionException, InterruptedException {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
        HazelcastInstance instance = factory.newHazelcastInstance();
        IExecutorService service = instance.getExecutorService(randomString());
        final CountDownLatch latch = new CountDownLatch(1);
        service.submit(new FailingTestTask(), new ExecutionCallback<String>() {
            @Override
            public void onResponse(String response) {
            }

            @Override
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

        HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
        HazelcastInstance h2 = nodeFactory.newHazelcastInstance();

        UnDeserializable unDeserializable = new UnDeserializable(1);
        IExecutorService executorService = h1.getExecutorService("default");
        Issue2509Runnable task = new Issue2509Runnable(unDeserializable);
        Future<?> future = executorService.submitToMember(task, h2.getCluster().getLocalMember());
        future.get();
    }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    @Test
    public void submitToAllMembers_WithStatefulCallable() throws Exception {
        final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        HazelcastInstance instance1 = factory.newHazelcastInstance();
        factory.newHazelcastInstance();
        IExecutorService executorService = instance1.getExecutorService(randomString());

        MyTask myTask = new MyTask();
        final CountDownLatch completedLatch = new CountDownLatch(1);
        final AtomicBoolean failed = new AtomicBoolean();
        // Local execution of callable may change the state of callable before sent to other members
        // we avoid this by serializing beforehand
        executorService.submitToAllMembers(myTask, new MultiExecutionCallback() {
            @Override
            public void onResponse(Member member, Object value) {
                if ((Integer) value != 1) {
                    failed.set(true);
                }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    }

    @Test
    public void testObjectWithPartitionKeyAndTask() throws Exception {
        HazelcastInstance instance = instances[0];
        IExecutorService executorServices = instance.getExecutorService("executor");
        String partitionKey = "hazelcast";
        ISemaphore semaphore = instance.getSemaphore("foobar@" + partitionKey);
        semaphore.release();
        ContainsSemaphoreTask task = new ContainsSemaphoreTask(semaphore.getName());
        Future<Boolean> f = executorServices.submitToKeyOwner(task, semaphore.getPartitionKey());
        assertTrue(f.get());
    }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    }

    @Test
    public void testObjectWithPartitionKeyAndMap() throws Exception {
        HazelcastInstance instance = instances[0];
        IExecutorService executorServices = instance.getExecutorService("executor");
        String partitionKey = "hazelcast";
        String mapKey = "key@" + partitionKey;
        IMap map = instance.getMap("map");

        map.put(mapKey, "foobar");

        ISemaphore semaphore = instance.getSemaphore("s@" + partitionKey);
        semaphore.release();

        ContainsSemaphoreAndMapEntryTask task = new ContainsSemaphoreAndMapEntryTask(semaphore.getName(), mapKey);
        Map<Member, Future<Boolean>> futures = executorServices.submitToAllMembers(task);

        int count = 0;
        for (Future<Boolean> f : futures.values()) {
            count += f.get() ? 1 : 0;
        }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    @Test(expected = RejectedExecutionException.class)
    public void testEmptyMemberSelector() {
        final HazelcastInstance instance = createHazelcastInstance();
        final String name = randomString();
        final IExecutorService executorService = instance.getExecutorService(name);
        HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
        executorService.execute(task, new MemberSelector() {
            @Override
            public boolean select(final Member member) {
                return false;
            }
        });
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

                return obj;
            }
        });

        final HazelcastInstance instance = createHazelcastInstance(config);
        IExecutorService executor = instance.getExecutorService("test");

        RunnableWithManagedContext task = new RunnableWithManagedContext();
        executor.submit(task).get();
        assertTrue("The task should have been initialized by the ManagedContext", initialized.get());
    }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    @Test
    public void hazelcastInstanceAwareAndLocal() throws Exception {
        final Config config = new Config();
        config.addExecutorConfig(new ExecutorConfig("test", 1));
        final HazelcastInstance instance = createHazelcastInstance(config);
        IExecutorService executor = instance.getExecutorService("test");

        HazelcastInstanceAwareRunnable task = new HazelcastInstanceAwareRunnable();
        // if 'setHazelcastInstance' not called we expect a RuntimeException
        executor.submit(task).get();
    }
View Full Code Here

Examples of com.hazelcast.core.IExecutorService

    public void testExecuteMultipleNode() throws InterruptedException, ExecutionException {
        final int k = simpleTestNodeCount;
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
        final HazelcastInstance[] instances = factory.newInstances(new Config());
        for (int i = 0; i < k; i++) {
            final IExecutorService service = instances[i].getExecutorService("testExecuteMultipleNode");
            final String script = "hazelcast.getAtomicLong('count').incrementAndGet();";
            final int rand = new Random().nextInt(100);
            final Future<Integer> future = service.submit(new ScriptRunnable(script, null), rand);
            assertEquals(Integer.valueOf(rand), future.get());
        }
        final IAtomicLong count = instances[0].getAtomicLong("count");
        assertEquals(k, count.get());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.