FileDocCategorySizeDatePackage
ContentConsumer.javaAPI DocExample2051Sun Feb 01 01:44:20 GMT 1998dcj.util.Bandwidth

ContentConsumer

public class ContentConsumer extends Object
Source code from "Java Distributed Computing", by Jim Farley. Example: 8-4 ContentConsumer Description: A consumer of content streaming into an application.

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


     
    source = src;
  
public ContentConsumer(ContentConsumer dst)

    dest = dst;
  
Methods Summary
public booleanconsume(byte[] data)

    // Log the start of the consumption cycle.
    Date start = new Date();

    boolean success;
    success = preConsume(data);
    if (success)
      success = doConsume(data);
    if (success)
      success = postConsume(data);

    // Mark the end of our consumption cycle
    monitor.addSample(data.length, start, new Date());

    // Pass the data on to the next consumer in the chain,
    // if present.
    if (dest != null) {
      dest.consume(data);
    }

    return success;
  
public booleanconsumeAll()

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

    return success;
  
protected booleandoConsume(byte[] data)

    return true;
  
protected booleanpostConsume(byte[] data)

    return true;
  
protected booleanpreConsume(byte[] data)

    return true;
  
public voidsetDest(dcj.util.Bandwidth.ContentConsumer c)

    dest = c;
  
public voidsetSource(ContentProducer p)

    source = p;