View Javadoc

1   package org.eclipse.jetty.io;
2   //========================================================================
3   //Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //All rights reserved. This program and the accompanying materials
6   //are made available under the terms of the Eclipse Public License v1.0
7   //and Apache License v2.0 which accompanies this distribution.
8   //The Eclipse Public License is available at
9   //http://www.eclipse.org/legal/epl-v10.html
10  //The Apache License v2.0 is available at
11  //http://www.opensource.org/licenses/apache2.0.php
12  //You may elect to redistribute this code under either of these licenses.
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  }