/*
 * Copyright (C) 2012-2013 Facebook, Inc.
 *
 * 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.facebook.nifty.core;

import com.facebook.nifty.codec.ThriftFrameCodecFactory;
import com.facebook.nifty.duplex.TDuplexProtocolFactory;
import com.facebook.nifty.processor.NiftyProcessorFactory;
import io.airlift.units.Duration;

import java.util.concurrent.Executor;

/**
 * Descriptor for a Thrift Server. This defines a listener port that Nifty need to start a Thrift endpoint.
 */
public class ThriftServerDef
{
    private final int serverPort;
    private final int maxFrameSize;
    private final int maxConnections;
    private final int queuedResponseLimit;
    private final NiftyProcessorFactory processorFactory;
    private final TDuplexProtocolFactory duplexProtocolFactory;

    private final Duration clientIdleTimeout;
    private final Duration taskTimeout;

    private final ThriftFrameCodecFactory thriftFrameCodecFactory;
    private final Executor executor;
    private final String name;
    private final NiftySecurityFactory securityFactory;

    public ThriftServerDef(
            String name,
            int serverPort,
            int maxFrameSize,
            int queuedResponseLimit,
            int maxConnections,
            NiftyProcessorFactory processorFactory,
            TDuplexProtocolFactory duplexProtocolFactory,
            Duration clientIdleTimeout,
            Duration taskTimeout,
            ThriftFrameCodecFactory thriftFrameCodecFactory,
            Executor executor,
            NiftySecurityFactory securityFactory)
    {
        this.name = name;
        this.serverPort = serverPort;
        this.maxFrameSize = maxFrameSize;
        this.maxConnections = maxConnections;
        this.queuedResponseLimit = queuedResponseLimit;
        this.processorFactory = processorFactory;
        this.duplexProtocolFactory = duplexProtocolFactory;
        this.clientIdleTimeout = clientIdleTimeout;
        this.taskTimeout = taskTimeout;
        this.thriftFrameCodecFactory = thriftFrameCodecFactory;
        this.executor = executor;
        this.securityFactory = securityFactory;
    }

    public static ThriftServerDefBuilder newBuilder()
    {
        return new ThriftServerDefBuilder();
    }

    public int getServerPort()
    {
        return serverPort;
    }

    public int getMaxFrameSize()
    {
        return maxFrameSize;
    }

    public int getMaxConnections()
    {
        return maxConnections;
    }

    public int getQueuedResponseLimit()
    {
        return queuedResponseLimit;
    }

    public NiftyProcessorFactory getProcessorFactory()
    {
        return processorFactory;
    }

    public TDuplexProtocolFactory getDuplexProtocolFactory()
    {
        return duplexProtocolFactory;
    }

    public Duration getClientIdleTimeout() {
        return clientIdleTimeout;
    }

    public Duration getTaskTimeout() { return taskTimeout; }

    public Executor getExecutor()
    {
        return executor;
    }

    public String getName()
    {
        return name;
    }

    public ThriftFrameCodecFactory getThriftFrameCodecFactory()
    {
        return thriftFrameCodecFactory;
    }

    public NiftySecurityFactory getSecurityFactory()
    {
        return securityFactory;
    }
}

@@ -877,16 +877,83 @@
 cutor;%0A%0A
+import static com.google.common.base.Preconditions.checkArgument;%0A%0A
 /**%0A * D
@@ -2148,32 +2148,275 @@
 yFactory)%0A    %7B%0A
+        // Upper two most significant bits are used for testing whether the message%0A        // has framing, and whether it is using HTTP transport.%0A        checkArgument(maxFrameSize %3C= 0x3FFFFFFF, %22Max frame size must be smaller than 1GB%22);%0A%0A
         this.nam

Set a limit on the frame size limit (0x3FFFFFFF)