private Object resolveTargetObject(Descriptor descriptor) throws MBeanException { Logger logger = getLogger(); Object target = descriptor.getFieldValue("targetObject"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObject is: " + target); if (target == null) { target = getManagedResource(); } else { String targetObjectType = (String) descriptor.getFieldValue("targetObjectType"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObjectType is: " + targetObjectType); if (targetObjectType == null) { // Not defined, assume object reference targetObjectType = OBJECT_RESOURCE_TYPE; } if (!isResourceTypeSupported(targetObjectType)) throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType)); } return target; }
private Object resolveTargetObject(Descriptor descriptor) throws MBeanException { Logger logger = getLogger(); Object target = descriptor.getFieldValue("targetObject"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObject is: " + target); if (target == null) { target = getManagedResource(); } else { String targetObjectType = (String)descriptor.getFieldValue("targetObjectType"); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("targetObjectType is: " + targetObjectType); if (targetObjectType == null) { // Not defined, assume object reference targetObjectType = OBJECT_RESOURCE_TYPE; } if (!isResourceTypeSupported(targetObjectType)) throw new MBeanException(new InvalidTargetObjectTypeException(targetObjectType)); } return target; }
/** * Sets managed resource to expose and stores its {@link ClassLoader}. */ @Override public void setManagedResource(Object managedResource, String managedResourceType) throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException { this.managedResourceClassLoader = managedResource.getClass().getClassLoader(); super.setManagedResource(managedResource, managedResourceType); }
/** * Get the instance handle of the object against which we execute * all methods in this ModelMBean management interface. * * @exception InstanceNotFoundException if the managed resource object * cannot be found * @exception MBeanException if the initializer of the object throws * an exception * @exception RuntimeOperationsException if the managed resource or the * resource type is <code>null</code> or invalid */ public Object getManagedResource() throws InstanceNotFoundException, InvalidTargetObjectTypeException, MBeanException, RuntimeOperationsException { if (resource == null) throw new RuntimeOperationsException (new IllegalArgumentException("Managed resource is null"), "Managed resource is null"); return resource; }
public void setManagedResource(Object resource, String resourceType) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException { if (resource == null) throw new RuntimeOperationsException(new IllegalArgumentException( LocalizedStrings.MX4JModelMBean_MANAGED_RESOURCE_CANNOT_BE_NULL.toLocalizedString())); if (!isResourceTypeSupported(resourceType)) throw new InvalidTargetObjectTypeException(resourceType); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Setting managed resource to be: " + resource); m_managedResource = resource; }
public void setManagedResource(Object resource, String resourceType) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException { if (resource == null) throw new RuntimeOperationsException(new IllegalArgumentException(LocalizedStrings.MX4JModelMBean_MANAGED_RESOURCE_CANNOT_BE_NULL.toLocalizedString())); if (!isResourceTypeSupported(resourceType)) throw new InvalidTargetObjectTypeException(resourceType); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Setting managed resource to be: " + resource); m_managedResource = resource; }
@Override public ModelMBean assemble(Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null; // use the default provided mbean which has been annotated with JMX // annotations LOGGER.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj); mbi = assembler.getMBeanInfo(obj, null, name.toString()); if (mbi == null) { return null; } RequiredModelMBean mbean = new RequiredModelMBean(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } // Allows the managed object to send notifications if (obj instanceof NotificationSenderAware) { ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean)); } return mbean; }
/** Constructor. * @exception MBeanException * @exception InstanceNotFoundException */ protected HttpServerMBean(HttpServer httpServer) throws MBeanException, InstanceNotFoundException { _httpServer=httpServer; _httpServer.addEventListener(this); try{super.setManagedResource(_httpServer,"objectReference");} catch(InvalidTargetObjectTypeException e){log.warn(LogSupport.EXCEPTION,e);} }
public void setManagedResource(Object o,String s) throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException { if (o!=null) ((HttpServer)o).addEventListener(this); super.setManagedResource(o,s); }
private Class<?> getType(Attributes attributes, String nomAttribut) throws ClassNotFoundException, InvalidTargetObjectTypeException { Class<?> typeToUnmarshall; String typeEcrit = attributes.getValue("type"); if(typeEcrit != null){ typeToUnmarshall = getTypeDepuisNom(attributes.getValue("type")); if(isFirst) checkType(typeToUnmarshall); }else{ typeToUnmarshall = getType(nomAttribut); } return typeToUnmarshall; }
@SuppressWarnings("unchecked") private <T> void checkType(Class<T> typeToUnmarshall) throws InvalidTargetObjectTypeException { try { U test = (U) createInstance(typeToUnmarshall); test.getClass(); } catch (Exception e) { LOGGER.error("le type attendu n'est pas celui du XML ou n'est pas instanciable", e); throw new InvalidTargetObjectTypeException(e, "not instanciable from " + typeToUnmarshall.getName()); } }
protected void startElement(String qName, Attributes attributes) throws ClassNotFoundException, NotImplementedSerializeException, InvalidTargetObjectTypeException, InstanciationException, EntityManagerImplementationException{ setCache(attributes); Class<?> type = getType(attributes, qName); isFirst = false; if(type != null){ ActionXml<?> action = (ActionXml<?>) getAction(type); setNom(action, qName); setFieldInformation(action); setId(attributes, action); pileAction.push(action); } }
public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null; // prefer to use the managed instance if it has been annotated with Spring JMX annotations if (obj instanceof ManagedInstance) { Object custom = ((ManagedInstance) obj).getInstance(); if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) { LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom); // get the mbean info from the custom managed object mbi = springAssembler.getMBeanInfo(custom, name.toString()); // and let the custom object be registered in JMX obj = custom; } } if (mbi == null) { if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) { // the object has a Spring ManagedResource annotations so assemble the MBeanInfo LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj); mbi = springAssembler.getMBeanInfo(obj, name.toString()); } else { // fallback and let the default mbean assembler handle this instead return super.assemble(mBeanServer, obj, name); } } LOG.trace("Assembled MBeanInfo {}", mbi); RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName()); mbean.setModelMBeanInfo(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } // Allows the managed object to send notifications if (obj instanceof NotificationSenderAware) { ((NotificationSenderAware)obj).setNotificationSender(new NotificationSenderAdapter(mbean)); } return mbean; }
public JmxBuilderModelMBean(Object objectRef) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException { super.setManagedResource(objectRef, "ObjectReference"); }
@Override public void setManagedResource(Object mr, String mr_type) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException { }
/** * Get the instance handle of the object against which we execute * all methods in this ModelMBean management interface. * * @exception InstanceNotFoundException if the managed resource object * cannot be found * @exception InvalidTargetObjectTypeException if the managed resource * object is of the wrong type * @exception MBeanException if the initializer of the object throws * an exception * @exception RuntimeOperationsException if the managed resource or the * resource type is <code>null</code> or invalid */ public Object getManagedResource() throws InstanceNotFoundException, InvalidTargetObjectTypeException, MBeanException, RuntimeOperationsException { if (resource == null) throw new RuntimeOperationsException (new IllegalArgumentException("Managed resource is null"), "Managed resource is null"); return resource; }
/** * Get the instance handle of the object against which we execute all * methods in this ModelMBean management interface. * * @exception InstanceNotFoundException * if the managed resource object cannot be found * @exception InvalidTargetObjectTypeException * if the managed resource object is of the wrong type * @exception MBeanException * if the initializer of the object throws an exception * @exception RuntimeOperationsException * if the managed resource or the resource type is * <code>null</code> or invalid */ public Object getManagedResource() throws InstanceNotFoundException, InvalidTargetObjectTypeException, MBeanException, RuntimeOperationsException { if (resource == null) throw new RuntimeOperationsException(new IllegalArgumentException("Managed resource is null"), "Managed resource is null"); return resource; }