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 <a href="http://mina.apache.org">Apache MINA Project</a>
    32   */
    33  public interface ProtocolEncoderOutput {
    34      /**
    35       * Callback for {@link ProtocolEncoder} to generate an encoded message such
    36       * as an {@link IoBuffer}. {@link ProtocolEncoder} must call
    37       * {@link #write(Object)} for each encoded message.
    38       *
    39       * @param encodedMessage the encoded message, typically an {@link IoBuffer}
    40       *                       or a {@link FileRegion}.
    41       */
    42      void write(Object encodedMessage);
    43
    44      /**
    45       * Merges all buffers you wrote via {@link #write(Object)} into
    46       * one {@link IoBuffer} and replaces the old fragmented ones with it.
    47       * This method is useful when you want to control the way MINA generates
    48       * network packets.  Please note that this method only works when you
    49       * called {@link #write(Object)} method with only {@link IoBuffer}s.
    50       *
    51       * @throws IllegalStateException if you wrote something else than {@link IoBuffer}
    52       */
    53      void mergeAll();
    54
    55      /**
    56       * Flushes all buffers you wrote via {@link #write(Object)} to
    57       * the session.  This operation is asynchronous; please wait for
    58       * the returned {@link WriteFuture} if you want to wait for
    59       * the buffers flushed.
    60       *
    61       * @return <tt>null</tt> if there is nothing to flush at all.
    62       */
    63      WriteFuture flush();
    64  }