Search in sources :

Example 26 with OpenDataException

use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.

the class FileAuditor method registerMBean.

/*
	 * Register the MBean
	 */
private void registerMBean() {
    LOGGER.info("Registering FileAuditor MBean");
    try {
        itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
        OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
        eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the FileAuditor MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 27 with OpenDataException

use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.

the class RDBMSAuditor method registerMBean.

/*
	 * Register the MBean
	 */
private void registerMBean() {
    LOGGER.info("Registering RDBMSAuditor MBean");
    try {
        itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
        OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
        eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    final Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the RDBMSAuditors MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 28 with OpenDataException

use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.

the class RDBMSAuditor method getEvents.

/**
	 * {@inheritDoc}
	 */
@Override
public CompositeData[] getEvents(Integer eventCount) {
    if (eventType == null || eventCount == 0)
        return null;
    final Vector<CompositeData> retVal = new Vector<CompositeData>();
    final Collection<org.nhindirect.common.audit.impl.entity.AuditEvent> rs = this.dao.getRDBMSEvents(eventCount);
    if (rs.size() == 0)
        return null;
    for (org.nhindirect.common.audit.impl.entity.AuditEvent event : rs) {
        String[] contexts = null;
        if (event.getAuditContexts() != null && !event.getAuditContexts().isEmpty()) {
            contexts = new String[event.getAuditContexts().size()];
            int idx = 0;
            for (org.nhindirect.common.audit.impl.entity.AuditContext ctx : event.getAuditContexts()) {
                contexts[idx++] = ctx.getContextName() + ":" + ctx.getContextValue();
            }
        }
        if (contexts == null)
            contexts = new String[] { " " };
        try {
            final Object[] eventValues = { event.getUUID(), event.getEventTime().toString(), event.getPrincipal(), event.getEventName(), event.getEventType(), contexts };
            retVal.add(new CompositeDataSupport(eventType, itemNames, eventValues));
        } catch (OpenDataException e) {
            LOGGER.error("Error create composit data for audit event.", e);
        }
    }
    return retVal.toArray(new CompositeData[retVal.size()]);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) OpenDataException(javax.management.openmbean.OpenDataException) AuditEvent(org.nhindirect.common.audit.AuditEvent) Vector(java.util.Vector)

Example 29 with OpenDataException

use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.

the class MXBeanLookup method mxbeanToObjectName.

synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException("Could not convert " + s + " to an ObjectName: " + wrong);
// Message will be strange if mxbean is null but it is not
// supposed to be.
}
Also used : Proxy(java.lang.reflect.Proxy) OpenDataException(javax.management.openmbean.OpenDataException) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ObjectName(javax.management.ObjectName)

Example 30 with OpenDataException

use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.

the class ConvertingMethod method invokeWithOpenReturn.

private Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
    final Object[] javaParams;
    try {
        javaParams = fromOpenParameters(params);
    } catch (InvalidObjectException e) {
        // probably can't happen
        final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
        throw new MBeanException(e, msg);
    }
    final Object javaReturn = MethodUtil.invoke(method, obj, javaParams);
    try {
        return returnMapping.toOpenValue(javaReturn);
    } catch (OpenDataException e) {
        // probably can't happen
        final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
        throw new MBeanException(e, msg);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) MBeanException(javax.management.MBeanException) InvalidObjectException(java.io.InvalidObjectException)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)51 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)24 TabularDataSupport (javax.management.openmbean.TabularDataSupport)22 TabularType (javax.management.openmbean.TabularType)22 CompositeType (javax.management.openmbean.CompositeType)21 CompositeData (javax.management.openmbean.CompositeData)17 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 MBeanServer (javax.management.MBeanServer)5 TabularData (javax.management.openmbean.TabularData)5 ArrayType (javax.management.openmbean.ArrayType)4 InvalidObjectException (java.io.InvalidObjectException)3 SortedMap (java.util.SortedMap)3 JMException (javax.management.JMException)3 StandardMBean (javax.management.StandardMBean)3 IOException (java.io.IOException)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2