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

ratpack.launch.internal.DefaultLaunchConfig Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc-1
Show newest version
/*
 * Copyright 2013 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.
 */

package ratpack.launch.internal;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBufAllocator;
import ratpack.api.Nullable;
import ratpack.exec.ExecController;
import ratpack.exec.internal.DefaultExecController;
import ratpack.file.FileSystemBinding;
import ratpack.launch.HandlerFactory;
import ratpack.launch.LaunchConfig;
import ratpack.launch.NoBaseDirException;

import javax.net.ssl.SSLContext;
import java.net.InetAddress;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class DefaultLaunchConfig implements LaunchConfig {

  private final FileSystemBinding baseDir;
  private final HandlerFactory handlerFactory;
  private final int port;
  private final InetAddress address;
  private final boolean development;
  private final int threads;
  private final ExecController execController;
  private final ByteBufAllocator byteBufAllocator;
  private final URI publicAddress;
  private final ImmutableList indexFiles;
  private final ImmutableMap other;
  private final SSLContext sslContext;
  private final int maxContentLength;
  private final boolean timeResponses;
  private final boolean compressResponses;
  private final long compressionMinSize;
  private final ImmutableSet compressionMimeTypeWhiteList;
  private final ImmutableSet compressionMimeTypeBlackList;

  public DefaultLaunchConfig(FileSystemBinding baseDir, int port, InetAddress address, boolean development, int threads, ByteBufAllocator byteBufAllocator, URI publicAddress, ImmutableList indexFiles, ImmutableMap other, SSLContext sslContext, int maxContentLength, boolean timeResponses, boolean compressResponses, long compressionMinSize, ImmutableSet compressionMimeTypeWhiteList, ImmutableSet compressionMimeTypeBlackList, HandlerFactory handlerFactory) {
    this.baseDir = baseDir;
    this.port = port;
    this.address = address;
    this.development = development;
    this.threads = threads;
    this.timeResponses = timeResponses;
    this.compressResponses = compressResponses;
    this.compressionMinSize = compressionMinSize;
    this.compressionMimeTypeWhiteList = compressionMimeTypeWhiteList;
    this.compressionMimeTypeBlackList = compressionMimeTypeBlackList;
    this.byteBufAllocator = byteBufAllocator;
    this.publicAddress = publicAddress;
    this.indexFiles = indexFiles;
    this.other = other;
    this.handlerFactory = handlerFactory;
    this.sslContext = sslContext;
    this.maxContentLength = maxContentLength;
    this.execController = new DefaultExecController(this.threads);
  }

  @Override
  public FileSystemBinding getBaseDir() {
    if (baseDir == null) {
      throw new NoBaseDirException("No base dir has been set");
    } else {
      return baseDir;
    }
  }

  @Override
  public HandlerFactory getHandlerFactory() {
    return handlerFactory;
  }

  @Override
  public int getPort() {
    return port;
  }

  @Override
  public InetAddress getAddress() {
    return address;
  }

  @Override
  public boolean isDevelopment() {
    return development;
  }

  @Override
  public int getThreads() {
    return threads;
  }

  @Override
  public ExecController getExecController() {
    return execController;
  }

  @Override
  public ByteBufAllocator getBufferAllocator() {
    return byteBufAllocator;
  }

  @Override
  public URI getPublicAddress() {
    return publicAddress;
  }

  @Override
  public List getIndexFiles() {
    return indexFiles;
  }

  @Override
  public SSLContext getSSLContext() {
    return sslContext;
  }

  public String getOther(String key, String defaultValue) {
    String value = other.get(key);
    return value == null ? defaultValue : value;
  }

  @Override
  public Map getOtherPrefixedWith(String prefix) {
    Map result = new LinkedHashMap<>();
    int prefixLength = prefix.length();
    for (Map.Entry property : other.entrySet()) {
      String key = property.getKey();
      if (key.startsWith(prefix) && key.length() > prefixLength) {
        result.put(key.substring(prefixLength), property.getValue());
      }
    }
    return result;
  }

  @Override
  public int getMaxContentLength() {
    return maxContentLength;
  }

  @Override
  public boolean isTimeResponses() {
    return timeResponses;
  }

  @Override
  public boolean isCompressResponses() {
    return compressResponses;
  }

  @Override
  public long getCompressionMinSize() {
    return compressionMinSize;
  }

  @Override
  @Nullable
  public ImmutableSet getCompressionMimeTypeWhiteList() {
    return compressionMimeTypeWhiteList;
  }

  @Override
  @Nullable
  public ImmutableSet getCompressionMimeTypeBlackList() {
    return compressionMimeTypeBlackList;
  }

  @Override
  public boolean isHasBaseDir() {
    return baseDir != null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy