/** * Returns the object name of the exposed component. * * @return the object name of the exposed component. */ private String getObjectNameString() { if (m_completeObjNameElt != null) { return m_completeObjNameElt; } String domain; if (m_domainElt != null) { domain = m_domainElt; } else { domain = getPackageName(m_instanceManager.getClassName()); } String name = "type=" + m_instanceManager.getClassName() + ",instance=" + m_instanceManager.getInstanceName(); if (m_objNameWODomainElt != null) { name = "name=" + m_objNameWODomainElt; } StringBuffer sb = new StringBuffer(); if ((domain != null) && (domain.length() > 0)) { sb.append(domain + ":"); } sb.append(name); info("Computed Objectname: " + sb.toString()); return sb.toString(); }
/** * Called when a POJO member is read by the MBean. * * @param pojo the read POJO object. * @param fieldName the name of the modified field * @param value the old value of the field * @return the (injected) value of the field * @see FieldInterceptor#onGet(Object, String, Object) */ public Object onGet(Object pojo, String fieldName, Object value) { // Check if the field is a configurable property PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName); if (propertyField != null) { // Do we have a value to inject ? Object v = propertyField.getValue(); if (v == null) { String type = propertyField.getType(); if ("boolean".equals(type)) { v = Boolean.FALSE; } else if ("byte".equals(type)) { v = new Byte((byte) 0); } else if ("short".equals(type)) { v = new Short((short) 0); } else if ("int".equals(type)) { v = new Integer(0); } else if ("long".equals(type)) { v = new Long(0); } else if ("float".equals(type)) { v = new Float(0); } else if ("double".equals(type)) { v = new Double(0); } else if ("char".equals(type)) { v = new Character((char) 0); } return v; } m_instanceManager.onSet(pojo, fieldName, propertyField.getValue()); return propertyField.getValue(); } return value; }
/** Registers the Dynamic Mbean. */ public void start() { // create the corresponding MBean if (m_registerCallbacks) { m_MBean = new DynamicMBeanWRegisterImpl( m_jmxConfigFieldMap, m_instanceManager, m_preRegisterMeth, m_postRegisterMeth, m_preDeregisterMeth, m_postDeregisterMeth); } else { m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager); } if (m_usesMOSGi) { // use whiteboard pattern to register MBean if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); } // Register the ManagedService BundleContext bundleContext = m_instanceManager.getContext(); Properties properties = new Properties(); try { m_objectName = new ObjectName(getObjectNameString()); properties.put("jmxagent.objectName", m_objectName.toString()); m_serviceRegistration = bundleContext.registerService( javax.management.DynamicMBean.class.getName(), m_MBean, properties); m_registered = true; } catch (Exception e) { e.printStackTrace(); } } else { try { m_objectName = new ObjectName(getObjectNameString()); ObjectInstance instance = ManagementFactory.getPlatformMBeanServer().registerMBean(m_MBean, m_objectName); // we must retrieve object name used to register the MBean. // It can have been changed by preRegister method of // MBeanRegistration interface. if (m_registerCallbacks) { m_objectName = instance.getObjectName(); } m_registered = true; } catch (Exception e) { error("Registration of MBean failed.", e); } } }
/** * Returns true if the MOSGi framework is present on the OSGi platform. * * @return {@code true} if the MOSGi framework is present on the OSGi platform, false otherwise. */ public boolean isMOSGiExists() { for (Bundle bundle : m_instanceManager.getContext().getBundles()) { String symbolicName = bundle.getSymbolicName(); if ("org.apache.felix.mosgi.jmx.agent".equals(symbolicName)) { return true; } } return false; }