1 /*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
464 this.flow = new FlowTubeStub(this);
465 }
466
467 final InetSocketAddress proxy;
468 final InetSocketAddress address;
469 final boolean secured;
470 final ConnectionPool.CacheKey key;
471 final HttpClient client;
472 final FlowTubeStub flow;
473 final SocketChannel channel;
474 volatile boolean closed, finished;
475
476 // Used for testing closeOrReturnToPool.
477 void finish(boolean finished) { this.finished = finished; }
478 void reopen() { closed = finished = false;}
479
480 // All these return something
481 @Override boolean connected() {return !closed;}
482 @Override boolean isSecure() {return secured;}
483 @Override boolean isProxied() {return proxy!=null;}
484 @Override ConnectionPool.CacheKey cacheKey() {return key;}
485 @Override FlowTube getConnectionFlow() {return flow;}
486 @Override SocketChannel channel() {return channel;}
487 @Override
488 public void close() {
489 closed=finished=true;
490 System.out.println("closed: " + this);
491 }
492 @Override
493 public String toString() {
494 return "HttpConnectionStub: " + address + " proxy: " + proxy;
495 }
496
497
498 // All these throw errors
499 @Override public HttpPublisher publisher() {return error();}
500 @Override public CompletableFuture<Void> connectAsync(Exchange<?> e) {return error();}
501 @Override public CompletableFuture<Void> finishConnect() {return error();}
502 }
503 // Emulates an HttpClient that has a strong reference to its connection pool.
|
1 /*
2 * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
464 this.flow = new FlowTubeStub(this);
465 }
466
467 final InetSocketAddress proxy;
468 final InetSocketAddress address;
469 final boolean secured;
470 final ConnectionPool.CacheKey key;
471 final HttpClient client;
472 final FlowTubeStub flow;
473 final SocketChannel channel;
474 volatile boolean closed, finished;
475
476 // Used for testing closeOrReturnToPool.
477 void finish(boolean finished) { this.finished = finished; }
478 void reopen() { closed = finished = false;}
479
480 // All these return something
481 @Override boolean connected() {return !closed;}
482 @Override boolean isSecure() {return secured;}
483 @Override boolean isProxied() {return proxy!=null;}
484 @Override InetSocketAddress proxy() { return proxy; }
485 @Override ConnectionPool.CacheKey cacheKey() {return key;}
486 @Override FlowTube getConnectionFlow() {return flow;}
487 @Override SocketChannel channel() {return channel;}
488 @Override
489 public void close() {
490 closed=finished=true;
491 System.out.println("closed: " + this);
492 }
493 @Override
494 public String toString() {
495 return "HttpConnectionStub: " + address + " proxy: " + proxy;
496 }
497
498
499 // All these throw errors
500 @Override public HttpPublisher publisher() {return error();}
501 @Override public CompletableFuture<Void> connectAsync(Exchange<?> e) {return error();}
502 @Override public CompletableFuture<Void> finishConnect() {return error();}
503 }
504 // Emulates an HttpClient that has a strong reference to its connection pool.
|