// Path: src/main/java/org/weakref/jmx/JmxException.java
// public enum Reason
// {
//     INVALID_ANNOTATION,
//     MALFORMED_OBJECT_NAME,
//     INSTANCE_ALREADY_EXISTS,
//     INSTANCE_NOT_FOUND,
//     MBEAN_REGISTRATION
// }


import com.google.common.collect.ImmutableMap;
import com.google.common.collect.MapMaker;
import com.google.inject.Inject;
import org.weakref.jmx.JmxException.Reason;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
        requireNonNull(type, "type is null");
        requireNonNull(name, "name is null");
        ObjectName objectName = createObjectName(objectNameGenerator.generatedNameOf(type, name));
        export(objectName, object);
        return new MBeanExport(objectName, () -> unexport(objectName));
    }

    public MBeanExport exportWithGeneratedName(Object object, Class<?> type, Map<String, String> properties)
    {
        requireNonNull(object, "object is null");
        requireNonNull(type, "type is null");
        requireNonNull(properties, "properties is null");
        ObjectName objectName = createObjectName(objectNameGenerator.generatedNameOf(type, properties));
        export(objectName, object);
        return new MBeanExport(objectName, () -> unexport(objectName));
    }

    public void export(String name, Object object)
    {
        export(createObjectName(name), object);
    }

    public void export(ObjectName objectName, Object object)
    {
        try {
            MBeanBuilder builder = new MBeanBuilder(object);
            MBean mbean = builder.build();

            synchronized(exportedObjects) {
                if(exportedObjects.containsKey(objectName)) {
// Path: src/main/java/org/weakref/jmx/JmxException.java
// public enum Reason
// {
//     INVALID_ANNOTATION,
//     MALFORMED_OBJECT_NAME,
//     INSTANCE_ALREADY_EXISTS,
//     INSTANCE_NOT_FOUND,
//     MBEAN_REGISTRATION
// }


// Path: src/main/java/org/weakref/jmx/MBeanExporter.java
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.MapMaker;
import com.google.inject.Inject;
import org.weakref.jmx.JmxException.Reason;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import static java.util.Objects.requireNonNull;

        requireNonNull(type, "type is null");
        requireNonNull(name, "name is null");
        ObjectName objectName = createObjectName(objectNameGenerator.generatedNameOf(type, name));
        export(objectName, object);
        return new MBeanExport(objectName, () -> unexport(objectName));
    }

    public MBeanExport exportWithGeneratedName(Object object, Class<?> type, Map<String, String> properties)
    {
        requireNonNull(object, "object is null");
        requireNonNull(type, "type is null");
        requireNonNull(properties, "properties is null");
        ObjectName objectName = createObjectName(objectNameGenerator.generatedNameOf(type, properties));
        export(objectName, object);
        return new MBeanExport(objectName, () -> unexport(objectName));
    }

    public void export(String name, Object object)
    {
        export(createObjectName(name), object);
    }

    public void export(ObjectName objectName, Object object)
    {
        try {
            MBeanBuilder builder = new MBeanBuilder(object);
            MBean mbean = builder.build();

            synchronized(exportedObjects) {
                if(exportedObjects.containsKey(objectName)) {
                    throw new JmxException(Reason.INSTANCE_ALREADY_EXISTS, "key already exported: %s", objectName);