<commit_before>#!/usr/bin/env ruby
# encoding: UTF-8
#
# Copyright 2012-2014, Continuuity, 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.
#


require_relative 'tenantspec'
require_relative 'logging'
require_relative 'workerlauncher'
require_relative 'resourcemanager'

module Loom
  class TenantManager
    include Logging
    attr_accessor :spec, :resourcemanager
    attr_reader :status, :config, :provisioner_id, :sync_requests

    def initialize(spec, config, provisioner_id)
      unless spec.instance_of?(TenantSpec)
        raise ArgumentError, "TenantManager needs to be initialized with object of type TenantSpec", caller
      end
      @spec = spec
      @config = config
      @provisioner_id = provisioner_id
      @workerpids = []
      @terminating_workers = []
      @resourcemanager = ResourceManager.new(spec.resourcespec, spec.id, config)
      @sync_requests = 0

    end 

    def id
      @spec.id
    end

    def num_workers
      @workerpids.size
    end

    # launch the specified number of worker processes
    def spawn
      @spec.workers.times do |i|
        spawn_worker_process
      end
    end

    def resource_sync_needed
      @status = 'STALE'
      @sync_requests += 1
      terminate_all_worker_processes
    end

    def resource_sync_needed?
      'STALE' == @status && @sync_requests > 0
    end

    def sync
      @resourcemanager.sync
      @sync_requests -= 1<commit_msg>avoid unnecessary syncs by setting sync_requests to 0 prior to sync<commit_after>#!/usr/bin/env ruby
# encoding: UTF-8
#
# Copyright 2012-2014, Continuuity, 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.
#


require_relative 'tenantspec'
require_relative 'logging'
require_relative 'workerlauncher'
require_relative 'resourcemanager'

module Loom
  class TenantManager
    include Logging
    attr_accessor :spec, :resourcemanager
    attr_reader :status, :config, :provisioner_id, :sync_requests

    def initialize(spec, config, provisioner_id)
      unless spec.instance_of?(TenantSpec)
        raise ArgumentError, "TenantManager needs to be initialized with object of type TenantSpec", caller
      end
      @spec = spec
      @config = config
      @provisioner_id = provisioner_id
      @workerpids = []
      @terminating_workers = []
      @resourcemanager = ResourceManager.new(spec.resourcespec, spec.id, config)
      @sync_requests = 0

    end 

    def id
      @spec.id
    end

    def num_workers
      @workerpids.size
    end

    # launch the specified number of worker processes
    def spawn
      @spec.workers.times do |i|
        spawn_worker_process
      end
    end

    def resource_sync_needed
      @status = 'STALE'
      @sync_requests += 1
      terminate_all_worker_processes
    end

    def resource_sync_needed?
      'STALE' == @status && @sync_requests > 0
    end

    def sync
      @sync_requests = 0
      @resourcemanager.sync
{'fraction_non_alphanumeric': 0.07203281209946168, 'fraction_numerical': 0.008972058446552167, 'mean_word_length': 3.186695278969957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1080752', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1093, 'n_words': 381}