View Javadoc

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