<commit_before>/*
 * Code Pulse: A real-time code coverage testing tool. For more information
 * see http://code-pulse.com
 *
 * Copyright (C) 2014 Applied Visions - http://securedecisions.avi.com
 *
 * 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.secdec.codepulse.tracer

import scala.collection.mutable.ListBuffer
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import scala.language.implicitConversions
import scala.util.Failure
import scala.util.Success
import org.joda.time.format.DateTimeFormat
import com.secdec.codepulse.userSettings
import com.secdec.codepulse.data.trace._
import com.secdec.codepulse.pages.traces.TraceDetailsPage
import com.secdec.codepulse.tracer.snippet.TraceWidgetry
import akka.actor.Cancellable
import net.liftweb.common.Full
import net.liftweb.common.Loggable
import net.liftweb.http._
import net.liftweb.http.rest._
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._
import net.liftweb.util.Helpers.AsBoolean
import net.liftweb.util.Helpers.AsInt
import com.secdec.codepulse.components.notifications.Notifications
import com.secdec.codepulse.components.notifications.Notifications.NotificationId
import java.net.BindException
import java.util.Locale

class TraceAPIServer(manager: TraceManager, treeBuilderManager: TreeBuilderManager) extends RestHelper with Loggable {

	import ActivityRequest._

	implicit class RichRecordingMetadata(rec: RecordingMetadata) {
		def toJson = {
			val idField = Some { JField("id", rec.id) }
			val runningField = Some { JField("running", rec.running) }
			val labelField = for (label <- rec.clientLabel) yield JField("label", label)
			val colorField = for (color <- rec.clientColor) yield JField("color", color)
<commit_msg>Use a private cached threadpool for TraceAPIServer.<commit_after>/*
 * Code Pulse: A real-time code coverage testing tool. For more information
 * see http://code-pulse.com
 *
 * Copyright (C) 2014 Applied Visions - http://securedecisions.avi.com
 *
 * 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.secdec.codepulse.tracer

import scala.collection.mutable.ListBuffer
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import scala.language.implicitConversions
import scala.util.Failure
import scala.util.Success
import org.joda.time.format.DateTimeFormat
import com.secdec.codepulse.userSettings
import com.secdec.codepulse.data.trace._
import com.secdec.codepulse.pages.traces.TraceDetailsPage
import com.secdec.codepulse.tracer.snippet.TraceWidgetry
import akka.actor.Cancellable
import net.liftweb.common.Full
import net.liftweb.common.Loggable
import net.liftweb.http._
import net.liftweb.http.rest._
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._
import net.liftweb.util.Helpers.AsBoolean
import net.liftweb.util.Helpers.AsInt
import com.secdec.codepulse.components.notifications.Notifications
import com.secdec.codepulse.components.notifications.Notifications.NotificationId
import java.net.BindException
import java.util.Locale
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors

class TraceAPIServer(manager: TraceManager, treeBuilderManager: TreeBuilderManager) extends RestHelper with Loggable {

	implicit val executionContext = ExecutionContext fromExecutor Executors.newCachedThreadPool

	import ActivityRequest._

	implicit class RichRecordingMetadata(rec: RecordingMetadata) {
		def toJson = {
			val idField = Some { JField("id", rec.id) }
			val runningField = Some { JField("running", rec.running) }
			val labelField = for (label <- rec.clientLabel) yield JField("label", label)
			val colorField = for (color <- rec.clientColor) yield JField("color", color)

{'fraction_non_alphanumeric': 0.08630393996247655, 'fraction_numerical': 0.003335417969564311, 'mean_word_length': 5.020075282308658, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1117913', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1357, 'n_words': 400}