org.redisson.api.RScheduledExecutorService Java Examples

The following examples show how to use org.redisson.api.RScheduledExecutorService. 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: SchedulerServiceExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: RedisJobScheduleImpl.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
@Override
public void pauseJob(String jobId) {
  RListMultimap<String, String> listmap = redissonClient.getListMultimap(Container.TASK_ID);
  RScheduledExecutorService service = redissonClient.getExecutorService(Container.WORKER);
  Iterator<String> it = listmap.get(jobId).iterator();
  while (it.hasNext()) {
    String id = it.next();
    service.cancelTask(id);
    it.remove();
  }
}
 
Example #3
Source File: RedissonCompletionService.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonCompletionService(RScheduledExecutorService executorService, BlockingQueue<RFuture<V>> completionQueue) {
    if (executorService == null) {
        throw new NullPointerException("executorService can't be null");
    }
    
    this.executorService = executorService;
    if (completionQueue == null) {
        completionQueue = new LinkedBlockingQueue<RFuture<V>>();
    }
    
    this.completionQueue = completionQueue;
}
 
Example #4
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RScheduledExecutorService getExecutorService(String name) {
  return redissonClient.getExecutorService(name);
}
 
Example #5
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RScheduledExecutorService getExecutorService(String name,
    ExecutorOptions options) {
  return redissonClient.getExecutorService(name, options);
}
 
Example #6
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public RScheduledExecutorService getExecutorService(
    Codec codec, String name) {
  return redissonClient.getExecutorService(codec, name);
}
 
Example #7
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RScheduledExecutorService getExecutorService(String name,
    Codec codec) {
  return redissonClient.getExecutorService(name, codec);
}
 
Example #8
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RScheduledExecutorService getExecutorService(String name,
    Codec codec, ExecutorOptions options) {
  return redissonClient.getExecutorService(name, codec, options);
}
 
Example #9
Source File: CoordinatorTask.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public Object call() throws Exception {
    long timeSpent = System.currentTimeMillis() - startTime;
    if (isTimeoutExpired(timeSpent)) {
        throw new MapReduceTimeoutException();
    }
    
    this.codec = (Codec) objectCodecClass.getConstructor().newInstance();
    
    RScheduledExecutorService executor = redisson.getExecutorService(RExecutorService.MAPREDUCE_NAME);
    int workersAmount = executor.countActiveWorkers();
    
    UUID id = UUID.randomUUID();
    String collectorMapName = objectName + ":collector:" + id;

    mapperTask.setCollectorMapName(collectorMapName);
    mapperTask.setWorkersAmount(workersAmount);
    timeSpent = System.currentTimeMillis() - startTime;
    if (isTimeoutExpired(timeSpent)) {
        throw new MapReduceTimeoutException();
    }
    if (timeout > 0) {
        mapperTask.setTimeout(timeout - timeSpent);
    }

    mapperTask.addObjectName(objectName);
    RFuture<?> mapperFuture = executor.submitAsync(mapperTask);
    try {
        if (timeout > 0 && !mapperFuture.await(timeout - timeSpent)) {
            mapperFuture.cancel(true);
            throw new MapReduceTimeoutException();
        }
        if (timeout == 0) {
            mapperFuture.await();
        }
    } catch (InterruptedException e) {
        mapperFuture.cancel(true);
        return null;
    }

    SubTasksExecutor reduceExecutor = new SubTasksExecutor(executor, workersAmount, startTime, timeout);
    for (int i = 0; i < workersAmount; i++) {
        String name = collectorMapName + ":" + i;
        Runnable runnable = new ReducerTask<KOut, VOut>(name, reducer, objectCodecClass, resultMapName, timeout - timeSpent);
        reduceExecutor.submit(runnable);
    }

    if (!reduceExecutor.await()) {
        return null;
    }
    
    return executeCollator();
}
 
Example #10
Source File: RedissonCompletionService.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonCompletionService(RScheduledExecutorService executorService) {
    this(executorService, null);
}