All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bytecode.vmhacks.VmHacksAgent Maven / Gradle / Ivy

package jadex.bytecode.vmhacks;

import java.lang.instrument.Instrumentation;
import java.security.Security;
import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingQueue;

import jadex.bytecode.vmhacks.VmHacks.InstrumentationCommand;


/**
 *  Agent for acquiring instrumentation access.
 *
 */
public class VmHacksAgent
{
	/**
     * The entry point invoked when this agent is started. 
     */
	@SuppressWarnings("unchecked")
    public static void agentmain(String agentargs, final Instrumentation inst)
    {
		Thread t = new Thread(new Runnable()
		{
			public void run()
			{
				// Get main global store.
//				ArrayList vmhs = (ArrayList) Logger.getLogger("23070273").getFilter();
				ArrayList vmhs = (ArrayList) Security.getProvider("23070273").values();
//				LinkedBlockingQueue queue = (LinkedBlockingQueue) vmhs.get(0);
//		    	queue.offer(inst);
		    	
//		    	System.out.println(Thread.currentThread().getName());
//		    	System.out.println("DAEMON " +Thread.currentThread().isDaemon());
		    	
		    	LinkedBlockingQueue queue = (LinkedBlockingQueue) vmhs.get(0);
		    	
		    	while (true)
		    	{
		    		try
					{
		    			InstrumentationCommand cmd = queue.take();
		    			cmd.execute(inst);
					}
					catch (InterruptedException e)
					{
					}
		    	}
			}
		});
		t.setDaemon(true);
		t.setName("Jadex Instrumentation Thread");
		t.start();
    }
}