Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.grizzly.spdy;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.Deflater;
import org.glassfish.grizzly.CloseType;
import org.glassfish.grizzly.Closeable;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.Context;
import org.glassfish.grizzly.GenericCloseListener;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.IOEvent;
import org.glassfish.grizzly.IOEventLifeCycleListener;
import org.glassfish.grizzly.ProcessorExecutor;
import org.glassfish.grizzly.WriteHandler;
import org.glassfish.grizzly.attributes.Attribute;
import org.glassfish.grizzly.attributes.AttributeBuilder;
import org.glassfish.grizzly.filterchain.FilterChain;
import org.glassfish.grizzly.filterchain.FilterChainContext;
import org.glassfish.grizzly.http.HttpContent;
import org.glassfish.grizzly.http.HttpContext;
import org.glassfish.grizzly.http.HttpHeader;
import org.glassfish.grizzly.http.HttpPacket;
import org.glassfish.grizzly.http.HttpRequestPacket;
import org.glassfish.grizzly.http.HttpResponsePacket;
import org.glassfish.grizzly.http.Method;
import org.glassfish.grizzly.http.util.Header;
import org.glassfish.grizzly.memory.MemoryManager;
import org.glassfish.grizzly.spdy.compression.SpdyDeflaterOutputStream;
import org.glassfish.grizzly.spdy.compression.SpdyInflaterOutputStream;
import org.glassfish.grizzly.spdy.frames.GoAwayFrame;
import org.glassfish.grizzly.spdy.frames.RstStreamFrame;
import org.glassfish.grizzly.spdy.frames.SpdyFrame;
import org.glassfish.grizzly.utils.DataStructures;
import org.glassfish.grizzly.utils.Holder;
import org.glassfish.grizzly.utils.NullaryFunction;
import static org.glassfish.grizzly.spdy.Constants.*;
/**
* The SPDY Session abstraction.
*
* @author oleksiys
*/
public abstract class SpdySession {
private static final Logger LOGGER = Grizzly.logger(SpdySession.class);
private static final Level LOGGER_LEVEL = Level.FINE;
private static final Attribute SPDY_SESSION_ATTR =
AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(
SpdySession.class.getName());
private final boolean isServer;
private final Connection> connection;
private SpdyInflaterOutputStream inflaterOutputStream;
private SpdyDeflaterOutputStream deflaterOutputStream;
private DataOutputStream deflaterDataOutputStream;
private final ReentrantLock deflaterLock = new ReentrantLock();
private int deflaterCompressionLevel = Deflater.DEFAULT_COMPRESSION;
private int lastPeerStreamId;
private int lastLocalStreamId;
private final ReentrantLock newClientStreamLock = new ReentrantLock();
private volatile FilterChain upstreamChain;
private volatile FilterChain downstreamChain;
private final Map streamsMap =
DataStructures.getConcurrentMap();
// (Optimization) We may read several DataFrames belonging to the same
// SpdyStream, so in order to not process every DataFrame separately -
// we buffer them and only then passing for processing.
final List streamsToFlushInput = new ArrayList();
private final Object sessionLock = new Object();
private CloseType closeFlag;
private int peerStreamWindowSize = DEFAULT_INITIAL_WINDOW_SIZE;
private volatile int localStreamWindowSize = DEFAULT_INITIAL_WINDOW_SIZE;
private volatile int localConnectionWindowSize = DEFAULT_INITIAL_WINDOW_SIZE;
private volatile int localMaxConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
private int peerMaxConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
private final StreamBuilder streamBuilder = new StreamBuilder();
private final SessionOutputSink outputSink;
public static SpdySession get(final Connection connection) {
return SPDY_SESSION_ATTR.get(connection);
}
public static void bind(final Connection connection, final SpdySession spdySession) {
SPDY_SESSION_ATTR.set(connection, spdySession);
}
private final Holder> addressHolder;
final SpdyHandlerFilter handlerFilter;
public SpdySession(final Connection> connection,
final boolean isServer,
final SpdyHandlerFilter handlerFilter) {
this.connection = connection;
this.isServer = isServer;
this.handlerFilter = handlerFilter;
if (isServer) {
lastLocalStreamId = 0;
lastPeerStreamId = -1;
} else {
lastLocalStreamId = -1;
lastPeerStreamId = 0;
}
addressHolder = Holder.lazyHolder(new NullaryFunction