blob: 7aa846ca516a23a990d52b1727700644665d7465 [file] [log] [blame]
Jake Slack03928ae2014-05-13 18:41:56 -07001//
2// ========================================================================
3// Copyright (c) 1995-2014 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//
9// The Eclipse Public License is available at
10// http://www.eclipse.org/legal/epl-v10.html
11//
12// The Apache License v2.0 is available at
13// http://www.opensource.org/licenses/apache2.0.php
14//
15// You may elect to redistribute this code under either of these licenses.
16// ========================================================================
17//
18
19package org.eclipse.jetty.io;
20
21import java.io.IOException;
22
23import org.eclipse.jetty.util.log.Log;
24import org.eclipse.jetty.util.log.Logger;
25
26
27public abstract class AbstractConnection implements Connection
28{
29 private static final Logger LOG = Log.getLogger(AbstractConnection.class);
30
31 private final long _timeStamp;
32 protected final EndPoint _endp;
33
34 public AbstractConnection(EndPoint endp)
35 {
36 _endp=(EndPoint)endp;
37 _timeStamp = System.currentTimeMillis();
38 }
39
40 public AbstractConnection(EndPoint endp,long timestamp)
41 {
42 _endp=(EndPoint)endp;
43 _timeStamp = timestamp;
44 }
45
46 public long getTimeStamp()
47 {
48 return _timeStamp;
49 }
50
51 public EndPoint getEndPoint()
52 {
53 return _endp;
54 }
55
56 public void onIdleExpired(long idleForMs)
57 {
58 try
59 {
60 LOG.debug("onIdleExpired {}ms {} {}",idleForMs,this,_endp);
61 if (_endp.isInputShutdown() || _endp.isOutputShutdown())
62 _endp.close();
63 else
64 _endp.shutdownOutput();
65 }
66 catch(IOException e)
67 {
68 LOG.ignore(e);
69
70 try
71 {
72 _endp.close();
73 }
74 catch(IOException e2)
75 {
76 LOG.ignore(e2);
77 }
78 }
79 }
80
81 public String toString()
82 {
83 return String.format("%s@%x", getClass().getSimpleName(), hashCode());
84 }
85}