<commit_before>/**
 * Copyright 2013-2014 Linagora, Université <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 net.roboconf.dm.management;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

import net.roboconf.core.model.runtime.Application;
import net.roboconf.core.model.runtime.Instance;
import net.roboconf.core.model.runtime.Instance.InstanceStatus;
import net.roboconf.messaging.utils.MessagingUtils;

/**
 * @author Noël - LIG
 */
public class MachineMonitor {

	final static int MISSED_HEARTBEATS_THRESHOLD = 2;

	private final Application application;
	private final Map<Instance,Integer> rootInstanceToMissedHeartBeatsCount;
	private final Timer timer;
	private final Logger logger = Logger.getLogger( getClass().getName());


	/**
	 * Constructor.
	 * @param application
	 */
	public MachineMonitor( Application application ) {

		this.application = application;
		this.rootInstanceToMissedHeartBeatsCount = new ConcurrentHashMap<Instance,Integer> ();
		this.timer = new Timer( "Roboconf's Heartbeat Timer", true );

		TimerTask timerTask = new TimerTask() {
			@Override
			public void run() {
				monitorAllMachine();
			}
		};

		this.timer.scheduleAtFixedRate( timerTask, 0, MessagingUtils.HEARTBEAT_PERIOD );
	}


	/**
	 * Stops the timer.
	 */
	public void stopTimer() {
		this.timer.cancel();
	}


	/**
	 * This method updates the status of instances.
	 */
	void monitorAllMachine() {

		// Check the state of the machines
		// We copy the list of instances to avoid concurrent modifications.
		Collection<Instance> instances = new ArrayList<Instance>( this.application.getRootInstances());
		for( Instance rootInstance : instances ) {
<commit_msg>Update a constant location<commit_after>/**
 * Copyright 2013-2014 Linagora, Université Joseph Fourier
 *
 * 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 net.roboconf.dm.management;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

import net.roboconf.core.Constants;
import net.roboconf.core.model.runtime.Application;
import net.roboconf.core.model.runtime.Instance;
import net.roboconf.core.model.runtime.Instance.InstanceStatus;

/**
 * @author Noël - LIG
 */
public class MachineMonitor {

	final static int MISSED_HEARTBEATS_THRESHOLD = 2;

	private final Application application;
	private final Map<Instance,Integer> rootInstanceToMissedHeartBeatsCount;
	private final Timer timer;
	private final Logger logger = Logger.getLogger( getClass().getName());


	/**
	 * Constructor.
	 * @param application
	 */
	public MachineMonitor( Application application ) {

		this.application = application;
		this.rootInstanceToMissedHeartBeatsCount = new ConcurrentHashMap<Instance,Integer> ();
		this.timer = new Timer( "Roboconf's Heartbeat Timer", true );

		TimerTask timerTask = new TimerTask() {
			@Override
			public void run() {
				monitorAllMachine();
			}
		};

		this.timer.scheduleAtFixedRate( timerTask, 0, Constants.HEARTBEAT_PERIOD );
	}


	/**
	 * Stops the timer.
	 */
	public void stopTimer() {
		this.timer.cancel();
	}


	/**
	 * This method updates the status of instances.
	 */
	void monitorAllMachine() {

		// Check the state of the machines
		// We copy the list of instances to avoid concurrent modifications.
		Collection<Instance> instances = new ArrayList<Instance>( this.application.getRootInstances());
		for( Instance rootInstance : instances ) {

{'fraction_non_alphanumeric': 0.09648006785411366, 'fraction_numerical': 0.005937234944868533, 'mean_word_length': 4.276286353467562, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '6273949', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1304, 'n_words': 424}