001    /*
002     * Copyright 2009 Red Hat, Inc.
003     * Red Hat licenses this file to you under the Apache License, version
004     * 2.0 (the "License"); you may not use this file except in compliance
005     * with the License.  You may obtain a copy of the License at
006     *    http://www.apache.org/licenses/LICENSE-2.0
007     * Unless required by applicable law or agreed to in writing, software
008     * distributed under the License is distributed on an "AS IS" BASIS,
009     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
010     * implied.  See the License for the specific language governing
011     * permissions and limitations under the License.
012     */
013    
014    package org.hornetq.spi.core.remoting;
015    
016    import org.hornetq.api.core.HornetQBuffer;
017    
018    /**
019     * The connection used by a channel to write data to.
020     *
021     * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
022     * @version <tt>$Revision$</tt>
023     */
024    public interface Connection
025    {
026       /**
027        * Create a new HornetQBuffer of the given size.
028        *
029        * @param size the size of buffer to create
030        * @return the new buffer.
031        */
032       HornetQBuffer createBuffer(int size);
033    
034       /**
035        * returns the unique id of this wire.
036        *
037        * @return the id
038        */
039       Object getID();
040    
041       /**
042        * writes the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.
043        *
044        * @param buffer the buffer to write
045        * @param flush  whether to flush the buffers onto the wire
046        * @param batched whether the packet is allowed to batched for better performance
047        */
048       void write(HornetQBuffer buffer, boolean flush, boolean batched);
049       
050       /**
051        * writes the buffer to the connection with no flushing or batching
052        *
053        * @param buffer the buffer to write
054        */
055       void write(HornetQBuffer buffer);
056    
057       /**
058        * closes this connection.
059        */
060       void close();
061    
062       /**
063        * returns a string representation of the remote address this connection is connected to.
064        *
065        * @return the remote address
066        */
067       String getRemoteAddress();
068       
069       /**
070        * Called periodically to flush any data in the batch buffer
071        */
072       void checkFlushBatchBuffer();
073    }