Java Code Examples for javax.management.InstanceNotFoundException

The following are top voted examples for showing how to use javax.management.InstanceNotFoundException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   View source code 7 votes vote down vote up
public Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
        throws InstanceNotFoundException, MBeanException,
               ReflectionException {

    name = nonDefaultDomain(name);

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, operationName, name, "invoke");
    try {
        return instance.invoke(operationName, params, signature);
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
 
Example 2
Project: jdk8u-jdk   File: RMIConnector.java   View source code 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 3
Project: jdk8u-jdk   File: RMIConnector.java   View source code 6 votes vote down vote up
public boolean isInstanceOf(ObjectName name,
        String className)
        throws InstanceNotFoundException,
        IOException {
    if (logger.debugOn())
        logger.debug("isInstanceOf", "name=" + name +
                ", className=" + className);

    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.isInstanceOf(name,
                className,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.isInstanceOf(name,
                className,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 4
Project: openjdk-jdk10   File: RMIConnector.java   View source code 6 votes vote down vote up
public void addNotificationListener(ObjectName name,
        NotificationListener listener,
        NotificationFilter filter,
        Object handback)
        throws InstanceNotFoundException,
        IOException {

    final boolean debug = logger.debugOn();

    if (debug)
        logger.debug("addNotificationListener" +
                "(ObjectName,NotificationListener,"+
                "NotificationFilter,Object)",
                "name=" + name
                + ", listener=" + listener
                + ", filter=" + filter
                + ", handback=" + handback);

    final Integer listenerID =
            addListenerWithSubject(name,
            new MarshalledObject<NotificationFilter>(filter),
            delegationSubject,true);
    rmiNotifClient.addNotificationListener(listenerID, name, listener,
            filter, handback,
            delegationSubject);
}
 
Example 5
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   View source code 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 6
Project: jdk8u-jdk   File: RMIConnector.java   View source code 6 votes vote down vote up
public MBeanInfo getMBeanInfo(ObjectName name)
throws InstanceNotFoundException,
        IntrospectionException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("getMBeanInfo", "name=" + name);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.getMBeanInfo(name, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.getMBeanInfo(name, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 7
Project: jdk8u-jdk   File: ArrayNotificationBuffer.java   View source code 6 votes vote down vote up
private static boolean isInstanceOf(final MBeanServer mbs,
                                    final ObjectName name,
                                    final String className) {
    PrivilegedExceptionAction<Boolean> act =
        new PrivilegedExceptionAction<Boolean>() {
            public Boolean run() throws InstanceNotFoundException {
                return mbs.isInstanceOf(name, className);
            }
        };
    try {
        return AccessController.doPrivileged(act);
    } catch (Exception e) {
        logger.fine("isInstanceOf", "failed: " + e);
        logger.debug("isInstanceOf", e);
        return false;
    }
}
 
Example 8
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   View source code 6 votes vote down vote up
/**
 * <p>Return the named {@link java.lang.ClassLoader}.
 * @param loaderName The ObjectName of the ClassLoader.
 * @return The named ClassLoader.
 * @exception InstanceNotFoundException if the named ClassLoader
 * is not found.
 */
public ClassLoader getClassLoader(ObjectName loaderName)
        throws InstanceNotFoundException {

    if (loaderName == null) {
        checkMBeanPermission((String) null, null, null, "getClassLoader");
        return server.getClass().getClassLoader();
    }

    DynamicMBean instance = getMBean(loaderName);
    checkMBeanPermission(instance, null, loaderName, "getClassLoader");

    Object resource = getResource(instance);

    /* Check if the given MBean is a ClassLoader */
    if (!(resource instanceof ClassLoader))
        throw new InstanceNotFoundException(loaderName.toString() +
                                            " is not a classloader");

    return (ClassLoader) resource;
}
 
Example 9
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   View source code 6 votes vote down vote up
/**
 * Gets a specific MBean controlled by the DefaultMBeanServerInterceptor.
 * The name must have a non-default domain.
 */
private DynamicMBean getMBean(ObjectName name)
    throws InstanceNotFoundException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
                           "Exception occurred trying to get an MBean");
    }
    DynamicMBean obj = repository.retrieve(name);
    if (obj == null) {
        if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
            MBEANSERVER_LOGGER.logp(Level.FINER,
                    DefaultMBeanServerInterceptor.class.getName(),
                    "getMBean", name + " : Found no object");
        }
        throw new InstanceNotFoundException(name.toString());
    }
    return obj;
}
 
Example 10
Project: monarch   File: MBeanServerWrapper.java   View source code 6 votes vote down vote up
@Override
public AttributeList getAttributes(ObjectName name, String[] attributes)
    throws InstanceNotFoundException, ReflectionException {
  AttributeList results = new AttributeList();
  for (String attribute : attributes) {
    try {
      Object value = getAttribute(name, attribute);
      Attribute att = new Attribute(attribute, value);
      results.add(att);
    } catch (Exception e) {
      throw new GemFireSecurityException("error getting value of " + attribute + " from " + name,
          e);
    }
  }
  return results;
}
 
Example 11
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   View source code 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 12
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   View source code 6 votes vote down vote up
public Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
        throws InstanceNotFoundException, MBeanException,
               ReflectionException {

    name = nonDefaultDomain(name);

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, operationName, name, "invoke");
    try {
        return instance.invoke(operationName, params, signature);
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
 
Example 13
Project: OpenJSharp   File: RMIConnector.java   View source code 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 14
Project: jdk8u-jdk   File: RMIConnector.java   View source code 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 15
Project: jdk8u-jdk   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public ObjectInstance createMBean(
        String className, ObjectName name, ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException {
    return createMBean(className, name, loaderName, null, null);
}
 
Example 16
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   View source code 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    removeNotificationListener(name, listener, filter, handback, false);
}
 
Example 17
Project: hashsdn-controller   File: TestingConfigTransactionController.java   View source code 5 votes vote down vote up
@Override
public void destroyModule(final ObjectName objectName)
        throws InstanceNotFoundException {
    if(objectName != null){
        conf4 = null;
    }
}
 
Example 18
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 5 votes vote down vote up
@Override
public synchronized void addNotificationListener(ObjectName name, ObjectName listener,
		NotificationFilter filter, Object handback)
		throws InstanceNotFoundException {
	mbs.addNotificationListener(name, listener, filter, handback);
	Listener1 l = new Listener1(name, listener, filter, handback);
	listeners.add(l);
	listeners1.add(l);
}
 
Example 19
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 5 votes vote down vote up
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
		ObjectName loaderName, Object[] params, String[] signature)
		throws ReflectionException, InstanceAlreadyExistsException,
		MBeanRegistrationException, MBeanException,
		NotCompliantMBeanException, InstanceNotFoundException {
	throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");		
}
 
Example 20
Project: jdk8u-jdk   File: JmxMBeanServer.java   View source code 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {

    mbsInterceptor.removeNotificationListener(cloneObjectName(name),
                                              listener, filter, handback);
}
 
Example 21
Project: openjdk-jdk10   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
    throws InstanceNotFoundException, ListenerNotFoundException {
    checkRead();
    getMBeanServer().removeNotificationListener(name, listener,
                                                filter, handback);
}
 
Example 22
Project: hashsdn-controller   File: ServiceReferenceRegistryImpl.java   View source code 5 votes vote down vote up
@Override
public synchronized ObjectName saveServiceReference(final String serviceInterfaceName, final String refName,
        final ObjectName moduleON) throws InstanceNotFoundException {
    assertWritable();
    ServiceReference serviceReference = new ServiceReference(serviceInterfaceName, refName);
    return saveServiceReference(serviceReference, moduleON);
}
 
Example 23
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 5 votes vote down vote up
@Override
public synchronized void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback)
		throws InstanceNotFoundException, ListenerNotFoundException {
	mbs.removeNotificationListener(name, listener, filter, handback);
	Listener1 l = new Listener1(name, listener, filter, handback);
	listeners.remove(l);
	listeners1.remove(l);
	unregisteredListeners.remove(l);
}
 
Example 24
Project: jdk8u-jdk   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {

    forbidJMImpl(name);

    DynamicMBean mbean = getMBean(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());

    MBeanRegistration reg = mbeanRegistration(mbean);
    try {
        reg.preDeregister();
    } catch (Exception e) {
        throw new MBeanRegistrationException(e);
    }
    if (!mbeans.remove(name, mbean))
        throw new InstanceNotFoundException(name.toString());
        // This is incorrect because we've invoked preDeregister

    Object userMBean = getUserMBean(mbean);
    if (userMBean instanceof ClassLoader)
        clr.removeLoader((ClassLoader) userMBean);

    Notification n = new MBeanServerNotification(
            MBeanServerNotification.REGISTRATION_NOTIFICATION,
            MBeanServerDelegate.DELEGATE_NAME,
            0,
            name);
    delegate.sendNotification(n);

    reg.postDeregister();
}
 
Example 25
Project: OpenJSharp   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
 
Example 26
Project: monarch   File: MBeanProxyFactory.java   View source code 5 votes vote down vote up
/**
 * Removes all proxies for a given member
 * 
 * @param member {@link org.apache.geode.distributed.DistributedMember}
 * @param monitoringRegion monitoring region containing the proxies
 */
public void removeAllProxies(DistributedMember member, Region<String, Object> monitoringRegion) {

  Set<Entry<String, Object>> entries = monitoringRegion.entrySet();
  Iterator<Entry<String, Object>> entriesIt = entries.iterator();

  if (logger.isDebugEnabled()) {
    logger.debug("Removing {} proxies for member {}", entries.size(), member.getId());
  }

  while (entriesIt.hasNext()) {
    String key = null;
    Object val = null;
    try {
      Entry<String, Object> entry = entriesIt.next();
      key = entry.getKey();// MBean Name in String format.
      val = entry.getValue(); // Federation Component
      ObjectName mbeanName = ObjectName.getInstance(key);
      removeProxy(member, mbeanName, val);
    } catch (Exception e) {
      if (!(e.getCause() instanceof InstanceNotFoundException)) {
        logger.warn("Remove Proxy failed for {} due to {}", key, e.getMessage(), e);
      }
      continue;
    }
  }
}
 
Example 27
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public ObjectInstance createMBean(
        String className, ObjectName name, ObjectName loaderName,
        Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException {
    Object mbean = instantiate(className, loaderName, params, signature);
    return registerMBean(mbean, name);
}
 
Example 28
Project: jerrydog   File: StandardServerMBean.java   View source code 5 votes vote down vote up
/**
 * Write the configuration information for this entire <code>Server</code>
 * out to the server.xml configuration file.
 *
 * @exception InstanceNotFoundException if the managed resource object
 *  cannot be found
 * @exception MBeanException if the initializer of the object throws
 *  an exception, or persistence is not supported
 * @exception RuntimeOperationsException if an exception is reported
 *  by the persistence mechanism
 */
public synchronized void store() throws InstanceNotFoundException,
    MBeanException, RuntimeOperationsException {

    Server server = ServerFactory.getServer();
    if (server instanceof StandardServer) {
        try {
            ((StandardServer) server).store();
        } catch (Exception e) {
            throw new MBeanException(e, "Error updating conf/server.xml");
        }
    }

}
 
Example 29
Project: Byter   File: JmxNetworkManagerTest.java   View source code 5 votes vote down vote up
/**
 * Test if there are all functions available.
 */
@Test
public void testStockAvailableOperations() throws IOException, IntrospectionException, InstanceNotFoundException, ReflectionException {
    //connect to server
    final JMXConnector connection = JmxConnectionHelper.buildJmxMPConnector(JMXSERVERIP,serverObj.getConnectorSystemPort());
    //get MBeanServerConnection
    MBeanServerConnection mbsConnection = JmxServerHelper.getMBeanServer(connection);
    //check if mbeans are registered
    Assert.assertNotSame(0,mbsConnection.getMBeanCount());
    //do actual test
    ObjectName networkManagerOn = JmxServerHelper.findObjectName(mbsConnection,"de.b4sh.byter","NetworkManager");
    final List<MBeanOperationInfo> functions = JmxServerHelper.getOperations(mbsConnection,networkManagerOn);
    Assert.assertNotEquals(0, functions.size());
}
 
Example 30
Project: jdk8u-jdk   File: RequiredModelMBean.java   View source code 5 votes vote down vote up
/**
 * Sets the instance handle of the object against which to
 * execute all methods in this ModelMBean management interface
 * (MBeanInfo and Descriptors).
 *
 * @param mr Object that is the managed resource
 * @param mr_type The type of reference for the managed resource.
 *     <br>Can be: "ObjectReference", "Handle", "IOR", "EJBHandle",
 *         or "RMIReference".
 *     <br>In this implementation only "ObjectReference" is supported.
 *
 * @exception MBeanException The initializer of the object has
 *            thrown an exception.
 * @exception InstanceNotFoundException The managed resource
 *            object could not be found
 * @exception InvalidTargetObjectTypeException The managed
 *            resource type should be "ObjectReference".
 * @exception RuntimeOperationsException Wraps a {@link
 *            RuntimeException} when setting the resource.
 **/
public void setManagedResource(Object mr, String mr_type)
    throws MBeanException, RuntimeOperationsException,
           InstanceNotFoundException, InvalidTargetObjectTypeException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object,String)","Entry");
    }

    // check that the mr_type is supported by this JMXAgent
    // only "objectReference" is supported
    if ((mr_type == null) ||
        (! mr_type.equalsIgnoreCase("objectReference"))) {
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    RequiredModelMBean.class.getName(),
                "setManagedResource(Object,String)",
                "Managed Resource Type is not supported: " + mr_type);
        }
        throw new InvalidTargetObjectTypeException(mr_type);
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object,String)",
            "Managed Resource is valid");
    }
    managedResource = mr;

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object, String)", "Exit");
    }
}
 
Example 31
Project: OpenJSharp   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
    throws InstanceNotFoundException, ListenerNotFoundException {
    checkRead();
    getMBeanServer().removeNotificationListener(name, listener,
                                                filter, handback);
}
 
Example 32
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   View source code 5 votes vote down vote up
private void exclusiveUnregisterMBean(ObjectName name)
        throws InstanceNotFoundException, MBeanRegistrationException {

    DynamicMBean instance = getMBean(name);
    // may throw InstanceNotFoundException

    checkMBeanPermission(instance, null, name, "unregisterMBean");

    if (instance instanceof MBeanRegistration)
        preDeregisterInvoke((MBeanRegistration) instance);

    final Object resource = getResource(instance);

    // Unregisters the MBean from the repository.
    // Returns the resource context that was used.
    // The returned context does nothing for regular MBeans.
    // For ClassLoader MBeans and JMXNamespace (and JMXDomain)
    // MBeans - the context makes it possible to unregister these
    // objects from the appropriate framework artifacts, such as
    // the CLR or the dispatcher, from within the repository lock.
    // In case of success, we also need to call context.done() at the
    // end of this method.
    //
    final ResourceContext context =
            unregisterFromRepository(resource, instance, name);

    try {
        if (instance instanceof MBeanRegistration)
            postDeregisterInvoke(name,(MBeanRegistration) instance);
    } finally {
        context.done();
    }
}
 
Example 33
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   View source code 5 votes vote down vote up
/**
 * Removes a MBean in the repository,
 * sends MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
 * returns ResourceContext for special resources such as ClassLoaders
 * or JMXNamespaces, or null. For regular MBean this method returns
 * ResourceContext.NONE.
 *
 * @return a ResourceContext for special resources such as ClassLoaders
 *         or JMXNamespaces.
 */
private ResourceContext unregisterFromRepository(
        final Object resource,
        final DynamicMBean object,
        final ObjectName logicalName)
        throws InstanceNotFoundException {

    // Creates a registration context, if needed.
    //
    final ResourceContext context =
            makeResourceContextFor(resource, logicalName);


    repository.remove(logicalName, context);

    // ---------------------
    // Send deletion event
    // ---------------------
    if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
        MBEANSERVER_LOGGER.log(Level.TRACE,
                "Send delete notification of object " +
                logicalName.getCanonicalName());
    }

    sendNotification(MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
            logicalName);
    return context;
}
 
Example 34
Project: jdk8u-jdk   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public void addNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException {
    NotificationBroadcaster userMBean =
            (NotificationBroadcaster) getUserMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.addNotificationListener(wrappedListener, filter, handback);
}
 
Example 35
Project: OpenJSharp   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
    throws InstanceNotFoundException, ListenerNotFoundException {
    checkRead();
    getMBeanServer().removeNotificationListener(name, listener,
                                                filter, handback);
}
 
Example 36
Project: OpenJSharp   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void addNotificationListener(ObjectName name,
                                    ObjectName listener,
                                    NotificationFilter filter,
                                    Object handback)
    throws InstanceNotFoundException {
    checkRead();
    getMBeanServer().addNotificationListener(name, listener,
                                             filter, handback);
}
 
Example 37
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {

    forbidJMImpl(name);

    DynamicMBean mbean = getMBean(name);
    if (mbean == null)
        throw new InstanceNotFoundException(name.toString());

    MBeanRegistration reg = mbeanRegistration(mbean);
    try {
        reg.preDeregister();
    } catch (Exception e) {
        throw new MBeanRegistrationException(e);
    }
    if (!mbeans.remove(name, mbean))
        throw new InstanceNotFoundException(name.toString());
        // This is incorrect because we've invoked preDeregister

    Object userMBean = getUserMBean(mbean);
    if (userMBean instanceof ClassLoader)
        clr.removeLoader((ClassLoader) userMBean);

    Notification n = new MBeanServerNotification(
            MBeanServerNotification.REGISTRATION_NOTIFICATION,
            MBeanServerDelegate.DELEGATE_NAME,
            0,
            name);
    delegate.sendNotification(n);

    reg.postDeregister();
}
 
Example 38
Project: OpenJSharp   File: SnmpGenericObjectServer.java   View source code 5 votes vote down vote up
/**
 * Set the value of an SNMP variable.
 *
 * <p><b><i>
 * You should never need to use this method directly.
 * </i></b></p>
 *
 * @param meta  The impacted metadata object
 * @param name  The ObjectName of the impacted MBean
 * @param x     The new requested SnmpValue
 * @param id    The OID arc identifying the variable we're trying to set.
 * @param data  User contextual data allocated through the
 *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
 *
 * @return The new value of the variable after the operation.
 *
 * @exception SnmpStatusException whenever an SNMP exception must be
 *      raised. Raising an exception will abort the request. <br>
 *      Exceptions should never be raised directly, but only by means of
 * <code>
 * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
 * </code>
 **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name,
                     SnmpValue x, long id, Object data)
    throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue=
        meta.buildAttributeValue(id,x);
    final Attribute att = new Attribute(attname,attvalue);

    Object result = null;

    try {
        server.setAttribute(name,att);
        result = server.getAttribute(name,attname);
    } catch(InvalidAttributeValueException iv) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    }

    return meta.buildSnmpValue(id,result);
}
 
Example 39
Project: hashsdn-controller   File: RuntimeBeanRegistratorImplTest.java   View source code 5 votes vote down vote up
protected void checkNotExists(final ObjectName on) throws Exception {
    try {
        platformMBeanServer.getMBeanInfo(on);
        fail();
    } catch (final InstanceNotFoundException e) {
        // FIXME: should it be empty?
    }
}
 
Example 40
Project: OpenJSharp   File: ServerNotifForwarder.java   View source code 5 votes vote down vote up
static void checkMBeanPermission(
        final MBeanServer mbs, final ObjectName name, final String actions)
        throws InstanceNotFoundException, SecurityException {

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        AccessControlContext acc = AccessController.getContext();
        ObjectInstance oi;
        try {
            oi = AccessController.doPrivileged(
                new PrivilegedExceptionAction<ObjectInstance>() {
                    public ObjectInstance run()
                    throws InstanceNotFoundException {
                        return mbs.getObjectInstance(name);
                    }
            });
        } catch (PrivilegedActionException e) {
            throw (InstanceNotFoundException) extractException(e);
        }
        String classname = oi.getClassName();
        MBeanPermission perm = new MBeanPermission(
            classname,
            null,
            name,
            actions);
        sm.checkPermission(perm, acc);
    }
}