All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firenio.baseio.codec.http2.Http2Session Maven / Gradle / Ivy

There is a newer version: 3.2.9.beta11
Show newest version
/*
 * Copyright 2015 The Baseio Project
 *  
 * 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.
 */
package com.firenio.baseio.codec.http2;

import com.firenio.baseio.component.Channel;

public class Http2Session {

    private static final String http2SessionChannelKey = "Http2SessionChannelKey";

    private Channel             ch;

    private Http2Headers        http2Headers           = new Http2HeadersImpl();

    private boolean             prefaceRead            = true;

    private long[]              settings               = new long[] { 0, 4096, 1, 128, 65535, 16384,
            0 };

    public Channel getChannel() {
        return ch;
    }

    public Http2Headers getHttp2Headers() {
        return http2Headers;
    }

    public long[] getSettings() {
        return settings;
    }

    public long getSettings(int i) {
        return settings[i];
    }

    public boolean isPrefaceRead() {
        return prefaceRead;
    }

    public void setChannel(Channel ch) {
        this.ch = ch;
    }

    public void setPrefaceRead(boolean prefaceRead) {
        this.prefaceRead = prefaceRead;
    }

    public void setSettings(int key, long value) {
        settings[key] = value;
    }

    public static Http2Session getHttp2Session(Channel ch) {
        Http2Session session = (Http2Session) ch.getAttribute(http2SessionChannelKey);
        if (session == null) {
            synchronized (ch.attributes()) {
                session = (Http2Session) ch.getAttribute(http2SessionChannelKey);
                if (session != null) {
                    return session;
                }
                session = new Http2Session();
                ch.setAttribute(http2SessionChannelKey, session);
            }
        }
        return session;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy