    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    import org.hornetq.api.core.TransportConfiguration;
    018
    019    /**
    020     * The connection used by a channel to write data to.
    021     *
    022     * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
    023     * @version <tt>$Revision$</tt>
    024     */
    025    public interface Connection
    026    {
    027       /**
    028        * Create a new HornetQBuffer of the given size.
    029        *
    030        * @param size the size of buffer to create
    031        * @return the new buffer.
    032        */
    033       HornetQBuffer createBuffer(int size);
    034
    035       /**
    036        * returns the unique id of this wire.
    037        *
    038        * @return the id
    039        */
    040       Object getID();
    041
    042       /**
    043        * writes the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.
    044        *
    045        * @param buffer the buffer to write
    046        * @param flush  whether to flush the buffers onto the wire
    047        * @param batched whether the packet is allowed to batched for better performance
    048        */
    049       void write(HornetQBuffer buffer, boolean flush, boolean batched);
    050
    051       /**
    052        * writes the buffer to the connection with no flushing or batching
    053        *
    054        * @param buffer the buffer to write
    055        */
    056       void write(HornetQBuffer buffer);
    057
    058       /**
    059        * closes this connection.
    060        */
    061       void close();
    062
    063       /**
    064        * returns a string representation of the remote address this connection is connected to.
    065        *
    066        * @return the remote address
    067        */
    068       String getRemoteAddress();
    069
    070       /**
    071        * Called periodically to flush any data in the batch buffer
    072        */
    073       void checkFlushBatchBuffer();
    074
    075       void addReadyListener(ReadyListener listener);
    076
    077       void removeReadyListener(ReadyListener listener);
    078
    079
    080       /**
    081        * Generates a {@link TransportConfiguration} to be use to connect to the
    082        * same target this is connect to
    083        * @return
    084        */
    085       TransportConfiguration getConnectorConfig();
    086
    087    }