1 |
/* |
/* |
2 |
Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. |
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
61 |
ObjectInputStream oin; |
ObjectInputStream oin; |
62 |
ObjectOutputStream oout; |
ObjectOutputStream oout; |
63 |
|
|
64 |
|
// reviveTime and expireTime make UnicastConnection pool-able |
65 |
|
long reviveTime = 0; |
66 |
|
long expireTime = Long.MAX_VALUE; |
67 |
|
|
68 |
UnicastConnection(UnicastConnectionManager man, Socket sock) { |
UnicastConnection(UnicastConnectionManager man, Socket sock) { |
69 |
this.manager = man; |
this.manager = man; |
70 |
this.sock = sock; |
this.sock = sock; |
141 |
|
|
142 |
ObjectInputStream getObjectInputStream() throws IOException { |
ObjectInputStream getObjectInputStream() throws IOException { |
143 |
if (oin == null) { |
if (oin == null) { |
144 |
oin = new RMIObjectInputStream(din, manager); |
oin = new RMIObjectInputStream(din); |
145 |
} |
} |
146 |
return (oin); |
return (oin); |
147 |
} |
} |
157 |
try { |
try { |
158 |
if(oout != null) |
if(oout != null) |
159 |
oout.close(); |
oout.close(); |
160 |
|
sock.close(); |
161 |
} |
} |
162 |
catch (IOException _) { |
catch (IOException _) { |
163 |
} |
} |
169 |
sock = null; |
sock = null; |
170 |
} |
} |
171 |
|
|
172 |
|
public static final long CONNECTION_TIMEOUT = 10000L; |
173 |
|
|
174 |
|
static boolean isExpired(UnicastConnection conn, long l){ |
175 |
|
if (l <= conn.expireTime ) |
176 |
|
return false; |
177 |
|
return true; |
178 |
|
} |
179 |
|
|
180 |
|
static void resetTime(UnicastConnection conn){ |
181 |
|
long l = System.currentTimeMillis(); |
182 |
|
conn.reviveTime = l; |
183 |
|
conn.expireTime = l + CONNECTION_TIMEOUT; |
184 |
|
} |
185 |
|
|
186 |
/** |
/** |
187 |
* We run connects on the server. Dispatch it then discard it. |
* We run connects on the server. Dispatch it then discard it. |
188 |
*/ |
*/ |
189 |
public void run() { |
public void run() { |
190 |
|
do{ |
191 |
try { |
try { |
192 |
UnicastServer.dispatch(this); |
UnicastServer.dispatch(this); |
193 |
|
//don't discardConnection explicitly, only when |
194 |
|
// exception happens or the connection's expireTime |
195 |
|
// comes |
196 |
|
} catch (Exception e ){ |
197 |
manager.discardConnection(this); |
manager.discardConnection(this); |
198 |
|
break; |
199 |
} |
} |
200 |
catch (Exception e) { |
}while(true); |
|
e.printStackTrace(); |
|
|
} |
|
201 |
} |
} |
202 |
|
|
203 |
} |
} |