comparison src/org/eclipse/jetty/io/EndPoint.java @ 978:bdb6eb0fbf93

simplify ChannelEndPoint
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 16 Oct 2016 14:53:43 -0600
parents 3428c60d7cfc
children 2b769da7f67d
comparison
equal deleted inserted replaced
977:d35b0a3a7a4a 978:bdb6eb0fbf93
17 // 17 //
18 18
19 package org.eclipse.jetty.io; 19 package org.eclipse.jetty.io;
20 20
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.nio.channels.SocketChannel;
22 23
23 24
24 /** 25 /**
25 * 26 *
26 * A transport EndPoint 27 * A transport EndPoint
27 */ 28 */
28 public interface EndPoint 29 public interface EndPoint
29 { 30 {
30 /** 31 /**
31 * Shutdown any backing output stream associated with the endpoint 32 * Shutdown any backing output stream associated with the endpoint
32 */ 33 */
33 void shutdownOutput() throws IOException; 34 void shutdownOutput() throws IOException;
34 35
35 boolean isOutputShutdown(); 36 boolean isOutputShutdown();
36 37
37 /** 38 /**
38 * Shutdown any backing input stream associated with the endpoint 39 * Shutdown any backing input stream associated with the endpoint
39 */ 40 */
40 void shutdownInput() throws IOException; 41 void shutdownInput() throws IOException;
41 42
42 boolean isInputShutdown(); 43 boolean isInputShutdown();
43 44
44 /** 45 /**
45 * Close any backing stream associated with the endpoint 46 * Close any backing stream associated with the endpoint
46 */ 47 */
47 void close() throws IOException; 48 void close() throws IOException;
48 49
49 /** 50 /**
50 * Fill the buffer from the current putIndex to it's capacity from whatever 51 * Fill the buffer from the current putIndex to it's capacity from whatever
51 * byte source is backing the buffer. The putIndex is increased if bytes filled. 52 * byte source is backing the buffer. The putIndex is increased if bytes filled.
52 * The buffer may chose to do a compact before filling. 53 * The buffer may chose to do a compact before filling.
53 * @return an <code>int</code> value indicating the number of bytes 54 * @return an <code>int</code> value indicating the number of bytes
54 * filled or -1 if EOF is reached. 55 * filled or -1 if EOF is reached.
55 * @throws EofException If input is shutdown or the endpoint is closed. 56 * @throws EofException If input is shutdown or the endpoint is closed.
56 */ 57 */
57 int fill(Buffer buffer) throws IOException; 58 int fill(Buffer buffer) throws IOException;
58 59
59 60
60 /** 61 /**
61 * Flush the buffer from the current getIndex to it's putIndex using whatever byte 62 * Flush the buffer from the current getIndex to it's putIndex using whatever byte
62 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed. 63 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
63 * Any mark set is cleared. 64 * Any mark set is cleared.
64 * If the entire contents of the buffer are flushed, then an implicit empty() is done. 65 * If the entire contents of the buffer are flushed, then an implicit empty() is done.
65 * 66 *
66 * @param buffer The buffer to flush. This buffers getIndex is updated. 67 * @param buffer The buffer to flush. This buffers getIndex is updated.
67 * @return the number of bytes written 68 * @return the number of bytes written
68 * @throws EofException If the endpoint is closed or output is shutdown. 69 * @throws EofException If the endpoint is closed or output is shutdown.
69 */ 70 */
70 int flush(Buffer buffer) throws IOException; 71 int flush(Buffer buffer) throws IOException;
71 72
72 /** 73 /**
73 * Flush the buffer from the current getIndex to it's putIndex using whatever byte 74 * Flush the buffer from the current getIndex to it's putIndex using whatever byte
74 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed. 75 * sink is backing the buffer. The getIndex is updated with the number of bytes flushed.
75 * Any mark set is cleared. 76 * Any mark set is cleared.
76 * If the entire contents of the buffer are flushed, then an implicit empty() is done. 77 * If the entire contents of the buffer are flushed, then an implicit empty() is done.
77 * The passed header/trailer buffers are written before/after the contents of this buffer. This may be done 78 * The passed header/trailer buffers are written before/after the contents of this buffer. This may be done
78 * either as gather writes, as a poke into this buffer or as several writes. The implementation is free to 79 * either as gather writes, as a poke into this buffer or as several writes. The implementation is free to
79 * select the optimal mechanism. 80 * select the optimal mechanism.
80 * @param header A buffer to write before flushing this buffer. This buffers getIndex is updated. 81 * @param header A buffer to write before flushing this buffer. This buffers getIndex is updated.
81 * @param buffer The buffer to flush. This buffers getIndex is updated. 82 * @param buffer The buffer to flush. This buffers getIndex is updated.
82 * @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated. 83 * @param trailer A buffer to write after flushing this buffer. This buffers getIndex is updated.
83 * @return the total number of bytes written. 84 * @return the total number of bytes written.
84 */ 85 */
85 int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException; 86 int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException;
86 87
87 88
88 /* ------------------------------------------------------------ */ 89 /* ------------------------------------------------------------ */
89 /** 90 /**
90 * @return The local IP address to which this <code>EndPoint</code> is bound, or <code>null</code> 91 * @return The local IP address to which this <code>EndPoint</code> is bound, or <code>null</code>
91 * if this <code>EndPoint</code> does not represent a network connection. 92 * if this <code>EndPoint</code> does not represent a network connection.
92 */ 93 */
93 public String getLocalAddr(); 94 public String getLocalAddr();
94 95
95 /* ------------------------------------------------------------ */ 96 /* ------------------------------------------------------------ */
96 /** 97 /**
97 * @return The local host name to which this <code>EndPoint</code> is bound, or <code>null</code> 98 * @return The local host name to which this <code>EndPoint</code> is bound, or <code>null</code>
98 * if this <code>EndPoint</code> does not represent a network connection. 99 * if this <code>EndPoint</code> does not represent a network connection.
99 */ 100 */
100 public String getLocalHost(); 101 public String getLocalHost();
101 102
102 /* ------------------------------------------------------------ */ 103 /* ------------------------------------------------------------ */
103 /** 104 /**
104 * @return The local port number on which this <code>EndPoint</code> is listening, or <code>0</code> 105 * @return The local port number on which this <code>EndPoint</code> is listening, or <code>0</code>
105 * if this <code>EndPoint</code> does not represent a network connection. 106 * if this <code>EndPoint</code> does not represent a network connection.
106 */ 107 */
107 public int getLocalPort(); 108 public int getLocalPort();
108 109
109 /* ------------------------------------------------------------ */ 110 /* ------------------------------------------------------------ */
110 /** 111 /**
111 * @return The remote IP address to which this <code>EndPoint</code> is connected, or <code>null</code> 112 * @return The remote IP address to which this <code>EndPoint</code> is connected, or <code>null</code>
112 * if this <code>EndPoint</code> does not represent a network connection. 113 * if this <code>EndPoint</code> does not represent a network connection.
113 */ 114 */
114 public String getRemoteAddr(); 115 public String getRemoteAddr();
115 116
116 /* ------------------------------------------------------------ */ 117 /* ------------------------------------------------------------ */
117 /** 118 /**
118 * @return The host name of the remote machine to which this <code>EndPoint</code> is connected, or <code>null</code> 119 * @return The host name of the remote machine to which this <code>EndPoint</code> is connected, or <code>null</code>
119 * if this <code>EndPoint</code> does not represent a network connection. 120 * if this <code>EndPoint</code> does not represent a network connection.
120 */ 121 */
121 public String getRemoteHost(); 122 public String getRemoteHost();
122 123
123 /* ------------------------------------------------------------ */ 124 /* ------------------------------------------------------------ */
124 /** 125 /**
125 * @return The remote port number to which this <code>EndPoint</code> is connected, or <code>0</code> 126 * @return The remote port number to which this <code>EndPoint</code> is connected, or <code>0</code>
126 * if this <code>EndPoint</code> does not represent a network connection. 127 * if this <code>EndPoint</code> does not represent a network connection.
127 */ 128 */
128 public int getRemotePort(); 129 public int getRemotePort();
129 130
130 /* ------------------------------------------------------------ */ 131 public boolean isBlocking();
131 public boolean isBlocking();
132 132
133 /* ------------------------------------------------------------ */ 133 public boolean blockReadable(long millisecs) throws IOException;
134 public boolean blockReadable(long millisecs) throws IOException;
135 134
136 /* ------------------------------------------------------------ */ 135 public boolean blockWritable(long millisecs) throws IOException;
137 public boolean blockWritable(long millisecs) throws IOException;
138 136
139 /* ------------------------------------------------------------ */ 137 public boolean isOpen();
140 public boolean isOpen();
141 138
142 /* ------------------------------------------------------------ */ 139 public SocketChannel getChannel();
143 /**
144 * @return The underlying transport object (socket, channel, etc.)
145 */
146 public Object getTransport();
147 140
148 /* ------------------------------------------------------------ */ 141 /* ------------------------------------------------------------ */
149 /** Flush any buffered output. 142 /** Flush any buffered output.
150 * May fail to write all data if endpoint is non-blocking 143 * May fail to write all data if endpoint is non-blocking
151 * @throws EofException If the endpoint is closed or output is shutdown. 144 * @throws EofException If the endpoint is closed or output is shutdown.
152 */ 145 */
153 public void flush() throws IOException; 146 public void flush() throws IOException;
154 147
155 /* ------------------------------------------------------------ */ 148 /* ------------------------------------------------------------ */
156 /** Get the max idle time in ms. 149 /** Get the max idle time in ms.
157 * <p>The max idle time is the time the endpoint can be idle before 150 * <p>The max idle time is the time the endpoint can be idle before
158 * extraordinary handling takes place. This loosely corresponds to 151 * extraordinary handling takes place. This loosely corresponds to
159 * the {@link java.net.Socket#getSoTimeout()} for blocking connections, 152 * the {@link java.net.Socket#getSoTimeout()} for blocking connections,
160 * but {@link AsyncEndPoint} implementations must use other mechanisms 153 * but {@link AsyncEndPoint} implementations must use other mechanisms
161 * to implement the max idle time. 154 * to implement the max idle time.
162 * @return the max idle time in ms or if ms <= 0 implies an infinite timeout 155 * @return the max idle time in ms or if ms <= 0 implies an infinite timeout
163 */ 156 */
164 public int getMaxIdleTime(); 157 public int getMaxIdleTime();
165 158
166 /* ------------------------------------------------------------ */ 159 /* ------------------------------------------------------------ */
167 /** Set the max idle time. 160 /** Set the max idle time.
168 * @param timeMs the max idle time in MS. Timeout <= 0 implies an infinite timeout 161 * @param timeMs the max idle time in MS. Timeout <= 0 implies an infinite timeout
169 * @throws IOException if the timeout cannot be set. 162 * @throws IOException if the timeout cannot be set.
170 */ 163 */
171 public void setMaxIdleTime(int timeMs) throws IOException; 164 public void setMaxIdleTime(int timeMs) throws IOException;
172 165
173 166
174 167
175 } 168 }