// Path: src/main/java/instrumentj/impl/ProfilerControllerImpl.java
// public final class ProfilerControllerImpl implements ProfilerController {
// 
//     private final AtomicBoolean active = new AtomicBoolean(false);
// 
//     private final Instrumentation instrumentation;
// 
//     private final ProbeExecutor probeExecutor;
// 
//     private ProbeManagerImpl probeManagerImpl;
// 
//     /**
//      *
//      * @param instrumentation
//      */
//     public ProfilerControllerImpl(final Instrumentation instrumentation) {
//         if (instrumentation == null) {
//             throw new NullPointerException("instrumentation");
//         }
// 
//         this.instrumentation = instrumentation;
//         this.probeManagerImpl = new ProbeManagerImpl(instrumentation);
//         this.probeExecutor = new ProbeExecutorImpl(probeManagerImpl);
//     }
// 
//     @Override
//     public void activate() {
//         active.set(true);
//     }
// 
//     @Override
//     public void deactivate() {
//         active.set(false);
//     }
// 
//     @Override
//     public long getObjectSize(final Object objectToSize) {
//         return instrumentation.getObjectSize(objectToSize);
//     }
// 
//     public ProbeExecutor getProbeExecutor() {
//         return probeExecutor;
//     }
// 
//     public ProbeManager getProbeManager() {
//         return probeManagerImpl;
//     }
// 
//     /**
//      * Initializes the {@link Instrumentation} with the
//      * {@link InstrumentingClassFileTransformer} and then {@link #activate()}'s
//      * this {@code ProfilerControllerImpl|
// 
//      */
//     public void initialize() {
//         instrumentation.addTransformer(new InstrumentingClassFileTransformer(this), true);
// 
//         activate();
//     }
// 
//     @Override
//     public boolean isActive() {
//         return active.get();
//     }
// 
//     void setProbeManagerImpl(final ProbeManagerImpl probeManagerImpl) {
//         this.probeManagerImpl = probeManagerImpl;
//     }
// }
// 
// Path: src/main/java/instrumentj/shell/ShellServer.java
// public class ShellServer implements Runnable {
// 
//     private static final Logger logger = Logger.getLogger(ShellServer.class.getName());
// 
//     private final Binding binding;
// 
//     private final int port;
// 
//     private volatile boolean run = true;
// 
//     private final Executor clientExecutor = Executors.newCachedThreadPool(new ThreadFactory() {
// 
//         private final AtomicInteger clientNumber = new AtomicInteger();
// 
//         @Override
//         public Thread newThread(final Runnable r) {
//             final Thread t = Executors.defaultThreadFactory().newThread(r);
//             t.setDaemon(true);
//             t.setName("profiler-client-" + clientNumber.incrementAndGet());
//             return t;
//         }
//     });
// 
//     private ServerSocket serverSocket;
// 
//     public ShellServer(final int port) {
//         this(port, new Binding());
//     }
// 
//     public ShellServer(final int port, final Binding binding) {
//         if (port < 1) {
//             throw new IllegalArgumentException("port");
//         }
// 
//         if (binding == null) {
//             throw new NullPointerException("binding");
//         }
// 
//         this.port = port;
//         this.binding = binding;
//     }
// 
//     @Override
//     public void run() {
// 
//         try {
//             serverSocket = new ServerSocket(port);
// 
//             while(run) {
//                 Socket client = null;
//                 try {
//                     client = serverSocket.accept();
// 
//                     if (!run) {
//                         try {
//                             client.close();
//                         } catch (final IOException e) {
//                             // Intentionally left blank
//                         }
// 
//                         return;
//                     }
// 
//                     final GroovyShellSession groovyShellSession = new GroovyShellSession(client, binding);
//                     clientExecutor.execute(groovyShellSession);
// 
//                 } catch (final IOException e) {
//                     logger.log(Level.SEVERE, "Unable to accept client connection", e);
//                 }
//             }
//         } catch (final IOException e) {
//             logger.log(Level.SEVERE, "Unable to setup shell server", e);
//         } finally {
//             if (serverSocket != null) {
//                 try {
//                     serverSocket.close();
//                 } catch (final IOException e) {
//                     // Intentionally left blank
//                 }
//             }
//         }
//     }
// 
//     public void stop() {
//         this.run = false;
//     }
// }


import groovy.lang.Binding;
import instrumentj.impl.ProfilerControllerImpl;
import instrumentj.shell.ShellServer;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import com.sun.tools.attach.VirtualMachine;
/*
 * 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 instrumentj;




/**
 * @author Stephen Evanchik (evanchsa@gmail.com)
 *
 */
public class Main {

    private static ProfilerControllerImpl profilerController;

    private static Executor shell = Executors.newSingleThreadExecutor(new ThreadFactory() {

        @Override
        public Thread newThread(final Runnable r) {
            final Thread t = Executors.defaultThreadFactory().newThread(r);
// Path: src/main/java/instrumentj/impl/ProfilerControllerImpl.java
// public final class ProfilerControllerImpl implements ProfilerController {
// 
//     private final AtomicBoolean active = new AtomicBoolean(false);
// 
//     private final Instrumentation instrumentation;
// 
//     private final ProbeExecutor probeExecutor;
// 
//     private ProbeManagerImpl probeManagerImpl;
// 
//     /**
//      *
//      * @param instrumentation
//      */
//     public ProfilerControllerImpl(final Instrumentation instrumentation) {
//         if (instrumentation == null) {
//             throw new NullPointerException("instrumentation");
//         }
// 
//         this.instrumentation = instrumentation;
//         this.probeManagerImpl = new ProbeManagerImpl(instrumentation);
//         this.probeExecutor = new ProbeExecutorImpl(probeManagerImpl);
//     }
// 
//     @Override
//     public void activate() {
//         active.set(true);
//     }
// 
//     @Override
//     public void deactivate() {
//         active.set(false);
//     }
// 
//     @Override
//     public long getObjectSize(final Object objectToSize) {
//         return instrumentation.getObjectSize(objectToSize);
//     }
// 
//     public ProbeExecutor getProbeExecutor() {
//         return probeExecutor;
//     }
// 
//     public ProbeManager getProbeManager() {
//         return probeManagerImpl;
//     }
// 
//     /**
//      * Initializes the {@link Instrumentation} with the
//      * {@link InstrumentingClassFileTransformer} and then {@link #activate()}'s
//      * this {@code ProfilerControllerImpl|
// 
//      */
//     public void initialize() {
//         instrumentation.addTransformer(new InstrumentingClassFileTransformer(this), true);
// 
//         activate();
//     }
// 
//     @Override
//     public boolean isActive() {
//         return active.get();
//     }
// 
//     void setProbeManagerImpl(final ProbeManagerImpl probeManagerImpl) {
//         this.probeManagerImpl = probeManagerImpl;
//     }
// }
// 
// Path: src/main/java/instrumentj/shell/ShellServer.java
// public class ShellServer implements Runnable {
// 
//     private static final Logger logger = Logger.getLogger(ShellServer.class.getName());
// 
//     private final Binding binding;
// 
//     private final int port;
// 
//     private volatile boolean run = true;
// 
//     private final Executor clientExecutor = Executors.newCachedThreadPool(new ThreadFactory() {
// 
//         private final AtomicInteger clientNumber = new AtomicInteger();
// 
//         @Override
//         public Thread newThread(final Runnable r) {
//             final Thread t = Executors.defaultThreadFactory().newThread(r);
//             t.setDaemon(true);
//             t.setName("profiler-client-" + clientNumber.incrementAndGet());
//             return t;
//         }
//     });
// 
//     private ServerSocket serverSocket;
// 
//     public ShellServer(final int port) {
//         this(port, new Binding());
//     }
// 
//     public ShellServer(final int port, final Binding binding) {
//         if (port < 1) {
//             throw new IllegalArgumentException("port");
//         }
// 
//         if (binding == null) {
//             throw new NullPointerException("binding");
//         }
// 
//         this.port = port;
//         this.binding = binding;
//     }
// 
//     @Override
//     public void run() {
// 
//         try {
//             serverSocket = new ServerSocket(port);
// 
//             while(run) {
//                 Socket client = null;
//                 try {
//                     client = serverSocket.accept();
// 
//                     if (!run) {
//                         try {
//                             client.close();
//                         } catch (final IOException e) {
//                             // Intentionally left blank
//                         }
// 
//                         return;
//                     }
// 
//                     final GroovyShellSession groovyShellSession = new GroovyShellSession(client, binding);
//                     clientExecutor.execute(groovyShellSession);
// 
//                 } catch (final IOException e) {
//                     logger.log(Level.SEVERE, "Unable to accept client connection", e);
//                 }
//             }
//         } catch (final IOException e) {
//             logger.log(Level.SEVERE, "Unable to setup shell server", e);
//         } finally {
//             if (serverSocket != null) {
//                 try {
//                     serverSocket.close();
//                 } catch (final IOException e) {
//                     // Intentionally left blank
//                 }
//             }
//         }
//     }
// 
//     public void stop() {
//         this.run = false;
//     }
// }


// Path: src/main/java/instrumentj/Main.java
import groovy.lang.Binding;
import instrumentj.impl.ProfilerControllerImpl;
import instrumentj.shell.ShellServer;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import com.sun.tools.attach.VirtualMachine;

/*
 * 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 instrumentj;




/**
 * @author Stephen Evanchik (evanchsa@gmail.com)
 *
 */
public class Main {

    private static ProfilerControllerImpl profilerController;

    private static Executor shell = Executors.newSingleThreadExecutor(new ThreadFactory() {

        @Override
        public Thread newThread(final Runnable r) {
            final Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);