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

io.takari.orchestra.plugins.nexus.perf.AgentPoolHolder Maven / Gradle / Ivy

The newest version!
package io.takari.orchestra.plugins.nexus.perf;

import com.sonatype.nexus.perftest.controller.AgentPool;
import com.sonatype.nexus.perftest.controller.JMXServiceURLs;

import javax.inject.Named;
import javax.inject.Singleton;
import java.util.HashMap;
import java.util.Map;

@Named
@Singleton
public class AgentPoolHolder {

    private final Map agents = new HashMap<>();

    /**
     * Creates a new JMX agent pool for specified URLs.
     *
     * @param id   Unique ID that will be associated with the created pool.
     * @param urls
     */
    public void connect(String id, String[] urls) {
        synchronized (agents) {
            AgentPoolManager m = agents.get(id);
            if (m != null) {
                throw new IllegalStateException("The agent pool for '" + id + "' is already created");
            }

            m = new AgentPoolManager(new AgentPool(JMXServiceURLs.of(urls)));
            agents.put(id, m);
        }
    }

    public AgentPoolManager get(String id) {
        synchronized (agents) {
            return agents.get(id);
        }
    }

    public void close(String id) {
        AgentPoolManager m = null;

        synchronized (agents) {
            m = agents.remove(id);
        }

        if (m == null) {
            return;
        }

        m.release();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy