/** * Is the specified <code>ModelMBeanInfo</code> instance valid? * * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation * does not check anything, but this method can be overridden * as required.</p> * * @param info The <code>ModelMBeanInfo object to check */ // protected boolean isModelMBeanInfoValid(ModelMBeanInfo info) { // return (true); // } // -------------------- Registration -------------------- // XXX We can add some method patterns here- like setName() and // setDomain() for code that doesn't implement the Registration public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { if( log.isDebugEnabled()) log.debug("preRegister " + resource + " " + name ); oname=name; if( resource instanceof MBeanRegistration ) { oname = ((MBeanRegistration)resource).preRegister(server, name ); } return oname; }
private static ObjectName preRegister( DynamicMBean mbean, MBeanServer mbs, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException { ObjectName newName = null; try { if (mbean instanceof MBeanRegistration) newName = ((MBeanRegistration) mbean).preRegister(mbs, name); } catch (Throwable t) { throwMBeanRegistrationException(t, "in preRegister method"); } if (newName != null) return newName; else return name; }
private static void postRegister( ObjectName logicalName, DynamicMBean mbean, boolean registrationDone, boolean registerFailed) { if (registerFailed && mbean instanceof DynamicMBean2) ((DynamicMBean2) mbean).registerFailed(); try { if (mbean instanceof MBeanRegistration) ((MBeanRegistration) mbean).postRegister(registrationDone); } catch (RuntimeException e) { MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+ "]: " + "Exception thrown by postRegister: " + "rethrowing <"+e+">, but keeping the MBean registered"); throw new RuntimeMBeanException(e, "RuntimeException thrown in postRegister method: "+ "rethrowing <"+e+">, but keeping the MBean registered"); } catch (Error er) { MBEANSERVER_LOGGER.fine("While registering MBean ["+logicalName+ "]: " + "Error thrown by postRegister: " + "rethrowing <"+er+">, but keeping the MBean registered"); throw new RuntimeErrorException(er, "Error thrown in postRegister method: "+ "rethrowing <"+er+">, but keeping the MBean registered"); } }
private static void postDeregisterInvoke(ObjectName mbean, MBeanRegistration moi) { try { moi.postDeregister(); } catch (RuntimeException e) { MBEANSERVER_LOGGER.fine("While unregistering MBean ["+mbean+ "]: " + "Exception thrown by postDeregister: " + "rethrowing <"+e+">, although the MBean is succesfully " + "unregistered"); throw new RuntimeMBeanException(e, "RuntimeException thrown in postDeregister method: "+ "rethrowing <"+e+ ">, although the MBean is sucessfully unregistered"); } catch (Error er) { MBEANSERVER_LOGGER.fine("While unregistering MBean ["+mbean+ "]: " + "Error thrown by postDeregister: " + "rethrowing <"+er+">, although the MBean is succesfully " + "unregistered"); throw new RuntimeErrorException(er, "Error thrown in postDeregister method: "+ "rethrowing <"+er+ ">, although the MBean is sucessfully unregistered"); } }
private static void postRegister( ObjectName logicalName, DynamicMBean mbean, boolean registrationDone, boolean registerFailed) { if (registerFailed && mbean instanceof DynamicMBean2) ((DynamicMBean2) mbean).registerFailed(); try { if (mbean instanceof MBeanRegistration) ((MBeanRegistration) mbean).postRegister(registrationDone); } catch (RuntimeException e) { MBEANSERVER_LOGGER.log(Level.DEBUG, "While registering MBean ["+logicalName+ "]: " + "Exception thrown by postRegister: " + "rethrowing <"+e+">, but keeping the MBean registered"); throw new RuntimeMBeanException(e, "RuntimeException thrown in postRegister method: "+ "rethrowing <"+e+">, but keeping the MBean registered"); } catch (Error er) { MBEANSERVER_LOGGER.log(Level.DEBUG, "While registering MBean ["+logicalName+ "]: " + "Error thrown by postRegister: " + "rethrowing <"+er+">, but keeping the MBean registered"); throw new RuntimeErrorException(er, "Error thrown in postRegister method: "+ "rethrowing <"+er+">, but keeping the MBean registered"); } }
private static void postDeregisterInvoke(ObjectName mbean, MBeanRegistration moi) { try { moi.postDeregister(); } catch (RuntimeException e) { MBEANSERVER_LOGGER.log(Level.DEBUG, "While unregistering MBean ["+mbean+ "]: " + "Exception thrown by postDeregister: " + "rethrowing <"+e+">, although the MBean is succesfully " + "unregistered"); throw new RuntimeMBeanException(e, "RuntimeException thrown in postDeregister method: "+ "rethrowing <"+e+ ">, although the MBean is sucessfully unregistered"); } catch (Error er) { MBEANSERVER_LOGGER.log(Level.DEBUG, "While unregistering MBean ["+mbean+ "]: " + "Error thrown by postDeregister: " + "rethrowing <"+er+">, although the MBean is succesfully " + "unregistered"); throw new RuntimeErrorException(er, "Error thrown in postDeregister method: "+ "rethrowing <"+er+ ">, although the MBean is sucessfully unregistered"); } }
private ServiceRegistration publishServerAsAService(StandardService server) { Properties props = new Properties(); // put some extra properties to easily identify the service props.put(Constants.SERVICE_VENDOR, "Spring Dynamic Modules"); props.put(Constants.SERVICE_DESCRIPTION, ServerInfo.getServerInfo()); props.put(Constants.BUNDLE_VERSION, ServerInfo.getServerNumber()); props.put(Constants.BUNDLE_NAME, bundleContext.getBundle().getSymbolicName()); // spring-dm specific property props.put("org.springframework.osgi.bean.name", "tomcat-server"); // publish just the interfaces and the major classes (server/handlerWrapper) String[] classes = new String[] { StandardService.class.getName(), Service.class.getName(), MBeanRegistration.class.getName(), Lifecycle.class.getName() }; return bundleContext.registerService(classes, server, props); }