FileDocCategorySizeDatePackage
ContentProducer.javaAPI DocExample2374Sun Feb 01 01:46:46 GMT 1998dcj.util.Bandwidth

ContentProducer

public class ContentProducer extends Object
Source code from "Java Distributed Computing", by Jim Farley. Class: ContentProducer Example: 8-5 Description: A producer of content. The source may be a network connection, a disk file, etc.

Fields Summary
protected ContentProducer
source
protected ContentConsumer
dest
protected DataMonitor
monitor
Constructors Summary
public ContentProducer(ContentProducer src)


     
    source = src;
  
public ContentProducer(ContentConsumer dst)

    dest = dst;
  
Methods Summary
protected byte[]doProduction(long limit)

    byte[] data = null;
    if (source != null) {
      data = source.produce(limit);
    }

    return data;
  
protected booleanpostProduction(byte[] data, long limit)

    return true;
  
protected booleanpreProduction(long limit)

    return true;
  
public byte[]produce(long limit)

    // Record the start time.
    Date start = new Date();

    boolean success;
    byte[] data = null;
    success = preProduction(limit);
    if (success)
      data = doProduction(limit);
    if (success && data != null)
      success = postProduction(data, limit);

    // Record the data sample in our monitor.
    monitor.addSample(data.length, start, new Date());

    // Pass the data on to our destination, if present
    if (data != null && dest != null)
      dest.consume(data);

    return data;
  
public booleanproduceAll()

    boolean success = false;
    if (dest != null) {
      byte[] data = produce(0);
      while (data != null) {
        success = dest.consume(data);
        if (success)
          data = produce(0);
        else
          data = null;
      }
    }

    return success;
  
public voidsetDest(ContentConsumer c)

    dest = c;
  
public voidsetSource(dcj.util.Bandwidth.ContentProducer p)

    source = p;