<commit_before>/*
 * Copyright (c) 2015 Limerun Project Contributors
 * Portions Copyright (c) 2015 Internet of Protocols Assocation (IOPA)
 *
 * 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.
 */

const FreeList = require('freelist').FreeList;
const Events = require('events');
const Cancellation = require('../util/cancellation.js');
const URL = require('url');
const Promise = require('bluebird');
const util = require('util');

/* *********************************************************
 * IOPA CONTEXT
 * ********************************************************* */

/**
 * Represents IOPA Context object for any REST Request/Response
 * See http://iopa.io for further details
 *
 * @class IopaContext
 * @constructor
 */
function IopaContext(){
     if (!(this instanceof IopaContext)) {
    return new IopaContext()
  }

  return this;
}

var counter =

/**
 * Initialize blank IopaContext object
 * Generic properties common to all server types included
 *
 * @method Init
 */
 IopaContext.prototype.init = function IopaContext_init(){
  this["iopa.Version"] = "1.2";
  var _cancellationTokenSource = Cancellation();
  this["iopa.CallCancelledSource"] = _cancellationTokenSource;
  this["iopa.CallCancelled"] = _cancellationTokenSource.token;
  this["iopa.Events"] = new Events.EventEmitter();
  this["iopa.Seq"] = _nextSequence();
  return this;
};

/**
 * Represents IopaContext Factory of up to 100 items
 *
 * @instance IopaContextFactory

 * @method alloc()  get new IopaContext from pool or by creation if none available; remember to call context.init();
 * @method free(context)   return IopaContext to the pool for reuse
 */
// Arguments are (freelistName, maxSize, constructorForNewObjects)
var IopaContextFactory = new FreeList('IopaContext', 100, function() {
  return IopaContext.apply(Object.create(IopaContext.prototype));
});

module.exports = IopaContextFactory;

IopaContextFactory.create = function() {
    var context = IopaContextFactory.alloc().init();
    var response = IopaContextFactory.alloc().init();
    context.response = response;
    context.response.parent = context;
    return context;
};
    
IopaContextFactory.dispose = function(context) {
    context.log.info("[IOPA] Disposing iopa messages " + context["iopa.Seq"] + "-" + context.response["iopa.Seq"]);
    
    var response = context.response;<commit_msg>logger<commit_after>/*
 * Copyright (c) 2015 Limerun Project Contributors
 * Portions Copyright (c) 2015 Internet of Protocols Assocation (IOPA)
 *
 * 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.
 */

const FreeList = require('freelist').FreeList;
const Events = require('events');
const Cancellation = require('../util/cancellation.js');
const URL = require('url');
const Promise = require('bluebird');
const util = require('util');

/* *********************************************************
 * IOPA CONTEXT
 * ********************************************************* */

/**
 * Represents IOPA Context object for any REST Request/Response
 * See http://iopa.io for further details
 *
 * @class IopaContext
 * @constructor
 */
function IopaContext(){
     if (!(this instanceof IopaContext)) {
    return new IopaContext()
  }

  return this;
}

var counter =

/**
 * Initialize blank IopaContext object
 * Generic properties common to all server types included
 *
 * @method Init
 */
 IopaContext.prototype.init = function IopaContext_init(){
  this["iopa.Version"] = "1.2";
  var _cancellationTokenSource = Cancellation();
  this["iopa.CallCancelledSource"] = _cancellationTokenSource;
  this["iopa.CallCancelled"] = _cancellationTokenSource.token;
  this["iopa.Events"] = new Events.EventEmitter();
  this["iopa.Seq"] = _nextSequence();
  this["server.Logger"] = console;
  this.log = this["server.Logger"];
  return this;
};

/**
 * Represents IopaContext Factory of up to 100 items
 *
 * @instance IopaContextFactory

 * @method alloc()  get new IopaContext from pool or by creation if none available; remember to call context.init();
 * @method free(context)   return IopaContext to the pool for reuse
 */
// Arguments are (freelistName, maxSize, constructorForNewObjects)
var IopaContextFactory = new FreeList('IopaContext', 100, function() {
  return IopaContext.apply(Object.create(IopaContext.prototype));
});

module.exports = IopaContextFactory;

IopaContextFactory.create = function() {
    var context = IopaContextFactory.alloc().init();
    var response = IopaContextFactory.alloc().init();
    context.response = response;
    context.response.parent = context;
    return context;
};
    
IopaContextFactory.dispose = function(context) {
    context.log.info("[IOPA] Disposing iopa messages " + context["iopa.Seq"] + "-" + context.response["iopa.Seq"]);
    
    var response = context.response;
{'fraction_non_alphanumeric': 0.1504837595024188, 'fraction_numerical': 0.006910850034554251, 'mean_word_length': 4.545019157088123, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3596021', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1574, 'n_words': 507}