001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.port;
030:
031: import com.caucho.server.connection.Connection;
032:
033: import java.net.InetAddress;
034: import java.nio.channels.SelectableChannel;
035:
036: /**
037: * Represents a protocol-independent connection. Prococol servers and
038: * their associated Requests use Connection to retrieve the read and
039: * write streams and to get information about the connection.
040: *
041: * <p>TcpConnection is the most common implementation. The test harness
042: * provides a string based Connection.
043: */
044: public abstract class PortConnection extends Connection {
045: private static int _connectionCount;
046:
047: private Port _port;
048:
049: private ServerRequest _request;
050:
051: private int _connectionId; // The connection's id
052: private long _accessTime; // Time the current request started
053:
054: /**
055: * Creates a new connection
056: */
057: protected PortConnection() {
058: synchronized (PortConnection.class) {
059: _connectionId = _connectionCount++;
060: }
061: }
062:
063: /**
064: * Returns the connection id. Primarily for debugging.
065: */
066: public int getId() {
067: return _connectionId;
068: }
069:
070: /**
071: * Returns the port which generated the connection.
072: */
073: public Port getPort() {
074: return _port;
075: }
076:
077: /**
078: * Sets the connection's port.
079: */
080: public void setPort(Port port) {
081: _port = port;
082: }
083:
084: /**
085: * Returns the request for the connection.
086: */
087: public final ServerRequest getRequest() {
088: return _request;
089: }
090:
091: /**
092: * Sets the connection's request.
093: */
094: public final void setRequest(ServerRequest request) {
095: _request = request;
096: }
097:
098: /**
099: * Returns true if secure (ssl)
100: */
101: public boolean isSecure() {
102: return false;
103: }
104:
105: /**
106: * Returns the static virtual host
107: */
108: public String getVirtualHost() {
109: return null;
110: }
111:
112: /**
113: * Returns the local address of the connection
114: */
115: public abstract InetAddress getLocalAddress();
116:
117: /**
118: * Returns the local port of the connection
119: */
120: public abstract int getLocalPort();
121:
122: /**
123: * Returns the remote address of the connection
124: */
125: public abstract InetAddress getRemoteAddress();
126:
127: /**
128: * Returns the remove port of the connection
129: */
130: public abstract int getRemotePort();
131:
132: /**
133: * Sets the time of the request start. ServerRequests can use
134: * setAccessTime() to put off connection reaping. HttpRequest calls
135: * setAccessTime() at the beginning of each request.
136: *
137: * @param now the current time in milliseconds as by Alarm.getCurrentTime().
138: */
139: public void setAccessTime(long now) {
140: _accessTime = now;
141: }
142:
143: /**
144: * Returns the time the last Request began in milliseconds.
145: */
146: public long getAccessTime() {
147: return _accessTime;
148: }
149:
150: /**
151: * Returns the selectable channel.
152: */
153: public SelectableChannel getSelectableChannel() {
154: throw new UnsupportedOperationException();
155: }
156:
157: /**
158: * Closes the connection()
159: */
160: public void close() {
161: }
162: }
|