1 package org.eclipse.jetty.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import java.io.IOException;
16
17 import org.eclipse.jetty.util.log.Log;
18 import org.eclipse.jetty.util.log.Logger;
19
20
21 public abstract class AbstractConnection implements Connection
22 {
23 private static final Logger LOG = Log.getLogger(AbstractConnection.class);
24
25 private final long _timeStamp;
26 protected final EndPoint _endp;
27
28 public AbstractConnection(EndPoint endp)
29 {
30 _endp=(EndPoint)endp;
31 _timeStamp = System.currentTimeMillis();
32 }
33
34 public AbstractConnection(EndPoint endp,long timestamp)
35 {
36 _endp=(EndPoint)endp;
37 _timeStamp = timestamp;
38 }
39
40 public long getTimeStamp()
41 {
42 return _timeStamp;
43 }
44
45 public EndPoint getEndPoint()
46 {
47 return _endp;
48 }
49
50 public void onIdleExpired(long idleForMs)
51 {
52 try
53 {
54 LOG.debug("onIdleExpired {}ms {} {}",idleForMs,this,_endp);
55 if (_endp.isInputShutdown() || _endp.isOutputShutdown())
56 _endp.close();
57 else
58 _endp.shutdownOutput();
59 }
60 catch(IOException e)
61 {
62 LOG.ignore(e);
63
64 try
65 {
66 _endp.close();
67 }
68 catch(IOException e2)
69 {
70 LOG.ignore(e2);
71 }
72 }
73 }
74
75 public String toString()
76 {
77 return String.format("%s@%x", getClass().getSimpleName(), hashCode());
78 }
79 }