<commit_before>package org.eclipse.scanning.event.queues;

import java.util.List;
import java.util.UUID;

import org.eclipse.scanning.api.event.alive.HeartbeatBean;
import org.eclipse.scanning.api.event.queues.IHeartbeatMonitor;
import org.eclipse.scanning.api.event.queues.IQueueService;

public class HeartbeatMonitor implements IHeartbeatMonitor {
	
	public HeartbeatMonitor(UUID consumerID) {
		
	}
	
	public HeartbeatMonitor(String queueID) {
		
	}
	
	public HeartbeatMonitor (String queueID, IQueueService queueService) {
		
	}

	@Override
	public HeartbeatBean getLastHeartbeat() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<HeartbeatBean> getLatestHeartbeats() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getHeartbeatTopic() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setHeartbeatTopic(String topicName) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public UUID getConsumerID() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setConsumerID(UUID consumerID) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getQueueID() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setQueueID(String queueID) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getRecorderSize() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void setRecorderSize(int beats) {
		// TODO Auto-generated method stub
		
	}
	
<commit_msg>Initial implementation of the class & constructors.<commit_after>package org.eclipse.scanning.event.queues;

import java.net.URI;
import java.util.List;
import java.util.UUID;

import org.eclipse.scanning.api.event.EventException;
import org.eclipse.scanning.api.event.IEventService;
import org.eclipse.scanning.api.event.alive.HeartbeatBean;
import org.eclipse.scanning.api.event.alive.HeartbeatEvent;
import org.eclipse.scanning.api.event.alive.IHeartbeatListener;
import org.eclipse.scanning.api.event.core.ISubscriber;
import org.eclipse.scanning.api.event.queues.IHeartbeatMonitor;
import org.eclipse.scanning.api.event.queues.IQueue;
import org.eclipse.scanning.api.event.queues.IQueueService;
import org.eclipse.scanning.api.event.queues.SizeLimitedRecorder;
import org.eclipse.scanning.api.event.queues.beans.Queueable;

public class HeartbeatMonitor implements IHeartbeatMonitor {

	private URI uri;
	private String heartbeatTopic;

	private ISubscriber<IHeartbeatListener> monitor;
	private SizeLimitedRecorder<HeartbeatBean> heartbeatRecord;

	private UUID monitoredConsumerID;
	private String queueID = null;

	/**
	 * Set up directly from a given consumer ID.
	 * 
	 * @param uri Location of the JMS broker.
	 * @param heartbeatTopic on which {@link HeartbeatBeans} are published.
	 * @param consumerID UUID to listen for.
	 * @throws EventException In case listener cannot be added correctly.
	 */
	public HeartbeatMonitor(URI uri, String heartbeatTopic, UUID consumerID) throws EventException {
		this.uri = uri;
		this.heartbeatTopic = heartbeatTopic;
		monitoredConsumerID = consumerID;
		setUpMonitor();
	}

	/**
	 * Set up using an {@link IQueue} instance.
	 * 
	 * @param uri Location of the JMS broker.
	 * @param heartbeatTopic on which {@link HeartbeatBeans} are published.
	 * @param queue {@link IQueue} object to monitor
	 * @throws EventException In case listener cannot be added correctly.
	 */
	public HeartbeatMonitor(URI uri, String heartbeatTopic, 
			IQueue<? extends Queueable> queue) throws EventException {
		this.uri = uri;
		this.heartbeatTopic = heartbeatTopic;
		monitoredConsumerID = queue.getConsumerID();
		setUpMonitor();
	}

	/**
	 * Set up using the queueID string name and the {@link IQueueService} which
	 *  maintains this queue.
	 * 
	 * @param  uri Location of the JMS broker.
	 * @param heartbeatTopic on which {@link HeartbeatBeans} are published.
	 * @param queueID String name of queue in {@link IQueueService}
	 * @param queueService {@link IQueueService} with reference to the 
	 *                     {@link IQueue} to monitor.
	 * @throws EventException In case listener cannot be added correctly.
	 */
	public HeartbeatMonitor(URI uri, String heartbeatTopic, String queueID, 
			IQueueService queueService) throws EventException {
		this.uri = uri;
		this.heartbeatTopic = heartbeatTopic;

		//Get consumerID through the IQueueService
		if (queueID.equals(queueService.getJobQueueID())) {
			monitoredConsumerID = queueService.getJobQueue().getConsumerID();
		} else {
			monitoredConsumerID = queueService.getActiveQueue(queueID).getConsumerID();
		}
		setUpMonitor();
		setQueueID(queueID);
	}

	private void setUpMonitor() throws EventException {
		heartbeatRecord = new SizeLimitedRecorder<>(100);
		
		IEventService evServ = QueueServicesHolder.getEventService();
		monitor = evServ.createSubscriber(uri, heartbeatTopic);
		monitor.addListener(new IHeartbeatListener() {
			@Override
			public void heartbeatPerformed(HeartbeatEvent evt) {
				HeartbeatBean beat = evt.getBean();
				if (beat.getConsumerId().equals(monitoredConsumerID)) {
					//Only add beans if they are from this consumer!!
					heartbeatRecord.add(beat);
				}
			}
		});
	}

	@Override
	public HeartbeatBean getLastHeartbeat() {
		return heartbeatRecord.latest();
	}

	@Override
	public List<HeartbeatBean> getLatestHeartbeats() {
		return heartbeatRecord.getRecording();
	}

	@Override
	public String getHeartbeatTopic() {
		return heartbeatTopic;
	}

	@Override
	public void setHeartbeatTopic(String topicName) {
		heartbeatTopic = topicName;
	}

	@Override
	public UUID getConsumerID() {
		return monitoredConsumerID;
	}

	@Override
	public void setConsumerID(UUID consumerID) {
		monitoredConsumerID = consumerID;
	}

	@Override
	public String getQueueID() {
		return queueID;
	}

	@Override
	public void setQueueID(String queueID) {
		this.queueID = queueID;
	}

	@Override
	public int getRecorderCapacity() {
		return heartbeatRecord.getCapacity();
	}

	@Override
	public void setRecorderCapacity(int beats) {
		heartbeatRecord.setCapacity(beats);
	}
{'fraction_non_alphanumeric': 0.0904815955894276, 'fraction_numerical': 0.0006486135884546781, 'mean_word_length': 4.377506538796862, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2897234', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1823, 'n_words': 485}