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