View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.filter.codec;
21  
22  import org.apache.mina.core.buffer.IoBuffer;
23  import org.apache.mina.core.file.FileRegion;
24  import org.apache.mina.core.future.WriteFuture;
25  
26  /**
27   * Callback for {@link ProtocolEncoder} to generate encoded messages such as
28   * {@link IoBuffer}s.  {@link ProtocolEncoder} must call {@link #write(Object)}
29   * for each encoded message.
30   *
31   * @author The Apache MINA Project (dev@mina.apache.org)
32   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
33   */
34  public interface ProtocolEncoderOutput {
35      /**
36       * Callback for {@link ProtocolEncoder} to generate an encoded message such
37       * as an {@link IoBuffer}. {@link ProtocolEncoder} must call
38       * {@link #write(Object)} for each encoded message.
39       *
40       * @param encodedMessage the encoded message, typically an {@link IoBuffer}
41       *                       or a {@link FileRegion}.
42       */
43      void write(Object encodedMessage);
44  
45      /**
46       * Merges all buffers you wrote via {@link #write(Object)} into
47       * one {@link IoBuffer} and replaces the old fragmented ones with it.
48       * This method is useful when you want to control the way MINA generates
49       * network packets.  Please note that this method only works when you
50       * called {@link #write(Object)} method with only {@link IoBuffer}s.
51       * 
52       * @throws IllegalStateException if you wrote something else than {@link IoBuffer}
53       */
54      void mergeAll();
55  
56      /**
57       * Flushes all buffers you wrote via {@link #write(Object)} to
58       * the session.  This operation is asynchronous; please wait for
59       * the returned {@link WriteFuture} if you want to wait for
60       * the buffers flushed.
61       *
62       * @return <tt>null</tt> if there is nothing to flush at all.
63       */
64      WriteFuture flush();
65  }