View Javadoc

1   // ========================================================================
2   // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  
15  package org.eclipse.jetty.client;
16  
17  import java.io.IOException;
18  
19  import org.eclipse.jetty.io.Buffer;
20  
21  public class HttpEventListenerWrapper implements HttpEventListener
22  {
23      HttpEventListener _listener;
24      boolean _delegatingRequests;
25      boolean _delegatingResponses;
26  
27      public HttpEventListenerWrapper()
28      {
29          _listener=null;
30          _delegatingRequests=false;
31          _delegatingResponses=false;
32      }
33      
34      public HttpEventListenerWrapper(HttpEventListener eventListener,boolean delegating)
35      {
36          _listener=eventListener;
37          _delegatingRequests=delegating;
38          _delegatingResponses=delegating;
39      }
40      
41      public HttpEventListener getEventListener()
42      {
43          return _listener;
44      }
45  
46      public void setEventListener(HttpEventListener listener)
47      {
48          _listener = listener;
49      }
50  
51      public boolean isDelegatingRequests()
52      {
53          return _delegatingRequests;
54      }
55      
56      public boolean isDelegatingResponses()
57      {
58          return _delegatingResponses;
59      }
60  
61      public void setDelegatingRequests(boolean delegating)
62      {
63          _delegatingRequests = delegating;
64      }
65      
66      public void setDelegatingResponses(boolean delegating)
67      {
68          _delegatingResponses = delegating;
69      }
70      
71      public void onConnectionFailed(Throwable ex)
72      {
73          if (_delegatingRequests)
74              _listener.onConnectionFailed(ex);
75      }
76  
77      public void onException(Throwable ex)
78      {
79          if (_delegatingRequests||_delegatingResponses)
80              _listener.onException(ex);
81      }
82  
83      public void onExpire()
84      {
85          if (_delegatingRequests||_delegatingResponses)
86              _listener.onExpire();
87      }
88  
89      public void onRequestCommitted() throws IOException
90      {
91          if (_delegatingRequests)
92              _listener.onRequestCommitted();
93      }
94  
95      public void onRequestComplete() throws IOException
96      {
97          if (_delegatingRequests)
98              _listener.onRequestComplete();
99      }
100 
101     public void onResponseComplete() throws IOException
102     {
103         if (_delegatingResponses)
104             _listener.onResponseComplete();
105     }
106 
107     public void onResponseContent(Buffer content) throws IOException
108     {
109         if (_delegatingResponses)
110             _listener.onResponseContent(content);
111     }
112 
113     public void onResponseHeader(Buffer name, Buffer value) throws IOException
114     {
115         if (_delegatingResponses)
116             _listener.onResponseHeader(name,value);
117     }
118 
119     public void onResponseHeaderComplete() throws IOException
120     {
121         if (_delegatingResponses)
122             _listener.onResponseHeaderComplete();
123     }
124 
125     public void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
126     {
127         if (_delegatingResponses)
128             _listener.onResponseStatus(version,status,reason);
129     }
130 
131     public void onRetry()
132     {
133         if (_delegatingRequests)
134             _listener.onRetry();
135     }
136     
137     
138     
139 }