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

com.signalfx.shaded.jetty.websocket.common.extensions.AbstractExtension Maven / Gradle / Ivy

//
//  ========================================================================
//  Copyright (c) 1995-2019 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 com.signalfx.shaded.jetty.websocket.common.extensions;

import com.signalfx.shaded.jetty.io.ByteBufferPool;
import com.signalfx.shaded.jetty.util.annotation.ManagedAttribute;
import com.signalfx.shaded.jetty.util.annotation.ManagedObject;
import com.signalfx.shaded.jetty.util.component.AbstractLifeCycle;
import com.signalfx.shaded.jetty.util.log.Log;
import com.signalfx.shaded.jetty.util.log.Logger;
import com.signalfx.shaded.jetty.websocket.api.BatchMode;
import com.signalfx.shaded.jetty.websocket.api.WebSocketPolicy;
import com.signalfx.shaded.jetty.websocket.api.WriteCallback;
import com.signalfx.shaded.jetty.websocket.api.extensions.Extension;
import com.signalfx.shaded.jetty.websocket.api.extensions.ExtensionConfig;
import com.signalfx.shaded.jetty.websocket.api.extensions.Frame;
import com.signalfx.shaded.jetty.websocket.api.extensions.IncomingFrames;
import com.signalfx.shaded.jetty.websocket.api.extensions.OutgoingFrames;
import com.signalfx.shaded.jetty.websocket.common.LogicalConnection;
import com.signalfx.shaded.jetty.websocket.common.scopes.WebSocketContainerScope;

@ManagedObject("Abstract Extension")
public abstract class AbstractExtension extends AbstractLifeCycle implements Extension
{
    private final Logger log;
    private WebSocketPolicy policy;
    private ByteBufferPool bufferPool;
    private ExtensionConfig config;
    private LogicalConnection connection;
    private OutgoingFrames nextOutgoing;
    private IncomingFrames nextIncoming;

    public AbstractExtension()
    {
        log = Log.getLogger(this.getClass());
    }

    @Deprecated
    public void init(WebSocketContainerScope container)
    {
        init(container.getPolicy(), container.getBufferPool());
    }

    public void init(WebSocketPolicy policy, ByteBufferPool bufferPool)
    {
        this.policy = policy;
        this.bufferPool = bufferPool;
    }

    public ByteBufferPool getBufferPool()
    {
        return bufferPool;
    }

    @Override
    public ExtensionConfig getConfig()
    {
        return config;
    }

    public LogicalConnection getConnection()
    {
        return connection;
    }

    @Override
    public String getName()
    {
        return config.getName();
    }

    @ManagedAttribute(name = "Next Incoming Frame Handler", readonly = true)
    public IncomingFrames getNextIncoming()
    {
        return nextIncoming;
    }

    @ManagedAttribute(name = "Next Outgoing Frame Handler", readonly = true)
    public OutgoingFrames getNextOutgoing()
    {
        return nextOutgoing;
    }

    public WebSocketPolicy getPolicy()
    {
        return policy;
    }

    /**
     * Used to indicate that the extension makes use of the RSV1 bit of the base websocket framing.
     * 

* This is used to adjust validation during parsing, as well as a checkpoint against 2 or more extensions all simultaneously claiming ownership of RSV1. * * @return true if extension uses RSV1 for its own purposes. */ @Override public boolean isRsv1User() { return false; } /** * Used to indicate that the extension makes use of the RSV2 bit of the base websocket framing. *

* This is used to adjust validation during parsing, as well as a checkpoint against 2 or more extensions all simultaneously claiming ownership of RSV2. * * @return true if extension uses RSV2 for its own purposes. */ @Override public boolean isRsv2User() { return false; } /** * Used to indicate that the extension makes use of the RSV3 bit of the base websocket framing. *

* This is used to adjust validation during parsing, as well as a checkpoint against 2 or more extensions all simultaneously claiming ownership of RSV3. * * @return true if extension uses RSV3 for its own purposes. */ @Override public boolean isRsv3User() { return false; } protected void nextIncomingFrame(Frame frame) { log.debug("nextIncomingFrame({})", frame); this.nextIncoming.incomingFrame(frame); } protected void nextOutgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) { try { log.debug("nextOutgoingFrame({})", frame); this.nextOutgoing.outgoingFrame(frame, callback, batchMode); } catch (Throwable t) { if (callback != null) callback.writeFailed(t); else log.warn(t); } } public void setBufferPool(ByteBufferPool bufferPool) { this.bufferPool = bufferPool; } public void setConfig(ExtensionConfig config) { this.config = config; } public void setConnection(LogicalConnection connection) { this.connection = connection; } @Override public void setNextIncomingFrames(IncomingFrames nextIncoming) { this.nextIncoming = nextIncoming; } @Override public void setNextOutgoingFrames(OutgoingFrames nextOutgoing) { this.nextOutgoing = nextOutgoing; } public void setPolicy(WebSocketPolicy policy) { this.policy = policy; } @Override public String toString() { return String.format("%s[%s]", this.getClass().getSimpleName(), config.getParameterizedName()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy