001: //========================================================================
002: //$Id: Connector.java,v 1.7 2005/11/25 21:01:45 gregwilkins 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.jetty;
017:
018: import java.io.IOException;
019:
020: import org.mortbay.component.LifeCycle;
021: import org.mortbay.io.Buffers;
022: import org.mortbay.io.EndPoint;
023: import org.mortbay.util.ajax.Continuation;
024:
025: /** HTTP Connector.
026: * Implementations of this interface provide connectors for the HTTP protocol.
027: * A connector receives requests (normally from a socket) and calls the
028: * handle method of the Handler object. These operations are performed using
029: * threads from the ThreadPool set on the connector.
030: *
031: * When a connector is registered with an instance of Server, then the server
032: * will set itself as both the ThreadPool and the Handler. Note that a connector
033: * can be used without a Server if a thread pool and handler are directly provided.
034: *
035: * @author gregw
036: *
037: */
038: public interface Connector extends LifeCycle, Buffers {
039: /* ------------------------------------------------------------ */
040: /**
041: * @return the name of the connector. Defaults to the HostName:port
042: */
043: String getName();
044:
045: /* ------------------------------------------------------------ */
046: /**
047: * Opens the connector
048: * @throws IOException
049: */
050: void open() throws IOException;
051:
052: void close() throws IOException;
053:
054: void setServer(Server server);
055:
056: Server getServer();
057:
058: /* ------------------------------------------------------------ */
059: /**
060: * @return Returns the headerBufferSize.
061: */
062: int getHeaderBufferSize();
063:
064: /* ------------------------------------------------------------ */
065: /**
066: * Set the size of the buffer to be used for request and response headers.
067: * An idle connection will at most have one buffer of this size allocated.
068: * @param headerBufferSize The headerBufferSize to set.
069: */
070: void setHeaderBufferSize(int headerBufferSize);
071:
072: /* ------------------------------------------------------------ */
073: /**
074: * @return Returns the requestBufferSize.
075: */
076: int getRequestBufferSize();
077:
078: /* ------------------------------------------------------------ */
079: /**
080: * Set the size of the content buffer for receiving requests.
081: * These buffers are only used for active connections that have
082: * requests with bodies that will not fit within the header buffer.
083: * @param requestBufferSize The requestBufferSize to set.
084: */
085: void setRequestBufferSize(int requestBufferSize);
086:
087: /* ------------------------------------------------------------ */
088: /**
089: * @return Returns the responseBufferSize.
090: */
091: int getResponseBufferSize();
092:
093: /* ------------------------------------------------------------ */
094: /**
095: * Set the size of the content buffer for sending responses.
096: * These buffers are only used for active connections that are sending
097: * responses with bodies that will not fit within the header buffer.
098: * @param responseBufferSize The responseBufferSize to set.
099: */
100: void setResponseBufferSize(int responseBufferSize);
101:
102: /* ------------------------------------------------------------ */
103: int getIntegralPort();
104:
105: String getIntegralScheme();
106:
107: boolean isIntegral(Request request);
108:
109: /* ------------------------------------------------------------ */
110: int getConfidentialPort();
111:
112: String getConfidentialScheme();
113:
114: boolean isConfidential(Request request);
115:
116: /* ------------------------------------------------------------ */
117: /** Customize a request for an endpoint.
118: * Called on every request to allow customization of the request for
119: * the particular endpoint (eg security properties from a SSL connection).
120: * @param endpoint
121: * @param request
122: * @throws IOException
123: */
124: void customize(EndPoint endpoint, Request request)
125: throws IOException;
126:
127: /* ------------------------------------------------------------ */
128: /** Persist an endpoint.
129: * Called after every request if the connection is to remain open.
130: * @param endpoint
131: * @param request
132: * @throws IOException
133: */
134: void persist(EndPoint endpoint) throws IOException;
135:
136: Continuation newContinuation();
137:
138: String getHost();
139:
140: void setHost(String hostname);
141:
142: /* ------------------------------------------------------------ */
143: /**
144: * @param port The port fto listen of for connections or 0 if any available
145: * port may be used.
146: */
147: void setPort(int port);
148:
149: /* ------------------------------------------------------------ */
150: /**
151: * @return The configured port for the connector or 0 if any available
152: * port may be used.
153: */
154: int getPort();
155:
156: /* ------------------------------------------------------------ */
157: /**
158: * @return The actual port the connector is listening on or -1 if there
159: * is no port or the connector is not open.
160: */
161: int getLocalPort();
162:
163: /* ------------------------------------------------------------ */
164: int getMaxIdleTime();
165:
166: void setMaxIdleTime(int ms);
167:
168: /* ------------------------------------------------------------ */
169: int getLowResourceMaxIdleTime();
170:
171: void setLowResourceMaxIdleTime(int ms);
172:
173: /* ------------------------------------------------------------ */
174: /**
175: * @return the underlying socket, channel, buffer etc. for the connector.
176: */
177: Object getConnection();
178:
179: /* ------------------------------------------------------------ */
180: /**
181: * @return true if names resolution should be done.
182: */
183: boolean getResolveNames();
184:
185: /* ------------------------------------------------------------ */
186: /**
187: * @return Get the number of requests handled by this connector
188: * since last call of statsReset(). If setStatsOn(false) then this
189: * is undefined.
190: */
191: public int getRequests();
192:
193: /* ------------------------------------------------------------ */
194: /**
195: * @return Returns the connectionsDurationMin.
196: */
197: public long getConnectionsDurationMin();
198:
199: /* ------------------------------------------------------------ */
200: /**
201: * @return Returns the connectionsDurationTotal.
202: */
203: public long getConnectionsDurationTotal();
204:
205: /* ------------------------------------------------------------ */
206: /**
207: * @return Returns the connectionsOpenMin.
208: */
209: public int getConnectionsOpenMin();
210:
211: /* ------------------------------------------------------------ */
212: /**
213: * @return Returns the connectionsRequestsMin.
214: */
215: public int getConnectionsRequestsMin();
216:
217: /* ------------------------------------------------------------ */
218: /**
219: * @return Number of connections accepted by the server since
220: * statsReset() called. Undefined if setStatsOn(false).
221: */
222: public int getConnections();
223:
224: /* ------------------------------------------------------------ */
225: /**
226: * @return Number of connections currently open that were opened
227: * since statsReset() called. Undefined if setStatsOn(false).
228: */
229: public int getConnectionsOpen();
230:
231: /* ------------------------------------------------------------ */
232: /**
233: * @return Maximum number of connections opened simultaneously
234: * since statsReset() called. Undefined if setStatsOn(false).
235: */
236: public int getConnectionsOpenMax();
237:
238: /* ------------------------------------------------------------ */
239: /**
240: * @return Average duration in milliseconds of open connections
241: * since statsReset() called. Undefined if setStatsOn(false).
242: */
243: public long getConnectionsDurationAve();
244:
245: /* ------------------------------------------------------------ */
246: /**
247: * @return Maximum duration in milliseconds of an open connection
248: * since statsReset() called. Undefined if setStatsOn(false).
249: */
250: public long getConnectionsDurationMax();
251:
252: /* ------------------------------------------------------------ */
253: /**
254: * @return Average number of requests per connection
255: * since statsReset() called. Undefined if setStatsOn(false).
256: */
257: public int getConnectionsRequestsAve();
258:
259: /* ------------------------------------------------------------ */
260: /**
261: * @return Maximum number of requests per connection
262: * since statsReset() called. Undefined if setStatsOn(false).
263: */
264: public int getConnectionsRequestsMax();
265:
266: /* ------------------------------------------------------------ */
267: /** Reset statistics.
268: */
269: public void statsReset();
270:
271: /* ------------------------------------------------------------ */
272: public void setStatsOn(boolean on);
273:
274: /* ------------------------------------------------------------ */
275: /**
276: * @return True if statistics collection is turned on.
277: */
278: public boolean getStatsOn();
279:
280: /* ------------------------------------------------------------ */
281: /**
282: * @return Timestamp stats were started at.
283: */
284: public long getStatsOnMs();
285:
286: }
|