當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。