001: //========================================================================
002: //$Id: EndPoint.java,v 1.1 2005/10/05 14:09:25 janb Exp $
003: //Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.mortbay.io;
017:
018: import java.io.IOException;
019:
020: /**
021: * @author gregw
022: * A transport EndPoint
023: */
024: public interface EndPoint {
025:
026: /**
027: * Close any backing stream associated with the buffer
028: */
029: void close() throws IOException;
030:
031: /**
032: * Fill the buffer from the current putIndex to it's capacity from whatever
033: * byte source is backing the buffer. The putIndex is increased if bytes filled.
034: * The buffer may chose to do a compact before filling.
035: * @return an <code>int</code> value indicating the number of bytes
036: * filled or -1 if EOF is reached.
037: */
038: int fill(Buffer buffer) throws IOException;
039:
040: /**
041: * Flush the buffer from the current getIndex to it's putIndex using whatever byte
042: * sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
043: * Any mark set is cleared.
044: * If the entire contents of the buffer are flushed, then an implicit empty() is done.
045: *
046: * @param buffer The buffer to flush. This buffers getIndex is updated.
047: * @return the number of bytes written
048: */
049: int flush(Buffer buffer) throws IOException;
050:
051: /**
052: * Flush the buffer from the current getIndex to it's putIndex using whatever byte
053: * sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
054: * Any mark set is cleared.
055: * If the entire contents of the buffer are flushed, then an implicit empty() is done.
056: * The passed header/trailer buffers are written before/after the contents of this buffer. This may be done
057: * either as gather writes, as a poke into this buffer or as several writes. The implementation is free to
058: * select the optimal mechanism.
059: * @param header A buffer to write before flushing this buffer. This buffers getIndex is updated.
060: * @param buffer The buffer to flush. This buffers getIndex is updated.
061: * @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated.
062: * @return the total number of bytes written.
063: */
064: int flush(Buffer header, Buffer buffer, Buffer trailer)
065: throws IOException;
066:
067: /* ------------------------------------------------------------ */
068: /**
069: * @return The local IP address to which this <code>EndPoint</code> is bound, or <code>null</code>
070: * if this <code>EndPoint</code> does not represent a network connection.
071: */
072: public String getLocalAddr();
073:
074: /* ------------------------------------------------------------ */
075: /**
076: * @return The local host name to which this <code>EndPoint</code> is bound, or <code>null</code>
077: * if this <code>EndPoint</code> does not represent a network connection.
078: */
079: public String getLocalHost();
080:
081: /* ------------------------------------------------------------ */
082: /**
083: * @return The local port number on which this <code>EndPoint</code> is listening, or <code>0</code>
084: * if this <code>EndPoint</code> does not represent a network connection.
085: */
086: public int getLocalPort();
087:
088: /* ------------------------------------------------------------ */
089: /**
090: * @return The remote IP address to which this <code>EndPoint</code> is connected, or <code>null</code>
091: * if this <code>EndPoint</code> does not represent a network connection.
092: */
093: public String getRemoteAddr();
094:
095: /* ------------------------------------------------------------ */
096: /**
097: * @return The host name of the remote machine to which this <code>EndPoint</code> is connected, or <code>null</code>
098: * if this <code>EndPoint</code> does not represent a network connection.
099: */
100: public String getRemoteHost();
101:
102: /* ------------------------------------------------------------ */
103: /**
104: * @return The remote port number to which this <code>EndPoint</code> is connected, or <code>0</code>
105: * if this <code>EndPoint</code> does not represent a network connection.
106: */
107: public int getRemotePort();
108:
109: /* ------------------------------------------------------------ */
110: public boolean isBlocking();
111:
112: /* ------------------------------------------------------------ */
113: public boolean isBufferred();
114:
115: /* ------------------------------------------------------------ */
116: public boolean blockReadable(long millisecs) throws IOException;
117:
118: /* ------------------------------------------------------------ */
119: public boolean blockWritable(long millisecs) throws IOException;
120:
121: /* ------------------------------------------------------------ */
122: public boolean isOpen();
123:
124: /* ------------------------------------------------------------ */
125: /**
126: * @return The underlying transport object (socket, channel, etc.)
127: */
128: public Object getTransport();
129:
130: /* ------------------------------------------------------------ */
131: /**
132: * @return True if the endpoint has some buffered input data
133: */
134: public boolean isBufferingInput();
135:
136: /* ------------------------------------------------------------ */
137: /**
138: * @return True if the endpoint has some buffered output data
139: */
140: public boolean isBufferingOutput();
141:
142: /* ------------------------------------------------------------ */
143: /** Flush any buffered output.
144: * May fail to write all data if endpoint is non-blocking
145: * @throws IOException
146: */
147: public void flush() throws IOException;
148:
149: }
|