View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.http.impl.nio.client;
28  
29  import java.nio.ByteBuffer;
30  
31  import org.apache.http.HttpResponse;
32  import org.apache.http.client.methods.HttpRequestWrapper;
33  import org.apache.http.client.methods.HttpUriRequest;
34  import org.apache.http.client.protocol.HttpClientContext;
35  import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
36  import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
37  
38  class InternalState {
39  
40      private final long id;
41      private final HttpAsyncRequestProducer requestProducer;
42      private final HttpAsyncResponseConsumer<?> responseConsumer;
43      private final HttpClientContext localContext;
44  
45      private HttpRequestWrapper mainRequest;
46      private HttpResponse finalResponse;
47      private ByteBuffer tmpbuf;
48      private boolean requestContentProduced;
49      private int execCount;
50  
51      private int redirectCount;
52      private HttpUriRequest redirect;
53  
54      public InternalState(
55              final long id,
56              final HttpAsyncRequestProducer requestProducer,
57              final HttpAsyncResponseConsumer<?> responseConsumer,
58              final HttpClientContext localContext) {
59          super();
60          this.id = id;
61          this.requestProducer = requestProducer;
62          this.responseConsumer = responseConsumer;
63          this.localContext = localContext;
64      }
65  
66      public long getId() {
67          return id;
68      }
69  
70      public HttpAsyncRequestProducer getRequestProducer() {
71          return requestProducer;
72      }
73  
74      public HttpAsyncResponseConsumer<?> getResponseConsumer() {
75          return responseConsumer;
76      }
77  
78      public HttpClientContext getLocalContext() {
79          return localContext;
80      }
81  
82      public HttpRequestWrapper getMainRequest() {
83          return mainRequest;
84      }
85  
86      public void setMainRequest(final HttpRequestWrapper mainRequest) {
87          this.mainRequest = mainRequest;
88      }
89  
90      public HttpResponse getFinalResponse() {
91          return finalResponse;
92      }
93  
94      public void setFinalResponse(final HttpResponse finalResponse) {
95          this.finalResponse = finalResponse;
96      }
97  
98      public ByteBuffer getTmpbuf() {
99          if (tmpbuf == null) {
100             tmpbuf = ByteBuffer.allocate(4 * 1024);
101         }
102         return tmpbuf;
103     }
104 
105     public boolean isRequestContentProduced() {
106         return requestContentProduced;
107     }
108 
109     public void setRequestContentProduced() {
110         this.requestContentProduced = true;
111     }
112 
113     public int getExecCount() {
114         return execCount;
115     }
116 
117     public void incrementExecCount() {
118         this.execCount++;
119     }
120 
121     public int getRedirectCount() {
122         return redirectCount;
123     }
124 
125     public void incrementRedirectCount() {
126         this.redirectCount++;
127     }
128 
129     public HttpUriRequest getRedirect() {
130         return redirect;
131     }
132 
133     public void setRedirect(final HttpUriRequest redirect) {
134         this.redirect = redirect;
135     }
136 
137     @Override
138     public String toString() {
139         return Long.toString(id);
140     }
141 
142 }