2 // ========================================================================
3 // Copyright (c) 1995-2016 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.io;
21 import java.io.IOException;
22 import java.nio.ByteBuffer;
25 import org.eclipse.jetty.util.log.Log;
26 import org.eclipse.jetty.util.log.Logger;
29 * Factory for client-side {@link Connection} instances.
31 public interface ClientConnectionFactory
35 * @param endPoint the {@link org.eclipse.jetty.io.EndPoint} to link the newly created connection to
36 * @param context the context data to create the connection
37 * @return a new {@link Connection}
38 * @throws IOException if the connection cannot be created
40 public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException;
42 public static class Helper
44 private static Logger LOG = Log.getLogger(Helper.class);
51 * Replaces the given {@code oldConnection} with the given {@code newConnection} on the
52 * {@link EndPoint} associated with {@code oldConnection}, performing connection lifecycle management.
54 * The {@code oldConnection} will be closed by invoking {@link org.eclipse.jetty.io.Connection#onClose()}
55 * and the {@code newConnection} will be opened by invoking {@link org.eclipse.jetty.io.Connection#onOpen(ByteBuffer)}.
56 * @param oldConnection the old connection to replace
57 * @param newConnection the new connection replacement
59 public static void replaceConnection(Connection oldConnection, Connection newConnection)
62 oldConnection.getEndPoint().setConnection(newConnection);
66 private static void open(Connection connection)
78 private static void close(Connection connection)