001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.mina.filter.codec; 021 022import org.apache.mina.core.buffer.IoBuffer; 023import org.apache.mina.core.file.FileRegion; 024import org.apache.mina.core.future.WriteFuture; 025 026/** 027 * Callback for {@link ProtocolEncoder} to generate encoded messages such as 028 * {@link IoBuffer}s. {@link ProtocolEncoder} must call {@link #write(Object)} 029 * for each encoded message. 030 * 031 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 032 */ 033public interface ProtocolEncoderOutput { 034 /** 035 * Callback for {@link ProtocolEncoder} to generate an encoded message such 036 * as an {@link IoBuffer}. {@link ProtocolEncoder} must call 037 * {@link #write(Object)} for each encoded message. 038 * 039 * @param encodedMessage the encoded message, typically an {@link IoBuffer} 040 * or a {@link FileRegion}. 041 */ 042 void write(Object encodedMessage); 043 044 /** 045 * Merges all buffers you wrote via {@link #write(Object)} into 046 * one {@link IoBuffer} and replaces the old fragmented ones with it. 047 * This method is useful when you want to control the way MINA generates 048 * network packets. Please note that this method only works when you 049 * called {@link #write(Object)} method with only {@link IoBuffer}s. 050 * 051 * @throws IllegalStateException if you wrote something else than {@link IoBuffer} 052 */ 053 void mergeAll(); 054 055 /** 056 * Flushes all buffers you wrote via {@link #write(Object)} to 057 * the session. This operation is asynchronous; please wait for 058 * the returned {@link WriteFuture} if you want to wait for 059 * the buffers flushed. 060 * 061 * @return <tt>null</tt> if there is nothing to flush at all. 062 */ 063 WriteFuture flush(); 064}