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;
23 import java.util.concurrent.Executor;
24 import javax.net.ssl.SSLEngine;
26 import org.eclipse.jetty.util.BufferUtil;
27 import org.eclipse.jetty.util.log.Log;
28 import org.eclipse.jetty.util.log.Logger;
30 public abstract class NegotiatingClientConnection extends AbstractConnection
32 private static final Logger LOG = Log.getLogger(NegotiatingClientConnection.class);
34 private final SSLEngine engine;
35 private final ClientConnectionFactory connectionFactory;
36 private final Map<String, Object> context;
37 private volatile boolean completed;
39 protected NegotiatingClientConnection(EndPoint endp, Executor executor, SSLEngine sslEngine, ClientConnectionFactory connectionFactory, Map<String, Object> context)
41 super(endp, executor);
42 this.engine = sslEngine;
43 this.connectionFactory = connectionFactory;
44 this.context = context;
47 protected SSLEngine getSSLEngine()
52 protected void completed()
63 getEndPoint().flush(BufferUtil.EMPTY_BUFFER);
72 throw new RuntimeIOException(x);
77 public void onFillable()
82 if (filled == 0 && !completed)
84 if (filled <= 0 || completed)
95 return getEndPoint().fill(BufferUtil.EMPTY_BUFFER);
105 private void replaceConnection()
107 EndPoint endPoint = getEndPoint();
110 Connection oldConnection = endPoint.getConnection();
111 Connection newConnection = connectionFactory.newConnection(endPoint, context);
112 ClientConnectionFactory.Helper.replaceConnection(oldConnection, newConnection);
124 // Gentler close for SSL.
125 getEndPoint().shutdownOutput();