DataConsumer.java 1.45 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
11

Matt Tucker's avatar
Matt Tucker committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
package org.jivesoftware.net;

import java.nio.ByteBuffer;

/**
 * <p>DataConsumers consume data, optionally passing it along to downstream
 * consumers.</p>
 *
 * <p>Consumers can either obtain their data from a producer using consumeAll()
 * or can be pushed data using their consume method. They may also be chained
 * by setting a data sink allowing consumers to be chained.</p>
 *
 * @author Iain Shigeoka
 */
public interface DataConsumer {
27

Matt Tucker's avatar
Matt Tucker committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    /**
     * <p>Set a data producer as a source of data when using the consumeAll()
     * method.</p>
     *
     * @param source The producer that will source data to this consumer
     * or null for no producer
     */
    void setSource(DataProducer source);

    /**
     * Set a downstream data consumer as a sink for data creating a consumer
     * chain.
     *
     * @param sink The consumer that will consume the data after this consumer
     * or null if there is no downstream consumer
     */
    void setSink(DataConsumer sink);

    /**
     * Consume data from the producer until the producer returns null (no data).
     */
    void consumeAll();

    /**
     * Consume the given data.
     *
     * @param data The data to consume
     */
    void consume(ByteBuffer data);
57
}