diff options
Diffstat (limited to 'jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java')
-rw-r--r-- | jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java index f73c87f227..4e45eedf74 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/ServerSPDYAsyncConnectionFactory.java @@ -1,28 +1,27 @@ -/* - * Copyright (c) 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +//======================================================================== +//Copyright 2011-2012 Mort Bay Consulting Pty. Ltd. +//------------------------------------------------------------------------ +//All rights reserved. This program and the accompanying materials +//are made available under the terms of the Eclipse Public License v1.0 +//and Apache License v2.0 which accompanies this distribution. +//The Eclipse Public License is available at +//http://www.eclipse.org/legal/epl-v10.html +//The Apache License v2.0 is available at +//http://www.opensource.org/licenses/apache2.0.php +//You may elect to redistribute this code under either of these licenses. +//======================================================================== + package org.eclipse.jetty.spdy; +import java.io.IOException; import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledExecutorService; -import org.eclipse.jetty.io.AsyncConnection; import org.eclipse.jetty.io.AsyncEndPoint; -import org.eclipse.jetty.io.ByteBufferPool; +import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.io.nio.AsyncConnection; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.generator.Generator; import org.eclipse.jetty.spdy.parser.Parser; @@ -49,6 +48,11 @@ public class ServerSPDYAsyncConnectionFactory implements AsyncConnectionFactory this.listener = listener; } + public short getVersion() + { + return version; + } + @Override public AsyncConnection newAsyncConnection(SocketChannel channel, AsyncEndPoint endPoint, Object attachment) { @@ -56,16 +60,17 @@ public class ServerSPDYAsyncConnectionFactory implements AsyncConnectionFactory Parser parser = new Parser(compressionFactory.newDecompressor()); Generator generator = new Generator(bufferPool, compressionFactory.newCompressor()); - ServerSessionFrameListener listener = this.listener; - if (listener == null) - listener = newServerSessionFrameListener(endPoint, attachment); - SPDYServerConnector connector = (SPDYServerConnector)attachment; + ServerSessionFrameListener listener = provideServerSessionFrameListener(endPoint, attachment); SPDYAsyncConnection connection = new ServerSPDYAsyncConnection(endPoint, bufferPool, parser, listener, connector); - endPoint.setAsyncConnection(connection); + endPoint.setConnection(connection); + + FlowControlStrategy flowControlStrategy = connector.newFlowControlStrategy(version); - final StandardSession session = new StandardSession(version, bufferPool, threadPool, scheduler, connection, connection, 2, listener, generator); + StandardSession session = new StandardSession(version, bufferPool, threadPool, scheduler, connection, connection, 2, listener, generator, flowControlStrategy); + session.setAttribute("org.eclipse.jetty.spdy.remoteAddress", endPoint.getRemoteAddr()); + session.setWindowSize(connector.getInitialWindowSize()); parser.addListener(session); connection.setSession(session); @@ -74,7 +79,7 @@ public class ServerSPDYAsyncConnectionFactory implements AsyncConnectionFactory return connection; } - protected ServerSessionFrameListener newServerSessionFrameListener(AsyncEndPoint endPoint, Object attachment) + protected ServerSessionFrameListener provideServerSessionFrameListener(AsyncEndPoint endPoint, Object attachment) { return listener; } @@ -83,6 +88,7 @@ public class ServerSPDYAsyncConnectionFactory implements AsyncConnectionFactory { private final ServerSessionFrameListener listener; private final SPDYServerConnector connector; + private volatile boolean connected; private ServerSPDYAsyncConnection(AsyncEndPoint endPoint, ByteBufferPool bufferPool, Parser parser, ServerSessionFrameListener listener, SPDYServerConnector connector) { @@ -92,11 +98,16 @@ public class ServerSPDYAsyncConnectionFactory implements AsyncConnectionFactory } @Override - public void onOpen() + public Connection handle() throws IOException { - // NPE guard to support tests - if (listener != null) - listener.onConnect(getSession()); + if (!connected) + { + // NPE guard to support tests + if (listener != null) + listener.onConnect(getSession()); + connected = true; + } + return super.handle(); } @Override |