当前位置: 首页>>代码示例>>Java>>正文


Java IncrementalTask类代码示例

本文整理汇总了Java中org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask的典型用法代码示例。如果您正苦于以下问题:Java IncrementalTask类的具体用法?Java IncrementalTask怎么用?Java IncrementalTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IncrementalTask类属于org.waveprotocol.wave.client.scheduler.Scheduler包,在下文中一共展示了IncrementalTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TimedTask

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
/**
 * A task that is to be run at the specified time, and then repeatedly each
 * time the specified interval has passed.
 *
 * @param time earliest time when the task should run
 * @param task The task to run
 * @param interval delay before the next time the task is to be run. Must be
 *        {@literal >= 0}. If {@link IncrementalTask#execute()} returns
 *        false, the task is not rerun again; Clients of this class must make
 *        sure that this eventually happens for tasks with an interval 0, as
 *        otherwise {@link FakeTimerService#tick(int)} will repeat the task
 *        indefinitely and never return.
 * @throws IllegalArgumentException if time or interval < 0
 */
TimedTask(int time, IncrementalTask task, int interval) {
  this.task = task;
  this.time = time;
  this.interval = interval;
  if (task == null) {
    throw new NullPointerException("null task");
  }
  if (time < 0) {
    throw new IllegalArgumentException("Expected time >= 0, got " + time);
  }
  if (interval < 0) {
    throw new IllegalArgumentException("Expected interval >= 0, got " + interval);
  }
  this.instanceNumber = instanceCount++;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:30,代码来源:FakeTimerService.java

示例2: testMultipleProcessesAtSameTime

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
/** Tests that multiple processes can be run at the same time. */
public void testMultipleProcessesAtSameTime() {
  final int time = 100;
  final IncrementalTask anotherTask = mock(IncrementalTask.class, "anotherTask");
  timer.scheduleRepeating(repeating, 0, time);
  timer.scheduleRepeating(anotherTask, time, time);

  checking(new Expectations() {{
    one(repeating).execute();
    will(returnValue(true));
  }});
  timer.tick(0);

  checking(new Expectations() {{
    one(repeating).execute();
    will(returnValue(true));
    one(anotherTask).execute();
    will(returnValue(true));
  }});
  timer.tick(time);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:22,代码来源:FakeTimerServiceTest.java

示例3: testCancellingAnIncrementalTaskDuringExecutionIgnoresContinueValue

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
public void testCancellingAnIncrementalTaskDuringExecutionIgnoresContinueValue() {
  IncrementalTask mock = new IncrementalTask() {
    boolean cancelled;
    @Override
    public boolean execute() {
      if (cancelled) {
        fail("Cancelled task was not removed from scheduler");
      }
      scheduler.cancel(this);
      cancelled = true;
      return true;
    }
  };

  scheduler.scheduleRepeating(Priority.LOW, mock, 0, 50);
  providedTimer.trigger();
  for (int i = 0; i < 50; i++) {
    providedTimer.trigger(1);
  }
  assertEmpty(true);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:22,代码来源:BrowserBackedSchedulerGwtTest.java

示例4: testRepeatingJobs

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
public void testRepeatingJobs() {

    final int[] intervals = new int[] { 30, 40, 70 };

    for (int i : intervals) {
      Scheduler.IncrementalTask p = new IntervalProcess(0, i);
      scheduler.scheduleRepeating(Priority.LOW, p, 0, i);
    }

    assertEmpty(false);

    for (int i = 0; i < 500; i++) {
      providedTimer.trigger();
      providedTimer.tick(1);
    }
  }
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:BrowserBackedSchedulerGwtTest.java

示例5: testTasksRepeatedlyRunningAtSameTimeAreScheduledFairly

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
/**
 * Tests that when there are several tasks with interval 0 running at the same time,
 * all of them are executed once before the first one is executed again.
 */
public void testTasksRepeatedlyRunningAtSameTimeAreScheduledFairly() {
  int taskCount = 10;
  final IncrementalTask[] tasks = new IncrementalTask[taskCount];
  for (int i = 0; i < taskCount; i++) {
    tasks[i] = mock(IncrementalTask.class, "repeating_" + i);
    if (i==0) {
      when(tasks[i].execute()).thenReturn(true, false);
    } else {
      when(tasks[i].execute()).thenReturn(false);
    }
    timer.scheduleRepeating(tasks[i], 1, 0);
  }

  InOrder inOrder = inOrder((Object[]) tasks);

  timer.tick(1);

  for (int i = 0; i < taskCount; i++) {
    inOrder.verify(tasks[i]).execute();
  }
  inOrder.verify(tasks[0]).execute();

  verify(tasks[0], times(2)).execute();
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:29,代码来源:FakeTimerServiceTest.java

示例6: build

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
public IdempotentScheduler build(IncrementalTask task) {
  Preconditions.checkNotNull(task, "task must not be null");

  // NOTE(user): this must be lazily created to avoid test dependency on SchedulerInstance.
  if (timer == null) {
    timer = SchedulerInstance.getLowPriorityTimer();
  }
  return new IdempotentScheduler(timer, task, recorder, interval);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:10,代码来源:IdempotentScheduler.java

示例7: IdempotentScheduler

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
private IdempotentScheduler(TimerService scheduler, IncrementalTask task,
    EfficiencyRecorder recorder, int interval) {
  this.scheduler = scheduler;
  this.task = task;
  this.recorder = recorder;
  this.interval = interval;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:8,代码来源:IdempotentScheduler.java

示例8: setUp

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
@Override
protected void setUp() {
  task = mock(IncrementalTask.class);
  timer = mock(TimerService.class);
  delay = 50;

  is = IdempotentScheduler.builder().with(timer).with(delay).build(task);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:9,代码来源:IdempotentSchedulerTest.java

示例9: tick

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
/**
 * Advances specified millis, running all tasks in between.
 *
 * @param millisToAdvance Number of milliseconds to advance the timer.
 */
public void tick(int millisToAdvance) {
  currentTime += millisToAdvance;
  while (!tasks.isEmpty() && tasks.peek().getTime() <= currentTime) {
    TimedTask timedTask = tasks.poll();
    IncrementalTask task = timedTask.getTask();
    boolean doReschedule = task.execute();
    if (doReschedule) {
      // Note: If the next execution is at or before currentTime, the task
      // will be re-executed before this tick() call returns.
      tasks.add(timedTask.nextExecution());
    }
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:19,代码来源:FakeTimerService.java

示例10: setUp

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();

  oneoff = mock(Task.class, "oneoff");
  repeating = mock(IncrementalTask.class, "repeating");
  timer = new FakeTimerService();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:9,代码来源:FakeTimerServiceTest.java

示例11: testRepeatingJob

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
public void testRepeatingJob() {
  Scheduler.IncrementalTask p = new IntervalProcess(0, 50);
  scheduler.scheduleRepeating(Priority.LOW, p, 0, 50);

  providedTimer.trigger();
  for (int i = 0; i < 200; i++) {
    providedTimer.trigger(1);
  }

  assertEmpty(false);

  scheduler.cancel(p);

  assertEmpty(true);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:16,代码来源:BrowserBackedSchedulerGwtTest.java

示例12: testCoincidingRepeatingJobs

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
public void testCoincidingRepeatingJobs() {
  for (int i = 0; i < 10; i++) {
    Scheduler.IncrementalTask p = new IntervalProcess(0, 50);
    scheduler.scheduleRepeating(Priority.LOW, p, 0, 50);
  }

  providedTimer.trigger();
  while (providedTimer.getTime() < 200) {
    providedTimer.trigger(1);
  }

  assertEmpty(false);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:14,代码来源:BrowserBackedSchedulerGwtTest.java

示例13: setUp

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();

  oneoff = mock(Task.class, "oneoff");
  repeating = mock(IncrementalTask.class, "repeating");
  when(repeating.execute()).thenReturn(true);
  timer = new FakeTimerService();
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:10,代码来源:FakeTimerServiceTest.java

示例14: testMultipleProcessesAtSameTime

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
/** Tests that multiple processes can be run at the same time. */
public void testMultipleProcessesAtSameTime() {
  final int time = 100;
  final IncrementalTask anotherTask = mock(IncrementalTask.class, "anotherTask");
  timer.scheduleRepeating(repeating, 0, time);
  timer.scheduleRepeating(anotherTask, time, time);

  timer.tick(0);
  verify(repeating, times(1)).execute();

  timer.tick(time);
  verify(repeating, times(2)).execute();
  verify(anotherTask, times(1)).execute();
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:15,代码来源:FakeTimerServiceTest.java

示例15: schedule

import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; //导入依赖的package包/类
@Override
public void schedule(IncrementalTask process) {
  throw new AssertionError("Not implemented");
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:5,代码来源:StubTimerService.java


注:本文中的org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。