Mercurial > hg > jslab
view src/samer/tools/SubrateTask.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2001, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.tools; /** * This is a task that runs a single child task * every N iterations, that is, at some integer * sub-multiple of the main loop rate */ public class SubrateTask implements Task, java.io.Serializable { private Task task; private int factor; // subrate factor private int count; protected SubrateTask() {} public SubrateTask(int f) { factor=f; } public SubrateTask(int f, Task t) { factor=f; task=t; count=factor; } public int getFactor() { return factor; } public void setFactor(int f) { factor=(f==0? 1 : f); // at least 1 if (count>factor) count=factor; // cut short current batch } public void setTask(Task t) { task=t; } public Task getTask() { return task; } public final void starting() { task.starting(); count=factor; } public final void stopping() { task.stopping(); } public final void run() throws Exception { if ((--count)<=0) { task.run(); count=factor; } } public void dispose() { task.dispose(); } public String toString() { return "Subrate("+factor+"):"+task; } }