<commit_before>//
//   Copyright 2018  <NAME>.A.S.
//
//   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 io.warp10.plugins.http;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.locks.LockSupport;
import java.util.function.Predicate;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.warp10.SSLUtils;
import io.warp10.continuum.Configuration;
import io.warp10.script.MemoryWarpScriptStack;
import io.warp10.script.WarpScriptStack.Macro;
import io.warp10.warp.sdk.AbstractWarp10Plugin;

public class HTTPWarp10Plugin extends AbstractWarp10Plugin implements Runnable {

  private static final Logger LOG = LoggerFactory.getLogger(HTTPWarp10Plugin.class);

  private static final String PARAM_PATH = "path";
  private static final String PARAM_MACRO = "macro";
  private static final String PARAM_PREFIX = "prefix";
  private static final String PARAM_PARSE_PAYLOAD = "parsePayload";

  private static final String CONF_HTTP_HOST = "http.host";
  private static final String CONF_HTTP_PORT = "http.port";
  private static final String CONF_HTTP_TCP_BACKLOG = "http.tcp.backlog";

  /**
   * Directory where spec files are located
   */
  private static final String CONF_HTTP_DIR = "http.dir";

  /**
   * Period at which to scan the spec directory
   */
  private static final String CONF_HTTP_PERIOD = "http.period";

  private static final String CONF_HTTP_ACCEPTORS = "http.acceptors";
  private static final String CONF_HTTP_SELECTORS = "http.selectors";
  private static final String CONF_HTTP_MAXTHREADS = "http.maxthreads";
  private static final String CONF_HTTP_IDLE_TIMEOUT = "http.idle.timeout";
  private static final String CONF_HTTP_QUEUESIZE = "http.queuesize";
  private static final String CONF_HTTP_GZIP = "http.gzip";
  private static final String CONF_HTTP_LCHEADERS = "http.lcheaders";

  /**
   * Default scanning period in ms
   */
  private static final long DEFAULT_PERIOD = 60000L;

  private String dir;
  private long period;
  private String host;
  private int port = -1;
  private int tcpBacklog = 0;
  private int acceptors = 2;
  private int selectors = 4;
  private int maxthreads = -1;
  private int idleTimeout = 30000;
  private BlockingQueue<Runnable> queue = null;

  private int sslport = -1;
  private int tcpBacklog = 0;

  /**
   * Map of uri to macros
   */
  private Map<String, Macro> macros = new HashMap<String, Macro>();

  /**<commit_msg>Fix syntax: Add parameters about Listen Queue/Backlog in TCP<commit_after>//
//   Copyright 2018  <NAME>.
//
//   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 io.warp10.plugins.http;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.locks.LockSupport;
import java.util.function.Predicate;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.warp10.SSLUtils;
import io.warp10.continuum.Configuration;
import io.warp10.script.MemoryWarpScriptStack;
import io.warp10.script.WarpScriptStack.Macro;
import io.warp10.warp.sdk.AbstractWarp10Plugin;

public class HTTPWarp10Plugin extends AbstractWarp10Plugin implements Runnable {

  private static final Logger LOG = LoggerFactory.getLogger(HTTPWarp10Plugin.class);

  private static final String PARAM_PATH = "path";
  private static final String PARAM_MACRO = "macro";
  private static final String PARAM_PREFIX = "prefix";
  private static final String PARAM_PARSE_PAYLOAD = "parsePayload";

  private static final String CONF_HTTP_HOST = "http.host";
  private static final String CONF_HTTP_PORT = "http.port";
  private static final String CONF_HTTP_TCP_BACKLOG = "http.tcp.backlog";

  /**
   * Directory where spec files are located
   */
  private static final String CONF_HTTP_DIR = "http.dir";

  /**
   * Period at which to scan the spec directory
   */
  private static final String CONF_HTTP_PERIOD = "http.period";

  private static final String CONF_HTTP_ACCEPTORS = "http.acceptors";
  private static final String CONF_HTTP_SELECTORS = "http.selectors";
  private static final String CONF_HTTP_MAXTHREADS = "http.maxthreads";
  private static final String CONF_HTTP_IDLE_TIMEOUT = "http.idle.timeout";
  private static final String CONF_HTTP_QUEUESIZE = "http.queuesize";
  private static final String CONF_HTTP_GZIP = "http.gzip";
  private static final String CONF_HTTP_LCHEADERS = "http.lcheaders";

  /**
   * Default scanning period in ms
   */
  private static final long DEFAULT_PERIOD = 60000L;

  private String dir;
  private long period;
  private String host;
  private int port = -1;
  private int tcpBacklog = 0;
  private int acceptors = 2;
  private int selectors = 4;
  private int maxthreads = -1;
  private int idleTimeout = 30000;
  private BlockingQueue<Runnable> queue = null;

  private int sslport = -1;

  /**
   * Map of uri to macros
   */
  private Map<String, Macro> macros = new HashMap<String, Macro>();

  /**
{'fraction_non_alphanumeric': 0.09101991060544494, 'fraction_numerical': 0.01259650548557497, 'mean_word_length': 4.331407942238267, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823729', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2225, 'n_words': 678}