KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > port > PortConnection


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.port;
30
31 import com.caucho.server.connection.Connection;
32
33 import java.net.InetAddress JavaDoc;
34 import java.nio.channels.SelectableChannel JavaDoc;
35
36 /**
37  * Represents a protocol-independent connection. Prococol servers and
38  * their associated Requests use Connection to retrieve the read and
39  * write streams and to get information about the connection.
40  *
41  * <p>TcpConnection is the most common implementation. The test harness
42  * provides a string based Connection.
43  */

44 public abstract class PortConnection extends Connection
45 {
46   private static int _connectionCount;
47
48   private Port _port;
49
50   private ServerRequest _request;
51
52   private int _connectionId; // The connection's id
53
private long _accessTime; // Time the current request started
54

55   /**
56    * Creates a new connection
57    */

58   protected PortConnection()
59   {
60     synchronized (PortConnection.class) {
61       _connectionId = _connectionCount++;
62     }
63   }
64
65   /**
66    * Returns the connection id. Primarily for debugging.
67    */

68   public int getId()
69   {
70     return _connectionId;
71   }
72
73   /**
74    * Returns the port which generated the connection.
75    */

76   public Port getPort()
77   {
78     return _port;
79   }
80
81   /**
82    * Sets the connection's port.
83    */

84   public void setPort(Port port)
85   {
86     _port = port;
87   }
88
89   /**
90    * Returns the request for the connection.
91    */

92   public final ServerRequest getRequest()
93   {
94     return _request;
95   }
96
97   /**
98    * Sets the connection's request.
99    */

100   public final void setRequest(ServerRequest request)
101   {
102     _request = request;
103   }
104
105   /**
106    * Returns true if secure (ssl)
107    */

108   public boolean isSecure()
109   {
110     return false;
111   }
112   /**
113    * Returns the static virtual host
114    */

115   public String JavaDoc getVirtualHost()
116   {
117     return null;
118   }
119   
120   /**
121    * Returns the local address of the connection
122    */

123   public abstract InetAddress JavaDoc getLocalAddress();
124
125   /**
126    * Returns the local port of the connection
127    */

128   public abstract int getLocalPort();
129
130   /**
131    * Returns the remote address of the connection
132    */

133   public abstract InetAddress JavaDoc getRemoteAddress();
134
135   /**
136    * Returns the remove port of the connection
137    */

138   public abstract int getRemotePort();
139
140   /**
141    * Sets the time of the request start. ServerRequests can use
142    * setAccessTime() to put off connection reaping. HttpRequest calls
143    * setAccessTime() at the beginning of each request.
144    *
145    * @param now the current time in milliseconds as by Alarm.getCurrentTime().
146    */

147   public void setAccessTime(long now)
148   {
149     _accessTime = now;
150   }
151
152   /**
153    * Returns the time the last Request began in milliseconds.
154    */

155   public long getAccessTime()
156   {
157     return _accessTime;
158   }
159
160   /**
161    * Returns the selectable channel.
162    */

163   public SelectableChannel JavaDoc getSelectableChannel()
164   {
165     throw new UnsupportedOperationException JavaDoc();
166   }
167
168   /**
169    * Closes the connection()
170    */

171   public void close()
172   {
173   }
174 }
175
Popular Tags