Mercurial > hg > jslab
annotate src/samer/tools/SubrateTask.java @ 3:15b93db27c04
Get StreamSource to compile, update args for demo
author | samer |
---|---|
date | Fri, 05 Apr 2019 17:00:18 +0100 |
parents | bf79fb79ee13 |
children |
rev | line source |
---|---|
samer@0 | 1 /* |
samer@0 | 2 * Copyright (c) 2001, Samer Abdallah, King's College London. |
samer@0 | 3 * All rights reserved. |
samer@0 | 4 * |
samer@0 | 5 * This software is provided AS iS and WITHOUT ANY WARRANTY; |
samer@0 | 6 * without even the implied warranty of MERCHANTABILITY or |
samer@0 | 7 * FITNESS FOR A PARTICULAR PURPOSE. |
samer@0 | 8 */ |
samer@0 | 9 |
samer@0 | 10 package samer.tools; |
samer@0 | 11 |
samer@0 | 12 /** |
samer@0 | 13 * This is a task that runs a single child task |
samer@0 | 14 * every N iterations, that is, at some integer |
samer@0 | 15 * sub-multiple of the main loop rate |
samer@0 | 16 */ |
samer@0 | 17 |
samer@0 | 18 public class SubrateTask implements Task, java.io.Serializable |
samer@0 | 19 { |
samer@0 | 20 private Task task; |
samer@0 | 21 private int factor; // subrate factor |
samer@0 | 22 private int count; |
samer@0 | 23 |
samer@0 | 24 protected SubrateTask() {} |
samer@0 | 25 public SubrateTask(int f) { factor=f; } |
samer@0 | 26 public SubrateTask(int f, Task t) { factor=f; task=t; count=factor; } |
samer@0 | 27 |
samer@0 | 28 public int getFactor() { return factor; } |
samer@0 | 29 public void setFactor(int f) { |
samer@0 | 30 factor=(f==0? 1 : f); // at least 1 |
samer@0 | 31 if (count>factor) count=factor; // cut short current batch |
samer@0 | 32 } |
samer@0 | 33 |
samer@0 | 34 public void setTask(Task t) { task=t; } |
samer@0 | 35 public Task getTask() { return task; } |
samer@0 | 36 |
samer@0 | 37 public final void starting() { task.starting(); count=factor; } |
samer@0 | 38 public final void stopping() { task.stopping(); } |
samer@0 | 39 public final void run() throws Exception { |
samer@0 | 40 if ((--count)<=0) { task.run(); count=factor; } |
samer@0 | 41 } |
samer@0 | 42 |
samer@0 | 43 public void dispose() { task.dispose(); } |
samer@0 | 44 public String toString() { return "Subrate("+factor+"):"+task; } |
samer@0 | 45 } |