/** * Overrides {@link FileJob#jobPaused()} to pause any file processing * by having the source InputStream's read methods lock. */ @Override protected void jobPaused() { super.jobPaused(); synchronized(this) { if(tlin !=null) tlin.setThroughputLimit(0); } }
/** * Overrides {@link FileJob#jobResumed()} to resume any file processing by releasing * the lock on the source InputStream's read methods. */ @Override protected void jobResumed() { super.jobResumed(); synchronized(this) { // Restore previous throughput limit (if any, -1 by default) if(tlin !=null) tlin.setThroughputLimit(throughputLimit); } }
/** * Sets a transfer throughput limit in bytes per seconds, replacing any previous limit. * This limit corresponds to the number of bytes that can be read from a registered InputStream. * * <p>Specifying 0 or -1 disables any throughput limit, the transfer will be carried out at full speed. * * <p>If this job is paused, the new limit will be effective after the job has been resumed. * If not, it will be effective immediately. * * @param bytesPerSecond new throughput limit in bytes per second, 0 or -1 to disable the limit */ public void setThroughputLimit(long bytesPerSecond) { // Note: ThroughputInputStream interprets 0 as a complete pause (blocks reads) which is different // from what a user would expect when specifying 0 as a limit this.throughputLimit = bytesPerSecond<=0?-1:bytesPerSecond; synchronized(this) { if(getState() != FileJobState.PAUSED && tlin !=null) tlin.setThroughputLimit(throughputLimit); } }