<commit_before>package br.usp.icmc.lasdpc.cloudsim;

import java.util.List;

import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.SimEvent;

public class OnlineBroker extends SimEntity {
	
	/** Sample time to monitoring, processing and afterwards effecting */
	private int sampleTime;
	
	/** Unique identification (tag) for Sample events. */
	private static final int SAMPLE_TIME = 80801;
	
	/** Monitor class, its responsibility is get information about the system */
	private Monitor monitor;
	
	/** Effector class, its responsibility is set demand and capacity against/of the systems */
	private Effector effector;
	
	/** Capacity class, its responsibility is generate a list of events about the amount of VMs in the system  */
	private Capacity capacity;
	
	/** Demand class, its responsibility is generate a list of events about the tasks to be imposed in the system */
	private Demand demand;
	
	
	public OnlineBroker(String name, int sampleTime, Monitor monitor, 
			Effector effector, Capacity capacity, Demand demand) throws Exception {
		super(name);
		
		this.sampleTime = sampleTime;
		this.monitor = monitor;
		this.capacity = capacity;
		this.effector = effector;
		this.effector.setMybroker(this);
		this.demand = demand;
	}

	@Override
	public void startEntity() {
		sendNow(getId(), SAMPLE_TIME);
	}

	@Override
	public void processEvent(SimEvent ev) {
		switch (ev.getTag()) {
		case SAMPLE_TIME:
				processSample(ev);
			break;
			
		case CloudSimTags.END_OF_SIMULATION:
				done();
			break;

		default:
				Log.printConcatLine("Ouch... event tag not found.");
			break;
		}
	}

	@Override
	public void shutdownEntity() {
		Log.printConcatLine(CloudSim.clock() + ": " + getName() + " shut down.");
	}

	private void done() {
		Log.printConcatLine("Ending " + getName() + " at CloudSim.Clock(): " 
				+ CloudSim.clock());
		setState(FINISHED);
	}
	
	private void processSample(SimEvent ev) {
		// process...
		List<Double> values = monitor.get();
		System.out.println(values.get(0) + " Sample time is ticking...");
		effector.set(capacity.update(values), demand.update(values));
		
		// schedule the next sample time event.
		send(getId(), sampleTime, SAMPLE_TIME);
	}
	
	public void sendEvents(List<Event> events) {
		for (Event e : events) {
			send(getId(), e.getDelay(), e.getTag(), e.getData());
		}
	}
}
<commit_msg>OnlineBroker extends DataCenterBroker; added processResourceCharacteristics.<commit_after>package br.usp.icmc.lasdpc.cloudsim;

import java.util.ArrayList;
import java.util.List;

import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;

public class OnlineBroker extends DatacenterBroker {
	
	/** Sample time to monitoring, processing and afterwards effecting */
	private int sampleTime;
	
	/** Unique identification (tag) for Sample events. */
	private static final int SAMPLE_TIME = 80801;
	
	/** Monitor class, its responsibility is get information about the system */
	private Monitor monitor;
	
	/** Effector class, its responsibility is set demand and capacity against/of the systems */
	private Effector effector;
	
	/** Capacity class, its responsibility is generate a list of events about the amount of VMs in the system  */
	private Capacity capacity;
	
	/** Demand class, its responsibility is generate a list of events about the tasks to be imposed in the system */
	private Demand demand;
	
	
	public OnlineBroker(String name, int sampleTime, Monitor monitor, 
			Effector effector, Capacity capacity, Demand demand) throws Exception {
		super(name);
		
		this.sampleTime = sampleTime;
		this.monitor = monitor;
		this.capacity = capacity;
		this.effector = effector;
		this.effector.setMybroker(this);
		this.demand = demand;
	}

	@Override
	public void startEntity() {
		super.startEntity();
		sendNow(getId(), SAMPLE_TIME);
	}

	@Override
	public void processEvent(SimEvent ev) {
		switch (ev.getTag()) {
		case SAMPLE_TIME:
				processSample(ev);
			break;
			
		case CloudSimTags.END_OF_SIMULATION:
				done();
			break;
			
		case CloudSimTags.RESOURCE_CHARACTERISTICS:
				processResourceCharacteristics(ev);
			break;
			
		default:
				super.processEvent(ev);
			break;
		}
	}

	@Override
	protected void processResourceCharacteristics(SimEvent ev) {
		DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData();
		getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics);

		if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) {
			setDatacenterRequestedIdsList(new ArrayList<Integer>());
		}
	}

	private void done() {
		Log.printConcatLine("Ending " + getName() + " at CloudSim.Clock(): " 
				+ CloudSim.clock());
		setState(FINISHED);
	}
	
	private void processSample(SimEvent ev) {
		effector.set(capacity.update(monitor.get()), demand.update(monitor.get()));
		send(getId(), sampleTime, SAMPLE_TIME);
	}
	
	public void sendEvents(List<Event> events) {
		for (Event e : events) {
			send(getId(), e.getDelay(), e.getTag(), e.getData());
		}
	}
}

{'fraction_non_alphanumeric': 0.11017897091722595, 'fraction_numerical': 0.0020507084265473526, 'mean_word_length': 4.275319567354965, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6265031', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1608, 'n_words': 444}