Java Code Examples for com.sun.jmx.mbeanserver.Util#cast()

The following examples show how to use com.sun.jmx.mbeanserver.Util#cast() . 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: JvmRuntimeImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static String[] getClassPath(Object userData) {
    final Map<Object, Object> m =
            Util.cast((userData instanceof Map)?userData:null);
    final String tag = "JvmRuntime.getClassPath";

    // If the list is in the cache, simply return it.
    //
    if (m != null) {
        final String[] cached = (String[])m.get(tag);
        if (cached != null) return cached;
    }

    final String[] args = splitPath(getRuntimeMXBean().getClassPath());

    if (m != null) m.put(tag,args);
    return args;
}
 
Example 2
Source File: JvmRuntimeImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static String[] getInputArguments(Object userData) {
    final Map<Object, Object> m =
            Util.cast((userData instanceof Map)?userData:null);
    final String tag = "JvmRuntime.getInputArguments";

    // If the list is in the cache, simply return it.
    //
    if (m != null) {
        final String[] cached = (String[])m.get(tag);
        if (cached != null) return cached;
    }

    final List<String> l = getRuntimeMXBean().getInputArguments();
    final String[] args = l.toArray(new String[0]);

    if (m != null) m.put(tag,args);
    return args;
}
 
Example 3
Source File: RMIConnector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Integer addListenerWithSubject(ObjectName name,
                                       MarshalledObject<NotificationFilter> filter,
                                       Subject delegationSubject,
                                       boolean reconnect)
    throws InstanceNotFoundException, IOException {

    final boolean debug = logger.debugOn();
    if (debug)
        logger.debug("addListenerWithSubject",
                "(ObjectName,MarshalledObject,Subject)");

    final ObjectName[] names = new ObjectName[] {name};
    final MarshalledObject<NotificationFilter>[] filters =
            Util.cast(new MarshalledObject<?>[] {filter});
    final Subject[] delegationSubjects = new Subject[] {
        delegationSubject
    };

    final Integer[] listenerIDs =
            addListenersWithSubjects(names,filters,delegationSubjects,
            reconnect);

    if (debug) logger.debug("addListenerWithSubject","listenerID="
            + listenerIDs[0]);
    return listenerIDs[0];
}
 
Example 4
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private Integer addListenerWithSubject(ObjectName name,
                                       MarshalledObject<NotificationFilter> filter,
                                       Subject delegationSubject,
                                       boolean reconnect)
    throws InstanceNotFoundException, IOException {

    final boolean debug = logger.debugOn();
    if (debug)
        logger.debug("addListenerWithSubject",
                "(ObjectName,MarshalledObject,Subject)");

    final ObjectName[] names = new ObjectName[] {name};
    final MarshalledObject<NotificationFilter>[] filters =
            Util.cast(new MarshalledObject<?>[] {filter});
    final Subject[] delegationSubjects = new Subject[] {
        delegationSubject
    };

    final Integer[] listenerIDs =
            addListenersWithSubjects(names,filters,delegationSubjects,
            reconnect);

    if (debug) logger.debug("addListenerWithSubject","listenerID="
            + listenerIDs[0]);
    return listenerIDs[0];
}
 
Example 5
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Integer addListenerWithSubject(ObjectName name,
                                       MarshalledObject<NotificationFilter> filter,
                                       Subject delegationSubject,
                                       boolean reconnect)
    throws InstanceNotFoundException, IOException {

    final boolean debug = logger.debugOn();
    if (debug)
        logger.debug("addListenerWithSubject",
                "(ObjectName,MarshalledObject,Subject)");

    final ObjectName[] names = new ObjectName[] {name};
    final MarshalledObject<NotificationFilter>[] filters =
            Util.cast(new MarshalledObject<?>[] {filter});
    final Subject[] delegationSubjects = new Subject[] {
        delegationSubject
    };

    final Integer[] listenerIDs =
            addListenersWithSubjects(names,filters,delegationSubjects,
            reconnect);

    if (debug) logger.debug("addListenerWithSubject","listenerID="
            + listenerIDs[0]);
    return listenerIDs[0];
}
 
Example 6
Source File: JvmContextFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static Map<Object, Object> getUserData() {
    final Object userData =
        com.sun.jmx.snmp.ThreadContext.get("SnmpUserData");

    if (userData instanceof Map<?, ?>) return Util.cast(userData);
    else return null;
}
 
Example 7
Source File: RMIConnector.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
Example 8
Source File: RMIConnector.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
Example 9
Source File: FileLoginModule.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize this <code>LoginModule</code>.
 *
 * @param subject the <code>Subject</code> to be authenticated.
 * @param callbackHandler a <code>CallbackHandler</code> to acquire the
 *                  user's name and password.
 * @param sharedState shared <code>LoginModule</code> state.
 * @param options options specified in the login
 *                  <code>Configuration</code> for this particular
 *                  <code>LoginModule</code>.
 */
public void initialize(Subject subject, CallbackHandler callbackHandler,
                       Map<String,?> sharedState,
                       Map<String,?> options)
{

    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = Util.cast(sharedState);
    this.options = options;

    // initialize any configured options
    tryFirstPass =
            "true".equalsIgnoreCase((String)options.get("tryFirstPass"));
    useFirstPass =
            "true".equalsIgnoreCase((String)options.get("useFirstPass"));
    storePass =
            "true".equalsIgnoreCase((String)options.get("storePass"));
    clearPass =
            "true".equalsIgnoreCase((String)options.get("clearPass"));

    passwordFile = (String)options.get("passwordFile");
    passwordFileDisplayName = passwordFile;
    userSuppliedPasswordFile = true;

    // set the location of the password file
    if (passwordFile == null) {
        passwordFile = DEFAULT_PASSWORD_FILE_NAME;
        userSuppliedPasswordFile = false;
        try {
            System.getProperty("java.home");
            hasJavaHomePermission = true;
            passwordFileDisplayName = passwordFile;
        } catch (SecurityException e) {
            hasJavaHomePermission = false;
            passwordFileDisplayName =
                    ConnectorBootstrap.DefaultValues.PASSWORD_FILE_NAME;
        }
    }
}
 
Example 10
Source File: JvmContextFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static Map<Object, Object> getUserData() {
    final Object userData =
        com.sun.jmx.snmp.ThreadContext.get("SnmpUserData");

    if (userData instanceof Map<?, ?>) return Util.cast(userData);
    else return null;
}
 
Example 11
Source File: RoleList.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return a view of this list as a {@code List<Role>}.
 * Changes to the returned value are reflected by changes
 * to the original {@code RoleList} and vice versa.
 *
 * @return a {@code List<Role>} whose contents
 * reflect the contents of this {@code RoleList}.
 *
 * <p>If this method has ever been called on a given
 * {@code RoleList} instance, a subsequent attempt to add
 * an object to that instance which is not a {@code Role}
 * will fail with an {@code IllegalArgumentException}. For compatibility
 * reasons, a {@code RoleList} on which this method has never
 * been called does allow objects other than {@code Role}s to
 * be added.</p>
 *
 * @throws IllegalArgumentException if this {@code RoleList} contains
 * an element that is not a {@code Role}.
 *
 * @since 1.6
 */
@SuppressWarnings("unchecked")
public List<Role> asList() {
    if (!typeSafe) {
        if (tainted)
            checkTypeSafe(this);
        typeSafe = true;
    }
    return Util.cast(this);
}
 
Example 12
Source File: RoleList.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Return a view of this list as a {@code List<Role>}.
 * Changes to the returned value are reflected by changes
 * to the original {@code RoleList} and vice versa.
 *
 * @return a {@code List<Role>} whose contents
 * reflect the contents of this {@code RoleList}.
 *
 * <p>If this method has ever been called on a given
 * {@code RoleList} instance, a subsequent attempt to add
 * an object to that instance which is not a {@code Role}
 * will fail with an {@code IllegalArgumentException}. For compatibility
 * reasons, a {@code RoleList} on which this method has never
 * been called does allow objects other than {@code Role}s to
 * be added.</p>
 *
 * @throws IllegalArgumentException if this {@code RoleList} contains
 * an element that is not a {@code Role}.
 *
 * @since 1.6
 */
@SuppressWarnings("unchecked")
public List<Role> asList() {
    if (!typeSafe) {
        if (tainted)
            checkTypeSafe(this);
        typeSafe = true;
    }
    return Util.cast(this);
}
 
Example 13
Source File: StandardMBean.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * <p>Replace the implementation object wrapped in this object.</p>
 *
 * @param implementation The new implementation of this Standard MBean
 * (or MXBean). The <code>implementation</code> object must implement
 * the Standard MBean (or MXBean) interface that was supplied when this
 * <code>StandardMBean</code> was constructed.
 *
 * @exception IllegalArgumentException if the given
 * <var>implementation</var> is null.
 *
 * @exception NotCompliantMBeanException if the given
 * <var>implementation</var> does not implement the
 * Standard MBean (or MXBean) interface that was
 * supplied at construction.
 *
 * @see #getImplementation
 **/
public void setImplementation(Object implementation)
    throws NotCompliantMBeanException {

    if (implementation == null)
        throw new IllegalArgumentException("implementation is null");

    if (isMXBean()) {
        this.mbean = new MXBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    } else {
        this.mbean = new StandardMBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    }
}
 
Example 14
Source File: StandardMBean.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Replace the implementation object wrapped in this object.</p>
 *
 * @param implementation The new implementation of this Standard MBean
 * (or MXBean). The <code>implementation</code> object must implement
 * the Standard MBean (or MXBean) interface that was supplied when this
 * <code>StandardMBean</code> was constructed.
 *
 * @exception IllegalArgumentException if the given
 * <var>implementation</var> is null.
 *
 * @exception NotCompliantMBeanException if the given
 * <var>implementation</var> does not implement the
 * Standard MBean (or MXBean) interface that was
 * supplied at construction.
 *
 * @see #getImplementation
 **/
public void setImplementation(Object implementation)
    throws NotCompliantMBeanException {

    if (implementation == null)
        throw new IllegalArgumentException("implementation is null");

    if (isMXBean()) {
        this.mbean = new MXBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    } else {
        this.mbean = new StandardMBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    }
}
 
Example 15
Source File: StandardMBean.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Replace the implementation object wrapped in this object.</p>
 *
 * @param implementation The new implementation of this Standard MBean
 * (or MXBean). The <code>implementation</code> object must implement
 * the Standard MBean (or MXBean) interface that was supplied when this
 * <code>StandardMBean</code> was constructed.
 *
 * @exception IllegalArgumentException if the given
 * <var>implementation</var> is null.
 *
 * @exception NotCompliantMBeanException if the given
 * <var>implementation</var> does not implement the
 * Standard MBean (or MXBean) interface that was
 * supplied at construction.
 *
 * @see #getImplementation
 **/
public void setImplementation(Object implementation)
    throws NotCompliantMBeanException {

    if (implementation == null)
        throw new IllegalArgumentException("implementation is null");

    if (isMXBean()) {
        this.mbean = new MXBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    } else {
        this.mbean = new StandardMBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    }
}
 
Example 16
Source File: StandardMBean.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Replace the implementation object wrapped in this object.</p>
 *
 * @param implementation The new implementation of this Standard MBean
 * (or MXBean). The <code>implementation</code> object must implement
 * the Standard MBean (or MXBean) interface that was supplied when this
 * <code>StandardMBean</code> was constructed.
 *
 * @exception IllegalArgumentException if the given
 * <var>implementation</var> is null.
 *
 * @exception NotCompliantMBeanException if the given
 * <var>implementation</var> does not implement the
 * Standard MBean (or MXBean) interface that was
 * supplied at construction.
 *
 * @see #getImplementation
 **/
public void setImplementation(Object implementation)
    throws NotCompliantMBeanException {

    if (implementation == null)
        throw new IllegalArgumentException("implementation is null");

    if (isMXBean()) {
        this.mbean = new MXBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    } else {
        this.mbean = new StandardMBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    }
}
 
Example 17
Source File: StandardMBean.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * <p>Replace the implementation object wrapped in this object.</p>
 *
 * @param implementation The new implementation of this Standard MBean
 * (or MXBean). The <code>implementation</code> object must implement
 * the Standard MBean (or MXBean) interface that was supplied when this
 * <code>StandardMBean</code> was constructed.
 *
 * @exception IllegalArgumentException if the given
 * <var>implementation</var> is null.
 *
 * @exception NotCompliantMBeanException if the given
 * <var>implementation</var> does not implement the
 * Standard MBean (or MXBean) interface that was
 * supplied at construction.
 *
 * @see #getImplementation
 **/
public void setImplementation(Object implementation)
    throws NotCompliantMBeanException {

    if (implementation == null)
        throw new IllegalArgumentException("implementation is null");

    if (isMXBean()) {
        this.mbean = new MXBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    } else {
        this.mbean = new StandardMBeanSupport(implementation,
                Util.<Class<Object>>cast(getMBeanInterface()));
    }
}
 
Example 18
Source File: RoleList.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Return a view of this list as a {@code List<Role>}.
 * Changes to the returned value are reflected by changes
 * to the original {@code RoleList} and vice versa.
 *
 * @return a {@code List<Role>} whose contents
 * reflect the contents of this {@code RoleList}.
 *
 * <p>If this method has ever been called on a given
 * {@code RoleList} instance, a subsequent attempt to add
 * an object to that instance which is not a {@code Role}
 * will fail with an {@code IllegalArgumentException}. For compatibility
 * reasons, a {@code RoleList} on which this method has never
 * been called does allow objects other than {@code Role}s to
 * be added.</p>
 *
 * @throws IllegalArgumentException if this {@code RoleList} contains
 * an element that is not a {@code Role}.
 *
 * @since 1.6
 */
@SuppressWarnings("unchecked")
public List<Role> asList() {
    if (!typeSafe) {
        if (tainted)
            checkTypeSafe(this);
        typeSafe = true;
    }
    return Util.cast(this);
}
 
Example 19
Source File: RoleUnresolvedList.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Return a view of this list as a {@code List<RoleUnresolved>}.
 * Changes to the returned value are reflected by changes
 * to the original {@code RoleUnresolvedList} and vice versa.
 *
 * @return a {@code List<RoleUnresolved>} whose contents
 * reflect the contents of this {@code RoleUnresolvedList}.
 *
 * <p>If this method has ever been called on a given
 * {@code RoleUnresolvedList} instance, a subsequent attempt to add
 * an object to that instance which is not a {@code RoleUnresolved}
 * will fail with an {@code IllegalArgumentException}. For compatibility
 * reasons, a {@code RoleUnresolvedList} on which this method has never
 * been called does allow objects other than {@code RoleUnresolved}s to
 * be added.</p>
 *
 * @throws IllegalArgumentException if this {@code RoleUnresolvedList}
 * contains an element that is not a {@code RoleUnresolved}.
 *
 * @since 1.6
 */
@SuppressWarnings("unchecked")
public List<RoleUnresolved> asList() {
    if (!typeSafe) {
        if (tainted)
            checkTypeSafe(this);
        typeSafe = true;
    }
    return Util.cast(this);
}
 
Example 20
Source File: TabularDataSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a collection view of the index to row mappings
 * contained in this {@code TabularDataSupport} instance.
 * Each element in the returned collection is
 * a {@code Map.Entry<List<?>,CompositeData>} but
 * is declared as a {@code Map.Entry<Object,Object>}
 * for compatibility reasons. Each of the map entry
 * keys is an unmodifiable {@code List<?>}.
 * The collection is backed by the underlying map of this
 * {@code TabularDataSupport} instance, so changes to the
 * {@code TabularDataSupport} instance are reflected in
 * the collection, and vice-versa.
 * The collection supports element removal, which removes
 * the corresponding mapping from the map, via the
 * {@link Iterator#remove}, {@link Collection#remove},
 * {@link Collection#removeAll}, {@link Collection#retainAll},
 * and {@link Collection#clear} operations. It does not support
 * the {@link Collection#add} or {@link Collection#addAll}
 * operations.
 * <p>
 * <b>IMPORTANT NOTICE</b>: Do not use the {@code setValue} method of the
 * {@code Map.Entry} elements contained in the returned collection view.
 * Doing so would corrupt the index to row mappings contained in this
 * {@code TabularDataSupport} instance.
 *
 * @return a collection view ({@code Set<Map.Entry<List<?>,CompositeData>>})
 * of the mappings contained in this map.
 * @see java.util.Map.Entry
 */
@SuppressWarnings("unchecked")  // historical confusion about the return type
public Set<Map.Entry<Object,Object>> entrySet() {

    return Util.cast(dataMap.entrySet());
}