Java Code Examples for org.redisson.config.RedissonNodeConfig#setExecutorServiceWorkers()
The following examples show how to use
org.redisson.config.RedissonNodeConfig#setExecutorServiceWorkers() .
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: ExecutorServiceExamples.java From redisson-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Config config = new Config(); config.useClusterServers() .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"); RedissonClient redisson = Redisson.create(config); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1)); RedissonNode node = RedissonNode.create(nodeConfig); node.start(); RExecutorService e = redisson.getExecutorService("myExecutor"); e.execute(new RunnableTask()); e.submit(new CallableTask()); e.shutdown(); node.shutdown(); }
Example 2
Source File: SchedulerServiceExamples.java From redisson-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Config config = new Config(); config.useClusterServers() .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003"); RedissonClient redisson = Redisson.create(config); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 5)); RedissonNode node = RedissonNode.create(nodeConfig); node.start(); RScheduledExecutorService e = redisson.getExecutorService("myExecutor"); e.schedule(new RunnableTask(), 10, TimeUnit.SECONDS); e.schedule(new CallableTask(), 4, TimeUnit.MINUTES); e.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?")); e.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5)); e.schedule(new RunnableTask(), CronSchedule.weeklyOnDayAndHourAndMinute(12, 4, Calendar.MONDAY, Calendar.FRIDAY)); e.shutdown(); node.shutdown(); }
Example 3
Source File: RedissonScheduledExecutorServiceTest.java From redisson with Apache License 2.0 | 6 votes |
@Test(timeout = 7000) public void testTaskResume() throws InterruptedException, ExecutionException { RScheduledExecutorService executor = redisson.getExecutorService("test"); ScheduledFuture<Long> future1 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS); ScheduledFuture<Long> future2 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS); ScheduledFuture<Long> future3 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS); node.shutdown(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(redisson.getConfig()); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1)); node = RedissonNode.create(nodeConfig); node.start(); assertThat(future1.get()).isEqualTo(100); assertThat(future2.get()).isEqualTo(100); assertThat(future3.get()).isEqualTo(100); }
Example 4
Source File: RedissonExecutorServiceTest.java From redisson with Apache License 2.0 | 6 votes |
public void testTaskFinishing() throws Exception { AtomicInteger counter = new AtomicInteger(); new MockUp<TasksRunnerService>() { @Mock private void finish(Invocation invocation, String requestId) { if (counter.incrementAndGet() > 1) { invocation.proceed(); } } }; Config config = createConfig(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1)); node.shutdown(); node = RedissonNode.create(nodeConfig); node.start(); RExecutorService executor = redisson.getExecutorService("test2"); RExecutorFuture<?> f = executor.submit(new FailoverTask("finished")); Thread.sleep(2000); node.shutdown(); f.get(); assertThat(redisson.<Boolean>getBucket("finished").get()).isTrue(); }
Example 5
Source File: RedissonScheduledExecutorServiceTest.java From redisson with Apache License 2.0 | 5 votes |
@Before @Override public void before() throws IOException, InterruptedException { super.before(); Config config = createConfig(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1)); node = RedissonNode.create(nodeConfig); node.start(); }
Example 6
Source File: RedissonExecutorServiceTest.java From redisson with Apache License 2.0 | 5 votes |
@Before @Override public void before() throws IOException, InterruptedException { super.before(); Config config = createConfig(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1)); node = RedissonNode.create(nodeConfig); node.start(); }
Example 7
Source File: RedissonExecutorServiceSpringTest.java From redisson with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "shutdown") RedissonNode redissonNode(BeanFactory beanFactory) { Config config = BaseTest.createConfig(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap(EXECUTOR_NAME, 1)); nodeConfig.setBeanFactory(beanFactory); RedissonNode node = RedissonNode.create(nodeConfig); node.start(); return node; }
Example 8
Source File: RedissonExecutorServiceTest.java From redisson with Apache License 2.0 | 4 votes |
@Test public void testFailoverInSentinel() throws Exception { RedisRunner.RedisProcess master = new RedisRunner() .nosave() .randomPort() .randomDir() .run(); RedisRunner.RedisProcess slave1 = new RedisRunner() .port(6380) .nosave() .randomDir() .slaveof("127.0.0.1", master.getRedisServerPort()) .run(); RedisRunner.RedisProcess slave2 = new RedisRunner() .port(6381) .nosave() .randomDir() .slaveof("127.0.0.1", master.getRedisServerPort()) .run(); RedisRunner.RedisProcess sentinel1 = new RedisRunner() .nosave() .randomDir() .port(26379) .sentinel() .sentinelMonitor("myMaster", "127.0.0.1", master.getRedisServerPort(), 2) .run(); RedisRunner.RedisProcess sentinel2 = new RedisRunner() .nosave() .randomDir() .port(26380) .sentinel() .sentinelMonitor("myMaster", "127.0.0.1", master.getRedisServerPort(), 2) .run(); RedisRunner.RedisProcess sentinel3 = new RedisRunner() .nosave() .randomDir() .port(26381) .sentinel() .sentinelMonitor("myMaster", "127.0.0.1", master.getRedisServerPort(), 2) .run(); Thread.sleep(5000); Config config = new Config(); config.useSentinelServers() .setLoadBalancer(new RandomLoadBalancer()) .addSentinelAddress(sentinel3.getRedisServerAddressAndPort()).setMasterName("myMaster"); RedissonClient redisson = Redisson.create(config); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1)); node.shutdown(); node = RedissonNode.create(nodeConfig); node.start(); RExecutorService executor = redisson.getExecutorService("test2", ExecutorOptions.defaults().taskRetryInterval(10, TimeUnit.SECONDS)); for (int i = 0; i < 10; i++) { executor.submit(new DelayedTask(2000, "counter")); } Thread.sleep(2500); assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(1); master.stop(); System.out.println("master " + master.getRedisServerAddressAndPort() + " stopped!"); Thread.sleep(TimeUnit.SECONDS.toMillis(70)); master = new RedisRunner() .port(master.getRedisServerPort()) .nosave() .randomDir() .run(); System.out.println("master " + master.getRedisServerAddressAndPort() + " started!"); Thread.sleep(25000); assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(10); redisson.shutdown(); node.shutdown(); sentinel1.stop(); sentinel2.stop(); sentinel3.stop(); master.stop(); slave1.stop(); slave2.stop(); }
Example 9
Source File: RedissonExecutorServiceTest.java From redisson with Apache License 2.0 | 4 votes |
@Test public void testNodeFailover() throws Exception { AtomicInteger counter = new AtomicInteger(); new MockUp<TasksRunnerService>() { @Mock private void finish(Invocation invocation, String requestId, boolean removeTask) { if (counter.incrementAndGet() > 1) { invocation.proceed(); } else { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } } }; Config config = createConfig(); RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config); nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1)); node.shutdown(); node = RedissonNode.create(nodeConfig); node.start(); RExecutorService executor = redisson.getExecutorService("test2", ExecutorOptions.defaults().taskRetryInterval(10, TimeUnit.SECONDS)); RExecutorFuture<?> f = executor.submit(new IncrementRunnableTask("counter")); assertThat(executor.getTaskCount()).isEqualTo(1); Thread.sleep(1000); assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(1); Thread.sleep(1000); System.out.println("shutdown"); node.shutdown(); assertThat(executor.getTaskCount()).isEqualTo(1); node = RedissonNode.create(nodeConfig); node.start(); assertThat(executor.getTaskCount()).isEqualTo(1); Thread.sleep(8500); assertThat(executor.getTaskCount()).isEqualTo(0); assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2); Thread.sleep(16000); assertThat(executor.getTaskCount()).isEqualTo(0); assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2); redisson.getKeys().delete("counter"); f.get(); assertThat(redisson.getKeys().count()).isEqualTo(1); }