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.
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;
24 import org.eclipse.jetty.util.log.Log;
25 import org.eclipse.jetty.util.log.Logger;
28 * Factory for client-side {@link Connection} instances.
30 public interface ClientConnectionFactory
34 * @param endPoint the {@link org.eclipse.jetty.io.EndPoint} to link the newly created connection to
35 * @param context the context data to create the connection
36 * @return a new {@link Connection}
37 * @throws IOException if the connection cannot be created
39 public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException;
41 public static class Helper
43 private static Logger LOG = Log.getLogger(Helper.class);
50 * Replaces the given {@code oldConnection} with the given {@code newConnection} on the
51 * {@link EndPoint} associated with {@code oldConnection}, performing connection lifecycle management.
53 * The {@code oldConnection} will be closed by invoking {@link org.eclipse.jetty.io.Connection#onClose()}
54 * and the {@code newConnection} will be opened by invoking {@link org.eclipse.jetty.io.Connection#onOpen()}.
55 * @param oldConnection the old connection to replace
56 * @param newConnection the new connection replacement
58 public static void replaceConnection(Connection oldConnection, Connection newConnection)
61 oldConnection.getEndPoint().setConnection(newConnection);
65 private static void open(Connection connection)
77 private static void close(Connection connection)