1 /* 2 * Copyright 2009 Red Hat, Inc. 3 * 4 * Red Hat licenses this file to you under the Apache License, version 2.0 5 * (the "License"); you may not use this file except in compliance with the 6 * License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package org.jboss.netty.handler.codec.embedder; 17 18 import java.util.Collection; 19 20 /** 21 * A helper that wraps an encoder or a decoder (codec) so that they can be used 22 * without doing actual I/O in unit tests or higher level codecs. Please refer 23 * to {@link EncoderEmbedder} and {@link DecoderEmbedder} for more information. 24 * 25 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a> 26 * @author <a href="http://gleamynode.net/">Trustin Lee</a> 27 * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $ 28 */ 29 public interface CodecEmbedder<E> { 30 /** 31 * Offers an input object to the pipeline of this embedder. 32 * 33 * @return {@code true} if and only if there is something to read in the 34 * product queue (see {@link #poll()} and {@link #peek()}) 35 */ 36 boolean offer(Object input); 37 38 /** 39 * Signals the pipeline that the encoding or decoding has been finished and 40 * no more data will be offered. 41 * 42 * @return {@code true} if and only if there is something to read in the 43 * product queue (see {@link #poll()} and {@link #peek()}) 44 */ 45 boolean finish(); 46 47 /** 48 * Consumes an encoded or decoded output from the product queue. The output 49 * object is generated by the offered input objects. 50 * 51 * @return an encoded or decoded object. 52 * {@code null} if and only if there is no output object left in the 53 * product queue. 54 */ 55 E poll(); 56 57 /** 58 * Reads an encoded or decoded output from the head of the product queue. 59 * The difference from {@link #poll()} is that it does not remove the 60 * retrieved object from the product queue. 61 * 62 * @return an encoded or decoded object. 63 * {@code null} if and only if there is no output object left in the 64 * product queue. 65 */ 66 E peek(); 67 68 /** 69 * Consumes all encoded or decoded output from the product queue. The 70 * output object is generated by the offered input objects. The behavior 71 * of this method is identical with {@link Collection#toArray()} except that 72 * the product queue is cleared. 73 * 74 * @return an array of all encoded or decoded objects. 75 * An empty array is returned if and only if there is no output 76 * object left in the product queue. 77 */ 78 Object[] pollAll(); 79 80 /** 81 * Consumes all encoded or decoded output from the product queue. The 82 * output object is generated by the offered input objects. The behavior 83 * of this method is identical with {@link Collection#toArray(Object[])} 84 * except that the product queue is cleared. 85 * 86 * @return an array of all encoded or decoded objects. 87 * An empty array is returned if and only if there is no output 88 * object left in the product queue. 89 */ 90 <T> T[] pollAll(T[] a); 91 92 /** 93 * Returns the number of encoded or decoded output in the product queue. 94 */ 95 int size(); 96 }