/** * Registers this MBean in the MBeanServer of the management context * provided at creation time. This method is only called by the constructor. */ private void register() { try { AnnotatedMBean.registerMBean(this.managementContext, this, this.name); } catch (Exception e) { log.error("Could not register MBean for TransportLoggerView " + id + "with name " + this.name.toString() + ", reason: " + e, e); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void registerMBean(ManagementContext context, Object object, ObjectName objectName) throws Exception { String mbeanName = object.getClass().getName() + "MBean"; for (Class c : object.getClass().getInterfaces()) { if (mbeanName.equals(c.getName())) { context.registerMBean(new AnnotatedMBean(object, c, objectName), objectName); return; } } context.registerMBean(object, objectName); }
entry.setUser(caller); entry.setTimestamp(System.currentTimeMillis()); entry.setTarget(extractTargetTypeProperty(objectName)); entry.setOperation(this.getMBeanInfo().getClassName() + "." + s); Method m = getMBeanMethod(this.getImplementationClass(), s, strings); entry.getParameters().put("arguments", AuditLogEntry.sanitizeArguments(objects, m));
/** {@inheritDoc} */ @Override protected String getDescription(MBeanAttributeInfo info) { String descr = info.getDescription(); Method m = getMethod(getMBeanInterface(), "get" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m == null) m = getMethod(getMBeanInterface(), "is" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m == null) m = getMethod(getMBeanInterface(), "does" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m != null) { MBeanInfo d = m.getAnnotation(MBeanInfo.class); if (d != null) descr = d.value(); } return descr; }
entry.setUser(caller); entry.setTimestamp(System.currentTimeMillis()); entry.setOperation(this.getMBeanInfo().getClassName() + "." + s); Method m = getMBeanMethod(this.getImplementationClass(), s, strings); entry.getParameters().put("arguments", AuditLogEntry.sanitizeArguments(objects, m));
/** {@inheritDoc} */ @Override protected String getDescription(MBeanOperationInfo op) { String descr = op.getDescription(); Method m = getMethod(op); if (m != null) { MBeanInfo d = m.getAnnotation(MBeanInfo.class); if (d != null) descr = d.value(); } return descr; }
protected Object asyncInvole(String s, Object[] objects, String[] strings) throws MBeanException, ReflectionException { return super.invoke(s, objects, strings); }
@Override public Object invoke(String s, Object[] objects, String[] strings) throws MBeanException, ReflectionException { if (audit) { Subject subject = Subject.getSubject(AccessController.getContext()); String caller = "anonymous"; if (subject != null) { caller = ""; for (Principal principal : subject.getPrincipals()) { caller += principal.getName() + " "; } } AuditLogEntry entry = new JMXAuditLogEntry(); entry.setUser(caller); entry.setTimestamp(System.currentTimeMillis()); entry.setOperation(this.getMBeanInfo().getClassName() + "." + s); entry.getParameters().put("arguments", objects); auditLog.log(entry); } return super.invoke(s, objects, strings); } }
public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception { if (bean instanceof AnnotatedMBean) { Object impl = ((AnnotatedMBean) bean).getImplementation(); if (impl instanceof SubscriptionViewMBean) { return null; } } else if (bean instanceof SubscriptionViewMBean) { return null; } return super.registerMBean(bean, name); } }
/** * Extracts the Method from the MBeanOperationInfo * * @param op * * @return a Method */ private Method getMethod(MBeanOperationInfo op) { final MBeanParameterInfo[] params = op.getSignature(); final String[] paramTypes = new String[params.length]; for (int i = 0; i < params.length; i++) paramTypes[i] = params[i].getType(); return getMethod(getMBeanInterface(), op.getName(), paramTypes); }
entry.setUser(caller); entry.setTimestamp(System.currentTimeMillis()); entry.setOperation(this.getMBeanInfo().getClassName() + "." + s); Method m = getMBeanMethod(this.getImplementationClass(), s, strings); entry.getParameters().put("arguments", AuditLogEntry.sanitizeArguments(objects, m));
/** {@inheritDoc} */ @Override protected String getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int paramNo) { String name = param.getName(); Method m = getMethod(op); if (m != null) { for (Annotation a : m.getParameterAnnotations()[paramNo]) { if (MBeanInfo.class.isInstance(a)) name = MBeanInfo.class.cast(a).value(); } } return name; }
protected Object asyncInvole(String s, Object[] objects, String[] strings) throws MBeanException, ReflectionException { return super.invoke(s, objects, strings); }
public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception { if (bean instanceof AnnotatedMBean) { Object impl = ((AnnotatedMBean) bean).getImplementation(); if (impl instanceof SubscriptionViewMBean) { return null; } } else if (bean instanceof SubscriptionViewMBean) { return null; } return super.registerMBean(bean, name); } }
protected void registerMBean(ObjectName name) { if (name != null) { try { AnnotatedMBean.registerMBean(managementContext, mbean, name); } catch (Throwable e) { LOG.warn("Failed to register MBean {}", name); LOG.debug("Failure reason: ", e); } } }
/** {@inheritDoc} */ @Override protected String getDescription(MBeanAttributeInfo info) { String descr = info.getDescription(); Method m = getMethod(getMBeanInterface(), "get" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m == null) m = getMethod(getMBeanInterface(), "is" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m == null) m = getMethod(getMBeanInterface(), "does" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1)); if (m != null) { MBeanInfo d = m.getAnnotation(MBeanInfo.class); if (d != null) descr = d.value(); } return descr; }
entry.setUser(caller); entry.setTimestamp(System.currentTimeMillis()); entry.setOperation(this.getMBeanInfo().getClassName() + "." + s); Method m = getMBeanMethod(this.getImplementationClass(), s, strings); entry.getParameters().put("arguments", AuditLogEntry.sanitizeArguments(objects, m));
/** {@inheritDoc} */ @Override protected String getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int paramNo) { String name = param.getName(); Method m = getMethod(op); if (m != null) { for (Annotation a : m.getParameterAnnotations()[paramNo]) { if (MBeanInfo.class.isInstance(a)) name = MBeanInfo.class.cast(a).value(); } } return name; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static ObjectInstance registerMBean(ExecutorService executor, long timeout, ManagementContext context, Object object, ObjectName objectName) throws Exception { if (timeout < 0 && executor != null) { throw new IllegalArgumentException("async timeout cannot be negative."); } if (timeout > 0 && executor == null) { throw new NullPointerException("timeout given but no ExecutorService instance given."); } String mbeanName = object.getClass().getName() + "MBean"; for (Class c : object.getClass().getInterfaces()) { if (mbeanName.equals(c.getName())) { if (timeout == 0) { return context.registerMBean(new AnnotatedMBean(object, c, objectName), objectName); } else { return context.registerMBean(new AsyncAnnotatedMBean(executor, timeout, object, c, objectName), objectName); } } } return context.registerMBean(object, objectName); }
protected Object asyncInvole(String s, Object[] objects, String[] strings) throws MBeanException, ReflectionException { return super.invoke(s, objects, strings); }