Java Code Examples for com.sun.jmx.remote.util.EnvHelp#initCause()

The following examples show how to use com.sun.jmx.remote.util.EnvHelp#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMBeanServerInterceptor.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private NotificationListener getListener(ObjectName listener)
    throws ListenerNotFoundException {
    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance;
    try {
        instance = getMBean(listener);
    } catch (InstanceNotFoundException e) {
        throw EnvHelp.initCause(
                      new ListenerNotFoundException(e.getMessage()), e);
    }

    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        final RuntimeException exc =
            new IllegalArgumentException(listener.getCanonicalName());
        final String msg =
            "MBean " + listener.getCanonicalName() + " does not " +
            "implement " + NotificationListener.class.getName();
        throw new RuntimeOperationsException(exc, msg);
    }
    return (NotificationListener) resource;
}
 
Example 2
Source File: DefaultMBeanServerInterceptor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException  {

    try {
        return createMBean(className, name, null, true,
                           params, signature);
    } catch (InstanceNotFoundException e) {
        /* Can only happen if loaderName doesn't exist, but we just
           passed null, so we shouldn't get this exception.  */
        throw EnvHelp.initCause(
            new IllegalArgumentException("Unexpected exception: " + e), e);
    }
}
 
Example 3
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException  {

    try {
        return createMBean(className, name, null, true,
                           params, signature);
    } catch (InstanceNotFoundException e) {
        /* Can only happen if loaderName doesn't exist, but we just
           passed null, so we shouldn't get this exception.  */
        throw EnvHelp.initCause(
            new IllegalArgumentException("Unexpected exception: " + e), e);
    }
}
 
Example 4
Source File: ClientNotifForwarder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Import: should not remove a listener during reconnection, the reconnection
 * needs to change the listener list and that will possibly make removal fail.
 */
private synchronized void beforeRemove() throws IOException {
    while (beingReconnected) {
        if (state == TERMINATED) {
            throw new IOException("Terminated.");
        }

        try {
            wait();
        } catch (InterruptedException ire) {
            IOException ioe = new IOException(ire.toString());
            EnvHelp.initCause(ioe, ire);

            throw ioe;
        }
    }

    if (state == TERMINATED) {
        throw new IOException("Terminated.");
    }
}
 
Example 5
Source File: DefaultMBeanServerInterceptor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException  {

    try {
        return createMBean(className, name, null, true,
                           params, signature);
    } catch (InstanceNotFoundException e) {
        /* Can only happen if loaderName doesn't exist, but we just
           passed null, so we shouldn't get this exception.  */
        throw EnvHelp.initCause(
            new IllegalArgumentException("Unexpected exception: " + e), e);
    }
}
 
Example 6
Source File: ClientNotifForwarder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Import: should not remove a listener during reconnection, the reconnection
 * needs to change the listener list and that will possibly make removal fail.
 */
private synchronized void beforeRemove() throws IOException {
    while (beingReconnected) {
        if (state == TERMINATED) {
            throw new IOException("Terminated.");
        }

        try {
            wait();
        } catch (InterruptedException ire) {
            IOException ioe = new IOException(ire.toString());
            EnvHelp.initCause(ioe, ire);

            throw ioe;
        }
    }

    if (state == TERMINATED) {
        throw new IOException("Terminated.");
    }
}
 
Example 7
Source File: ClientNotifForwarder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Import: should not remove a listener during reconnection, the reconnection
 * needs to change the listener list and that will possibly make removal fail.
 */
private synchronized void beforeRemove() throws IOException {
    while (beingReconnected) {
        if (state == TERMINATED) {
            throw new IOException("Terminated.");
        }

        try {
            wait();
        } catch (InterruptedException ire) {
            IOException ioe = new IOException(ire.toString());
            EnvHelp.initCause(ioe, ire);

            throw ioe;
        }
    }

    if (state == TERMINATED) {
        throw new IOException("Terminated.");
    }
}
 
Example 8
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private NotificationListener getListener(ObjectName listener)
    throws ListenerNotFoundException {
    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance;
    try {
        instance = getMBean(listener);
    } catch (InstanceNotFoundException e) {
        throw EnvHelp.initCause(
                      new ListenerNotFoundException(e.getMessage()), e);
    }

    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        final RuntimeException exc =
            new IllegalArgumentException(listener.getCanonicalName());
        final String msg =
            "MBean " + listener.getCanonicalName() + " does not " +
            "implement " + NotificationListener.class.getName();
        throw new RuntimeOperationsException(exc, msg);
    }
    return (NotificationListener) resource;
}
 
Example 9
Source File: ArrayNotificationBuffer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void createListeners() {
    logger.debug("createListeners", "starts");

    synchronized (this) {
        createdDuringQuery = new HashSet<ObjectName>();
    }

    try {
        addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
                                creationListener, creationFilter, null);
        logger.debug("createListeners", "added creationListener");
    } catch (Exception e) {
        final String msg = "Can't add listener to MBean server delegate: ";
        RuntimeException re = new IllegalArgumentException(msg + e);
        EnvHelp.initCause(re, e);
        logger.fine("createListeners", msg + e);
        logger.debug("createListeners", e);
        throw re;
    }

    /* Spec doesn't say whether Set returned by QueryNames can be modified
       so we clone it. */
    Set<ObjectName> names = queryNames(null, broadcasterQuery);
    names = new HashSet<ObjectName>(names);

    synchronized (this) {
        names.addAll(createdDuringQuery);
        createdDuringQuery = null;
    }

    for (ObjectName name : names)
        addBufferListener(name);
    logger.debug("createListeners", "ends");
}
 
Example 10
Source File: ArrayNotificationBuffer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void createListeners() {
    logger.debug("createListeners", "starts");

    synchronized (this) {
        createdDuringQuery = new HashSet<ObjectName>();
    }

    try {
        addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
                                creationListener, creationFilter, null);
        logger.debug("createListeners", "added creationListener");
    } catch (Exception e) {
        final String msg = "Can't add listener to MBean server delegate: ";
        RuntimeException re = new IllegalArgumentException(msg + e);
        EnvHelp.initCause(re, e);
        logger.fine("createListeners", msg + e);
        logger.debug("createListeners", e);
        throw re;
    }

    /* Spec doesn't say whether Set returned by QueryNames can be modified
       so we clone it. */
    Set<ObjectName> names = queryNames(null, broadcasterQuery);
    names = new HashSet<ObjectName>(names);

    synchronized (this) {
        names.addAll(createdDuringQuery);
        createdDuringQuery = null;
    }

    for (ObjectName name : names)
        addBufferListener(name);
    logger.debug("createListeners", "ends");
}
 
Example 11
Source File: OpenMBeanAttributeInfoSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) {
    Object x = d.getFieldValue(name);
    if (x == null)
        return null;
    try {
        return convertFrom(x, openType);
    } catch (Exception e) {
        final String msg =
            "Cannot convert descriptor field " + name + "  to " +
            openType.getTypeName();
        throw EnvHelp.initCause(new IllegalArgumentException(msg), e);
    }
}
 
Example 12
Source File: ArrayNotificationBuffer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void createListeners() {
    logger.debug("createListeners", "starts");

    synchronized (this) {
        createdDuringQuery = new HashSet<ObjectName>();
    }

    try {
        addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
                                creationListener, creationFilter, null);
        logger.debug("createListeners", "added creationListener");
    } catch (Exception e) {
        final String msg = "Can't add listener to MBean server delegate: ";
        RuntimeException re = new IllegalArgumentException(msg + e);
        EnvHelp.initCause(re, e);
        logger.fine("createListeners", msg + e);
        logger.debug("createListeners", e);
        throw re;
    }

    /* Spec doesn't say whether Set returned by QueryNames can be modified
       so we clone it. */
    Set<ObjectName> names = queryNames(null, broadcasterQuery);
    names = new HashSet<ObjectName>(names);

    synchronized (this) {
        names.addAll(createdDuringQuery);
        createdDuringQuery = null;
    }

    for (ObjectName name : names)
        addBufferListener(name);
    logger.debug("createListeners", "ends");
}
 
Example 13
Source File: OpenMBeanAttributeInfoSupport.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) {
    Object x = d.getFieldValue(name);
    if (x == null)
        return null;
    try {
        return convertFrom(x, openType);
    } catch (Exception e) {
        final String msg =
            "Cannot convert descriptor field " + name + "  to " +
            openType.getTypeName();
        throw EnvHelp.initCause(new IllegalArgumentException(msg), e);
    }
}
 
Example 14
Source File: RMIConnectorServer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a new IOException with a nested exception.
 * The nested exception is set only if JDK {@literal >= 1.4}
 */
private static IOException newIOException(String message,
                                          Throwable cause) {
    final IOException x = new IOException(message);
    return EnvHelp.initCause(x,cause);
}
 
Example 15
Source File: ClientCommunicatorAdmin.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void restart(IOException ioe) throws IOException {
    // check state
    synchronized(lock) {
        if (state == TERMINATED) {
            throw new IOException("The client has been closed.");
        } else if (state == FAILED) { // already failed to re-start by another thread
            throw ioe;
        } else if (state == RE_CONNECTING) {
            // restart process has been called by another thread
            // we need to wait
            while(state == RE_CONNECTING) {
                try {
                    lock.wait();
                } catch (InterruptedException ire) {
                    // be asked to give up
                    InterruptedIOException iioe = new InterruptedIOException(ire.toString());
                    EnvHelp.initCause(iioe, ire);

                    throw iioe;
                }
            }

            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            } else if (state != CONNECTED) {
                // restarted is failed by another thread
                throw ioe;
            }
            return;
        } else {
            state = RE_CONNECTING;
            lock.notifyAll();
        }
    }

    // re-starting
    try {
        doStart();
        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = CONNECTED;

            lock.notifyAll();
        }

        return;
    } catch (Exception e) {
        logger.warning("restart", "Failed to restart: " + e);
        logger.debug("restart",e);

        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = FAILED;

            lock.notifyAll();
        }

        try {
            doStop();
        } catch (Exception eee) {
            // OK.
            // We know there is a problem.
        }

        terminate();

        throw ioe;
    }
}
 
Example 16
Source File: DefaultMXBeanMappingFactory.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
static InvalidObjectException invalidObjectException(String msg,
                                                     Throwable cause) {
    return EnvHelp.initCause(new InvalidObjectException(msg), cause);
}
 
Example 17
Source File: ClientCommunicatorAdmin.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void restart(IOException ioe) throws IOException {
    // check state
    synchronized(lock) {
        if (state == TERMINATED) {
            throw new IOException("The client has been closed.");
        } else if (state == FAILED) { // already failed to re-start by another thread
            throw ioe;
        } else if (state == RE_CONNECTING) {
            // restart process has been called by another thread
            // we need to wait
            while(state == RE_CONNECTING) {
                try {
                    lock.wait();
                } catch (InterruptedException ire) {
                    // be asked to give up
                    InterruptedIOException iioe = new InterruptedIOException(ire.toString());
                    EnvHelp.initCause(iioe, ire);

                    throw iioe;
                }
            }

            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            } else if (state != CONNECTED) {
                // restarted is failed by another thread
                throw ioe;
            }
            return;
        } else {
            state = RE_CONNECTING;
            lock.notifyAll();
        }
    }

    // re-starting
    try {
        doStart();
        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = CONNECTED;

            lock.notifyAll();
        }

        return;
    } catch (Exception e) {
        logger.warning("restart", "Failed to restart: " + e);
        logger.debug("restart",e);

        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = FAILED;

            lock.notifyAll();
        }

        try {
            doStop();
        } catch (Exception eee) {
            // OK.
            // We know there is a problem.
        }

        terminate();

        throw ioe;
    }
}
 
Example 18
Source File: RMIConnectionImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a new IOException with a nested exception.
 * The nested exception is set only if JDK {@literal >= 1.4}
 */
private static IOException newIOException(String message,
                                          Throwable cause) {
    final IOException x = new IOException(message);
    return EnvHelp.initCause(x,cause);
}
 
Example 19
Source File: DefaultMXBeanMappingFactory.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
static InvalidObjectException invalidObjectException(String msg,
                                                     Throwable cause) {
    return EnvHelp.initCause(new InvalidObjectException(msg), cause);
}
 
Example 20
Source File: ClientCommunicatorAdmin.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void restart(IOException ioe) throws IOException {
    // check state
    synchronized(lock) {
        if (state == TERMINATED) {
            throw new IOException("The client has been closed.");
        } else if (state == FAILED) { // already failed to re-start by another thread
            throw ioe;
        } else if (state == RE_CONNECTING) {
            // restart process has been called by another thread
            // we need to wait
            while(state == RE_CONNECTING) {
                try {
                    lock.wait();
                } catch (InterruptedException ire) {
                    // be asked to give up
                    InterruptedIOException iioe = new InterruptedIOException(ire.toString());
                    EnvHelp.initCause(iioe, ire);

                    throw iioe;
                }
            }

            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            } else if (state != CONNECTED) {
                // restarted is failed by another thread
                throw ioe;
            }
            return;
        } else {
            state = RE_CONNECTING;
            lock.notifyAll();
        }
    }

    // re-starting
    try {
        doStart();
        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = CONNECTED;

            lock.notifyAll();
        }

        return;
    } catch (Exception e) {
        logger.warning("restart", "Failed to restart: " + e);
        logger.debug("restart",e);

        synchronized(lock) {
            if (state == TERMINATED) {
                throw new IOException("The client has been closed.");
            }

            state = FAILED;

            lock.notifyAll();
        }

        try {
            doStop();
        } catch (Exception eee) {
            // OK.
            // We know there is a problem.
        }

        terminate();

        throw ioe;
    }
}