<commit_before>package ActiveMQ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;

import plugincore.PluginEngine;
import shared.MsgEvent;
import shared.MsgEventType;


public class ActiveDestManager implements Runnable 
{
	//private MulticastSocket socket;
	private Timer timer;
	private ActiveMQConnection activeMQConnection;
	
	public ActiveDestManager(String URI)
	{
		
		//timer = new Timer();
	    //timer.scheduleAtFixedRate(new BrokerWatchDog(), 500, 300000);//remote 
		//timer.scheduleAtFixedRate(new BrokerWatchDog(), 500, 15000);//remote
		try{
			ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(URI);
			//Connection conn = factory.createConnection();
			//conn.start();
			activeMQConnection = (ActiveMQConnection) factory.createConnection();
		    activeMQConnection.start();
		
		}
		catch(Exception ex)
		{
			System.out.println("ActiveDestManager Init : Run Error " + ex.toString());
			PluginEngine.ActiveDestManagerActive = false;
		}
	}
	  
	public void shutdown()
	{
	
	}
		  
	  public void run() 
	  {
		  PluginEngine.ActiveDestManagerActive = true;
		    
		  System.out.println("Checking Queues");
			
		//List<String> agentList = new ArrayList<String>();
		//Map<String,ActiveProducer> cm = new HashMap<String,ActiveProducer>();
		while(PluginEngine.ActiveDestManagerActive)
	    {
			int count = 0; //count queues
			
		  try 
		  {
			  
			  ActiveMQDestination[] er = PluginEngine.broker.broker.getBroker().getDestinations();
			  for(ActiveMQDestination des : er)
			  {
				 	if(des.isQueue())
					{
						boolean reachable = false;
				 		count++;
						for(String path : des.getDestinationPaths())
						{
							if(!des.getPhysicalName().equals(PluginEngine.agentpath))
							{
								reachable = true;
								//System.out.println("Dest: " + des.getPhysicalName() + " is reachable = " + PluginEngine.isReachableAgent(des.getPhysicalName()));

								String[] str = des.getPhysicalName().split("_");
								MsgEvent sme = new MsgEvent(MsgEventType.INFO,PluginEngine.region,PluginEngine.agent,PluginEngine.plugin,"Discovery request.");
								sme.setParam("src_region",PluginEngine.region);
								sme.setParam("src_agent",PluginEngine.agent);
								sme.setParam("dst_region",str[0]);
								sme.setParam("dst_agent",str[1]);
								  
								//
								
								//PluginEngine.outgoingMessages.offer(sme);
								if (!PluginEngine.ap.sendMessage(sme)) {
									System.out.println("Message send failure!");
								}
								//if(!cm.containsKey(des.getPhysicalName()))
								//{
								/*
									if(PluginEngine.isReachableAgent(des.getPhysicalName()))
									{
										//System.out.println("Dest: " + des.getPhysicalName() + "starting feed");
										//ActiveProducer ap = new ActiveProducer(des.getPhysicalName(),"tcp://[::1]:32010");
										//cm.put(des.getPhysicalName(), ap);
										//new Thread(ap).start();
										
									}
									*/
								//}
									/*
								else
								{
									if(!PluginEngine.isReachableAgent(des.getPhysicalName()))
									{<commit_msg>Debug message change<commit_after>package ActiveMQ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;

import plugincore.PluginEngine;
import shared.MsgEvent;
import shared.MsgEventType;


public class ActiveDestManager implements Runnable 
{
	//private MulticastSocket socket;
	private Timer timer;
	private ActiveMQConnection activeMQConnection;
	
	public ActiveDestManager(String URI)
	{
		
		//timer = new Timer();
	    //timer.scheduleAtFixedRate(new BrokerWatchDog(), 500, 300000);//remote 
		//timer.scheduleAtFixedRate(new BrokerWatchDog(), 500, 15000);//remote
		try{
			ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(URI);
			//Connection conn = factory.createConnection();
			//conn.start();
			activeMQConnection = (ActiveMQConnection) factory.createConnection();
		    activeMQConnection.start();
		
		}
		catch(Exception ex)
		{
			System.out.println("ActiveDestManager Init : Run Error " + ex.toString());
			PluginEngine.ActiveDestManagerActive = false;
		}
	}
	  
	public void shutdown()
	{
	
	}
		  
	  public void run() 
	  {
		  PluginEngine.ActiveDestManagerActive = true;
		    
		  System.out.println("Checking Queues");
			
		//List<String> agentList = new ArrayList<String>();
		//Map<String,ActiveProducer> cm = new HashMap<String,ActiveProducer>();
		while(PluginEngine.ActiveDestManagerActive)
	    {
			int count = 0; //count queues
			
		  try 
		  {
			  
			  ActiveMQDestination[] er = PluginEngine.broker.broker.getBroker().getDestinations();
			  for(ActiveMQDestination des : er)
			  {
				 	if(des.isQueue())
					{
						boolean reachable = false;
				 		count++;
						for(String path : des.getDestinationPaths())
						{
							if(!des.getPhysicalName().equals(PluginEngine.agentpath))
							{
								reachable = true;
								//System.out.println("Dest: " + des.getPhysicalName() + " is reachable = " + PluginEngine.isReachableAgent(des.getPhysicalName()));

								String[] str = des.getPhysicalName().split("_");
								MsgEvent sme = new MsgEvent(MsgEventType.INFO,PluginEngine.region,PluginEngine.agent,PluginEngine.plugin,"Discovery request.");
								sme.setParam("src_region",PluginEngine.region);
								sme.setParam("src_agent",PluginEngine.agent);
								sme.setParam("dst_region",str[0]);
								sme.setParam("dst_agent",str[1]);
								  
								//
								if (count > 20) continue;
								//PluginEngine.outgoingMessages.offer(sme);
								if (!PluginEngine.ap.sendMessage(sme)) {
									System.out.println("Message send failure!");
								}
								//if(!cm.containsKey(des.getPhysicalName()))
								//{
								/*
									if(PluginEngine.isReachableAgent(des.getPhysicalName()))
									{
										//System.out.println("Dest: " + des.getPhysicalName() + "starting feed");
										//ActiveProducer ap = new ActiveProducer(des.getPhysicalName(),"tcp://[::1]:32010");
										//cm.put(des.getPhysicalName(), ap);
										//new Thread(ap).start();
										
									}
									*/
								//}
									/*
								else
								{
									if(!PluginEngine.isReachableAgent(des.getPhysicalName()))
									{
{'fraction_non_alphanumeric': 0.1251583481124905, 'fraction_numerical': 0.006840638459589561, 'mean_word_length': 3.3450742982938912, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '3216964', 'n_tokens_mistral': 3137, 'n_tokens_neox': 2311, 'n_words': 372}