Java Code Examples for javax.management.openmbean.OpenDataException

The following are top voted examples for showing how to use javax.management.openmbean.OpenDataException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: apache-tomcat-7.0.73-with-comment   File: SlowQueryReportJmx.java   Source Code and License 7 votes vote down vote up
/**
 * JMX operation - returns all the queries we have collected.
 * @return - the slow query report as composite data.
 */
@Override
public CompositeData[] getSlowQueriesCD() throws OpenDataException {
    CompositeDataSupport[] result = null;
    ConcurrentHashMap<String,QueryStats> queries = perPoolStats.get(poolName);
    if (queries!=null) {
        Set<Map.Entry<String,QueryStats>> stats = queries.entrySet();
        if (stats!=null) {
            result = new CompositeDataSupport[stats.size()];
            Iterator<Map.Entry<String,QueryStats>> it = stats.iterator();
            int pos = 0;
            while (it.hasNext()) {
                Map.Entry<String,QueryStats> entry = it.next();
                QueryStats qs = entry.getValue();
                result[pos++] = qs.getCompositeData(getCompositeType());
            }
        }
    }
    return result;
}
 
Example 2
Project: lams   File: JobDetailSupport.java   Source Code and License 6 votes vote down vote up
/**
 * @param jobDetail
 * @return CompositeData
 */
public static CompositeData toCompositeData(JobDetail jobDetail) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        jobDetail.getKey().getName(),
                        jobDetail.getKey().getGroup(),
                        jobDetail.getDescription(),
                        jobDetail.getJobClass().getName(),
                        JobDataMapSupport.toTabularData(jobDetail
                                .getJobDataMap()), 
                        jobDetail.isDurable(),
                        jobDetail.requestsRecovery(), });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Project: lams   File: CronTriggerSupport.java   Source Code and License 6 votes vote down vote up
public static CompositeData toCompositeData(CronTrigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getCronExpression(),
                        trigger.getTimeZone(),
                        trigger.getKey().getName(),
                        trigger.getKey().getGroup(),
                        trigger.getJobKey().getName(),
                        trigger.getJobKey().getGroup(),
                        trigger.getDescription(),
                        JobDataMapSupport.toTabularData(trigger
                                .getJobDataMap()),
                        trigger.getCalendarName(),
                        ((OperableTrigger)trigger).getFireInstanceId(),
                        trigger.getMisfireInstruction(),
                        trigger.getPriority(), trigger.getStartTime(),
                        trigger.getEndTime(), trigger.getNextFireTime(),
                        trigger.getPreviousFireTime(),
                        trigger.getFinalFireTime() });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Project: lams   File: SimpleTriggerSupport.java   Source Code and License 6 votes vote down vote up
public static CompositeData toCompositeData(SimpleTrigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getRepeatCount(),
                        trigger.getRepeatInterval(),
                        trigger.getTimesTriggered(),
                        trigger.getKey().getName(),
                        trigger.getKey().getGroup(),
                        trigger.getJobKey().getName(),
                        trigger.getJobKey().getGroup(),
                        trigger.getDescription(),
                        JobDataMapSupport.toTabularData(trigger
                                .getJobDataMap()),
                        trigger.getCalendarName(),
                        ((OperableTrigger)trigger).getFireInstanceId(),
                        trigger.getMisfireInstruction(),
                        trigger.getPriority(), trigger.getStartTime(),
                        trigger.getEndTime(), trigger.getNextFireTime(),
                        trigger.getPreviousFireTime(),
                        trigger.getFinalFireTime() });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Project: lams   File: TriggerSupport.java   Source Code and License 6 votes vote down vote up
public static CompositeData toCompositeData(Trigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getKey().getName(),
                        trigger.getKey().getGroup(),
                        trigger.getJobKey().getName(),
                        trigger.getJobKey().getGroup(),
                        trigger.getDescription(),
                        JobDataMapSupport.toTabularData(trigger
                                .getJobDataMap()),
                        trigger.getCalendarName(),
                        ((OperableTrigger)trigger).getFireInstanceId(),
                        trigger.getMisfireInstruction(),
                        trigger.getPriority(), trigger.getStartTime(),
                        trigger.getEndTime(), trigger.getNextFireTime(),
                        trigger.getPreviousFireTime(),
                        trigger.getFinalFireTime() });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Project: asura   File: JobDetailSupport.java   Source Code and License 6 votes vote down vote up
/**
 * @param jobDetail
 * @return CompositeData
 */
public static CompositeData toCompositeData(JobDetail jobDetail) {
	try {
		return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
				new Object[] {
						jobDetail.getName(),
						jobDetail.getGroup(),
						jobDetail.getDescription(),
						jobDetail.getJobClass().getName(),
						JobDataMapSupport.toTabularData(jobDetail
								.getJobDataMap()), jobDetail.isVolatile(),
						jobDetail.isDurable(),
						jobDetail.requestsRecovery(), });
	} catch (OpenDataException e) {
		throw new RuntimeException(e);
	}
}
 
Example 7
Project: OpenJSharp   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 8
Project: OpenJSharp   File: StackTraceElementCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // stackTraceElementItemNames!
    final Object[] stackTraceElementItemValues = {
        ste.getClassName(),
        ste.getMethodName(),
        ste.getFileName(),
        new Integer(ste.getLineNumber()),
        new Boolean(ste.isNativeMethod()),
    };
    try {
        return new CompositeDataSupport(stackTraceElementCompositeType,
                                        stackTraceElementItemNames,
                                        stackTraceElementItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 9
Project: OpenJSharp   File: LockInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // lockInfoItemNames!
    final Object[] lockInfoItemValues = {
        new String(lock.getClassName()),
        new Integer(lock.getIdentityHashCode()),
    };

    try {
        return new CompositeDataSupport(lockInfoCompositeType,
                                        lockInfoItemNames,
                                        lockInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw Util.newException(e);
    }
}
 
Example 10
Project: OpenJSharp   File: VMOptionCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // vmOptionItemNames!
    final Object[] vmOptionItemValues = {
        option.getName(),
        option.getValue(),
        new Boolean(option.isWriteable()),
        option.getOrigin().toString(),
    };

    try {
        return new CompositeDataSupport(vmOptionCompositeType,
                                        vmOptionItemNames,
                                        vmOptionItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 11
Project: OpenJSharp   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryNotifInfoItemNames!
    final Object[] memoryNotifInfoItemValues = {
        memoryNotifInfo.getPoolName(),
        MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),
        new Long(memoryNotifInfo.getCount()),
    };

    try {
        return new CompositeDataSupport(memoryNotifInfoCompositeType,
                                        memoryNotifInfoItemNames,
                                        memoryNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 12
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    final Collection<?> valueCollection = (Collection<?>) value;
    if (valueCollection instanceof SortedSet<?>) {
        Comparator<?> comparator =
            ((SortedSet<?>) valueCollection).comparator();
        if (comparator != null) {
            final String msg =
                "Cannot convert SortedSet with non-null comparator: " +
                comparator;
            throw openDataException(msg, new IllegalArgumentException(msg));
        }
    }
    final Object[] openArray = (Object[])
        Array.newInstance(getOpenClass().getComponentType(),
                          valueCollection.size());
    int i = 0;
    for (Object o : valueCollection)
        openArray[i++] = elementMapping.toOpenValue(o);
    return openArray;
}
 
Example 13
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example 14
Project: hashsdn-controller   File: TOAttribute.java   Source Code and License 6 votes vote down vote up
@Override
public CompositeType getOpenType() {
    final String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();

    final FunctionImpl functionImpl = new FunctionImpl();
    final Map<String, AttributeIfc> jmxPropertiesToTypesMap = getJmxPropertiesToTypesMap();
    final OpenType<?>[] itemTypes = Collections2.transform(
            jmxPropertiesToTypesMap.entrySet(), functionImpl).toArray(
            new OpenType<?>[] {});
    final String[] itemNames = functionImpl.getItemNames();
    try {
        // TODO add package name to create fully qualified name for this
        // type
        final CompositeType compositeType = new CompositeType(
                getUpperCaseCammelCase(), description, itemNames,
                itemNames, itemTypes);
        return compositeType;
    } catch (final OpenDataException e) {
        throw new RuntimeException("Unable to create CompositeType for "
                + this, e);
    }
}
 
Example 15
Project: monarch   File: CollectionConverter.java   Source Code and License 6 votes vote down vote up
final Object toNonNullOpenValue(Object value) throws OpenDataException {
  final Collection valueCollection = (Collection) value;
  if (valueCollection instanceof SortedSet) {
    Comparator comparator = ((SortedSet) valueCollection).comparator();
    if (comparator != null) {
      final String msg = "Cannot convert SortedSet with non-null comparator: " + comparator;
      throw openDataException(msg, new IllegalArgumentException(msg));
    }
  }
  final Object[] openArray =
      (Object[]) Array.newInstance(getOpenClass().getComponentType(), valueCollection.size());
  int i = 0;
  for (Object o : valueCollection)
    openArray[i++] = elementConverter.toOpenValue(o);
  return openArray;
}
 
Example 16
Project: monarch   File: OpenTypeConverter.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * @param objType
 * @return the converter for the given Java type, creating it if necessary
 * @throws OpenDataException
 */
public static synchronized OpenTypeConverter toConverter(Type objType) throws OpenDataException {

  if (inProgress.containsKey(objType)) {
    throw new OpenDataException("Recursive data structure, including " + typeName(objType));
  }

  OpenTypeConverter conv;

  conv = getConverter(objType);
  if (conv != null)
    return conv;

  inProgress.put(objType, objType);
  try {
    conv = makeConverter(objType);
  } catch (OpenDataException e) {
    throw openDataException("Cannot convert type: " + objType, e);
  } finally {
    inProgress.remove(objType);
  }

  putConverter(objType, conv);
  return conv;
}
 
Example 17
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example 18
Project: openjdk-jdk10   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 19
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example 20
Project: monarch   File: CompositeConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Converts to open value
 */
final Object toNonNullOpenValue(Object value) throws OpenDataException {
  CompositeType ct = (CompositeType) getOpenType();
  if (value instanceof CompositeDataView)
    return ((CompositeDataView) value).toCompositeData(ct);
  if (value == null)
    return null;

  Object[] values = new Object[getters.length];
  for (int i = 0; i < getters.length; i++) {
    try {
      Object got = getters[i].invoke(value, (Object[]) null);
      values[i] = getterConverters[i].toOpenValue(got);
    } catch (Exception e) {
      throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e);
    }
  }
  return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 21
Project: openjdk-jdk10   File: MemoryUsageCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryUsageItemNames!
    final Object[] memoryUsageItemValues = {
        usage.getInit(),
        usage.getUsed(),
        usage.getCommitted(),
        usage.getMax(),
    };

    try {
        return new CompositeDataSupport(memoryUsageCompositeType,
                                        memoryUsageItemNames,
                                        memoryUsageItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 22
Project: apache-tomcat-7.0.73-with-comment   File: SlowQueryReport.java   Source Code and License 6 votes vote down vote up
public CompositeDataSupport getCompositeData(final CompositeType type) throws OpenDataException{
    Object[] values = new Object[] {
            query,
            Integer.valueOf(nrOfInvocations),
            Long.valueOf(maxInvocationTime),
            Long.valueOf(maxInvocationDate),
            Long.valueOf(minInvocationTime),
            Long.valueOf(minInvocationDate),
            Long.valueOf(totalInvocationTime),
            Long.valueOf(failures),
            Integer.valueOf(prepareCount),
            Long.valueOf(prepareTime),
            Long.valueOf(lastInvocation)
    };
    return new CompositeDataSupport(type,FIELD_NAMES,values);
}
 
Example 23
Project: jdk8u-jdk   File: GarbageCollectionNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 24
Project: openjdk-jdk10   File: LockInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // lockInfoItemNames!
    final Object[] lockInfoItemValues = {
        new String(lock.getClassName()),
        lock.getIdentityHashCode(),
    };

    try {
        return new CompositeDataSupport(lockInfoCompositeType,
                                        lockInfoItemNames,
                                        lockInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw Util.newException(e);
    }
}
 
Example 25
Project: jdk8u-jdk   File: LockInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // lockInfoItemNames!
    final Object[] lockInfoItemValues = {
        new String(lock.getClassName()),
        new Integer(lock.getIdentityHashCode()),
    };

    try {
        return new CompositeDataSupport(lockInfoCompositeType,
                                        lockInfoItemNames,
                                        lockInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw Util.newException(e);
    }
}
 
Example 26
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example 27
Project: jdk8u-jdk   File: MemoryUsageCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryUsageItemNames!
    final Object[] memoryUsageItemValues = {
        new Long(usage.getInit()),
        new Long(usage.getUsed()),
        new Long(usage.getCommitted()),
        new Long(usage.getMax()),
    };

    try {
        return new CompositeDataSupport(memoryUsageCompositeType,
                                        memoryUsageItemNames,
                                        memoryUsageItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 28
Project: jdk8u-jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryNotifInfoItemNames!
    final Object[] memoryNotifInfoItemValues = {
        memoryNotifInfo.getPoolName(),
        MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),
        new Long(memoryNotifInfo.getCount()),
    };

    try {
        return new CompositeDataSupport(memoryNotifInfoCompositeType,
                                        memoryNotifInfoItemNames,
                                        memoryNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 29
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example 30
Project: openjdk-jdk10   File: StackTraceElementCompositeData.java   Source Code and License 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // stackTraceElementItemNames!
    final Object[] stackTraceElementItemValues = {
        ste.getClassLoaderName(),
        ste.getModuleName(),
        ste.getModuleVersion(),
        ste.getClassName(),
        ste.getMethodName(),
        ste.getFileName(),
        ste.getLineNumber(),
        ste.isNativeMethod(),
    };
    try {
        return new CompositeDataSupport(stackTraceElementCompositeType,
                                        stackTraceElementItemNames,
                                        stackTraceElementItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 31
Project: APacheSynapseSimplePOC   File: JSON1.java   Source Code and License 5 votes vote down vote up
/**
 * Will call all getter methods on payload that are defined in the given interfaces
 */
public static Map makeCallerChain ( Object payload, Class... ifaces ) throws OpenDataException, NoSuchMethodException, InstantiationException,
        IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
    CompositeType rt = new CompositeType("a", "b", new String[] {
        "a"
    }, new String[] {
        "a"
    }, new OpenType[] {
        javax.management.openmbean.SimpleType.INTEGER
    });
    TabularType tt = new TabularType("a", "b", rt, new String[] {
        "a"
    });
    TabularDataSupport t1 = new TabularDataSupport(tt);
    TabularDataSupport t2 = new TabularDataSupport(tt);

    // we need to make payload implement composite data
    // it's very likely that there are other proxy impls that could be used
    AdvisedSupport as = new AdvisedSupport();
    as.setTarget(payload);
    InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections
            .getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
    InvocationHandler cdsInvocationHandler = Gadgets.createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
    CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
    invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
    invocationHandler.setDefaultHandler(delegateInvocationHandler);
    final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);

    JSONObject jo = new JSONObject();
    Map m = new HashMap();
    m.put("t", cdsProxy);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(t1, "dataMap", jo);
    Reflections.setFieldValue(t2, "dataMap", jo);
    return Gadgets.makeMap(t1, t2);
}
 
Example 32
Project: ysoserial-plus   File: JSON1.java   Source Code and License 5 votes vote down vote up
/**
 * Will call all getter methods on payload that are defined in the given interfaces
 */
public static Map makeCallerChain ( Object payload, Class... ifaces ) throws OpenDataException, NoSuchMethodException, InstantiationException,
        IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
    CompositeType rt = new CompositeType("a", "b", new String[] {
        "a"
    }, new String[] {
        "a"
    }, new OpenType[] {
        javax.management.openmbean.SimpleType.INTEGER
    });
    TabularType tt = new TabularType("a", "b", rt, new String[] {
        "a"
    });
    TabularDataSupport t1 = new TabularDataSupport(tt);
    TabularDataSupport t2 = new TabularDataSupport(tt);

    // we need to make payload implement composite data
    // it's very likely that there are other proxy impls that could be used
    AdvisedSupport as = new AdvisedSupport();
    as.setTarget(payload);
    InvocationHandler delegateInvocationHandler = (InvocationHandler) Reflections
            .getFirstCtor("org.springframework.aop.framework.JdkDynamicAopProxy").newInstance(as);
    InvocationHandler cdsInvocationHandler = Gadgets.createMemoizedInvocationHandler(Gadgets.createMap("getCompositeType", rt));
    CompositeInvocationHandlerImpl invocationHandler = new CompositeInvocationHandlerImpl();
    invocationHandler.addInvocationHandler(CompositeData.class, cdsInvocationHandler);
    invocationHandler.setDefaultHandler(delegateInvocationHandler);
    final CompositeData cdsProxy = Gadgets.createProxy(invocationHandler, CompositeData.class, ifaces);

    JSONObject jo = new JSONObject();
    Map m = new HashMap();
    m.put("t", cdsProxy);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(jo, "properties", m);
    Reflections.setFieldValue(t1, "dataMap", jo);
    Reflections.setFieldValue(t2, "dataMap", jo);
    return Gadgets.makeMap(t1, t2);
}
 
Example 33
Project: lams   File: JobDataMapSupport.java   Source Code and License 5 votes vote down vote up
/**
 * @return composite data
 */
public static CompositeData toCompositeData(String key, String value) {
    try {
        return new CompositeDataSupport(rowType, keyValue, new Object[] {
                key, value });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 34
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
@Override
public final Object toOpenValue(Object javaValue) throws OpenDataException {
    if (javaValue == null)
        return null;
    else
        return toNonNullOpenValue(javaValue);
}
 
Example 35
Project: OpenJSharp   File: MonitorInfoCompositeData.java   Source Code and License 5 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // monitorInfoItemNames!

    int len = monitorInfoItemNames.length;
    Object[] values = new Object[len];
    CompositeData li = LockInfoCompositeData.toCompositeData(lock);

    for (int i = 0; i < len; i++) {
        String item = monitorInfoItemNames[i];
        if (item.equals(LOCKED_STACK_FRAME)) {
            StackTraceElement ste = lock.getLockedStackFrame();
            values[i] = (ste != null ? StackTraceElementCompositeData.
                                           toCompositeData(ste)
                                     : null);
        } else if (item.equals(LOCKED_STACK_DEPTH)) {
            values[i] = new Integer(lock.getLockedStackDepth());
        } else {
            values[i] = li.get(item);
        }
    }

    try {
        return new CompositeDataSupport(monitorInfoCompositeType,
                                        monitorInfoItemNames,
                                        values);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 36
Project: openjdk-jdk10   File: ConvertingMethod.java   Source Code and License 5 votes vote down vote up
final Object[] toOpenParameters(MXBeanLookup lookup, Object[] params)
        throws OpenDataException {
    if (paramConversionIsIdentity || params == null)
        return params;
    final Object[] oparams = new Object[params.length];
    for (int i = 0; i < params.length; i++)
        oparams[i] = paramMappings[i].toOpenValue(params[i]);
    return oparams;
}
 
Example 37
Project: jdk8u-jdk   File: AttributeArbitraryDataTypeTest.java   Source Code and License 5 votes vote down vote up
public CompositeData getCompositeDataAttribute()
    throws OpenDataException {
    CompositeType ct = new CompositeType("CompositeDataAttribute",
                                         "Composite Data Attribute",
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
    Object itemValues[] = { ia, da, sa };
    return new CompositeDataSupport(ct, itemNames, itemValues);
}
 
Example 38
Project: OpenJSharp   File: GcInfoCompositeData.java   Source Code and License 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageBeforeGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC);
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 39
Project: openjdk-jdk10   File: MerlinMXBean.java   Source Code and License 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 40
Project: OpenJSharp   File: ConvertingMethod.java   Source Code and License 5 votes vote down vote up
final Object[] toOpenParameters(MXBeanLookup lookup, Object[] params)
        throws OpenDataException {
    if (paramConversionIsIdentity || params == null)
        return params;
    final Object[] oparams = new Object[params.length];
    for (int i = 0; i < params.length; i++)
        oparams[i] = paramMappings[i].toOpenValue(params[i]);
    return oparams;
}
 
Example 41
Project: OpenJSharp   File: ConvertingMethod.java   Source Code and License 5 votes vote down vote up
private ConvertingMethod(Method m) throws OpenDataException {
    this.method = m;
    MXBeanMappingFactory mappingFactory = MXBeanMappingFactory.DEFAULT;
    returnMapping =
            mappingFactory.mappingForType(m.getGenericReturnType(), mappingFactory);
    Type[] params = m.getGenericParameterTypes();
    paramMappings = new MXBeanMapping[params.length];
    boolean identity = true;
    for (int i = 0; i < params.length; i++) {
        paramMappings[i] = mappingFactory.mappingForType(params[i], mappingFactory);
        identity &= DefaultMXBeanMappingFactory.isIdentity(paramMappings[i]);
    }
    paramConversionIsIdentity = identity;
}
 
Example 42
Project: OpenJSharp   File: MXBeanLookup.java   Source Code and License 5 votes vote down vote up
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.
}
 
Example 43
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
@Override
public final Object toOpenValue(Object javaValue) throws OpenDataException {
    if (javaValue == null)
        return null;
    else
        return toNonNullOpenValue(javaValue);
}
 
Example 44
Project: openjdk-jdk10   File: TabularDataOrderTest.java   Source Code and License 5 votes vote down vote up
private static TabularData makeTable() throws OpenDataException {
    TabularData td = new TabularDataSupport(tt);
    for (Map.Entry<String, Integer> entry : stringToValue.entrySet()) {
        CompositeData cd = new CompositeDataSupport(
                ct,
                new String[] {"name", "int"},
                new Object[] {entry.getKey(), entry.getValue()});
        td.put(cd);
    }
    return td;
}
 
Example 45
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object javaValue)
        throws OpenDataException {
    MXBeanLookup lookup = lookupNotNull(OpenDataException.class);
    ObjectName name = lookup.mxbeanToObjectName(javaValue);
    if (name == null)
        throw new OpenDataException("No name for object: " + javaValue);
    return name;
}
 
Example 46
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object javaValue)
        throws OpenDataException {
    MXBeanLookup lookup = lookupNotNull(OpenDataException.class);
    ObjectName name = lookup.mxbeanToObjectName(javaValue);
    if (name == null)
        throw new OpenDataException("No name for object: " + javaValue);
    return name;
}
 
Example 47
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
static void mustBeComparable(Class<?> collection, Type element)
        throws OpenDataException {
    if (!(element instanceof Class<?>)
        || !Comparable.class.isAssignableFrom((Class<?>) element)) {
        final String msg =
            "Parameter class " + element + " of " +
            collection.getName() + " does not implement " +
            Comparable.class.getName();
        throw new OpenDataException(msg);
    }
}
 
Example 48
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object javaValue)
        throws OpenDataException {
    MXBeanLookup lookup = lookupNotNull(OpenDataException.class);
    ObjectName name = lookup.mxbeanToObjectName(javaValue);
    if (name == null)
        throw new OpenDataException("No name for object: " + javaValue);
    return name;
}
 
Example 49
Project: monarch   File: OpenTypeConverter.java   Source Code and License 5 votes vote down vote up
private static OpenTypeConverter makeTabularConverter(Type objType, boolean sortedMap,
    Type keyType, Type valueType) throws OpenDataException {

  final String objTypeName = objType.toString();
  final OpenTypeConverter keyConverter = toConverter(keyType);
  final OpenTypeConverter valueConverter = toConverter(valueType);
  final OpenType keyOpenType = keyConverter.getOpenType();
  final OpenType valueOpenType = valueConverter.getOpenType();
  final CompositeType rowType = new CompositeType(objTypeName, objTypeName, keyValueArray,
      keyValueArray, new OpenType[] {keyOpenType, valueOpenType});
  final TabularType tabularType = new TabularType(objTypeName, objTypeName, rowType, keyArray);
  return new TableConverter(objType, sortedMap, tabularType, keyConverter, valueConverter);
}
 
Example 50
Project: openjdk-jdk10   File: MonitorInfoCompositeData.java   Source Code and License 5 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // monitorInfoItemNames!

    int len = monitorInfoItemNames.length;
    Object[] values = new Object[len];
    CompositeData li = LockInfoCompositeData.toCompositeData(lock);

    for (int i = 0; i < len; i++) {
        String item = monitorInfoItemNames[i];
        if (item.equals(LOCKED_STACK_FRAME)) {
            StackTraceElement ste = lock.getLockedStackFrame();
            values[i] = (ste != null ? StackTraceElementCompositeData.
                                           toCompositeData(ste)
                                     : null);
        } else if (item.equals(LOCKED_STACK_DEPTH)) {
            values[i] = lock.getLockedStackDepth();
        } else {
            values[i] = li.get(item);
        }
    }

    try {
        return new CompositeDataSupport(monitorInfoCompositeType,
                                        monitorInfoItemNames,
                                        values);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 51
Project: monarch   File: CompositeConverter.java   Source Code and License 5 votes vote down vote up
CompositeConverter(Class targetClass, CompositeType compositeType, String[] itemNames,
    Method[] getters) throws OpenDataException {
  super(targetClass, compositeType, CompositeData.class);

  assert (itemNames.length == getters.length);

  this.itemNames = itemNames;
  this.getters = getters;
  this.getterConverters = new OpenTypeConverter[getters.length];
  for (int i = 0; i < getters.length; i++) {
    Type retType = getters[i].getGenericReturnType();
    getterConverters[i] = OpenTypeConverter.toConverter(retType);
  }
}
 
Example 52
Project: openjdk-jdk10   File: TypeVersionMapper.java   Source Code and License 5 votes vote down vote up
private OpenType<?> getVersionedType(OpenType<?> type, String version)
    throws OpenDataException
{
    if (type instanceof ArrayType) {
        return getVersionedArrayType((ArrayType)type, version);
    }
    if (type instanceof CompositeType) {
        return getVersionedCompositeType((CompositeType)type, version);
    }
    if (type instanceof TabularType) {
        return getVersionedTabularType((TabularType)type, version);
    }
    return type;
}
 
Example 53
Project: jdk8u-jdk   File: MerlinMXBean.java   Source Code and License 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 54
Project: monarch   File: OpenMethod.java   Source Code and License 5 votes vote down vote up
final Object[] toOpenParameters(Object[] params) throws OpenDataException {
  if (paramConversionIsIdentity || params == null)
    return params;
  final Object[] oparams = new Object[params.length];
  for (int i = 0; i < params.length; i++)
    oparams[i] = paramTypeConverters[i].toOpenValue(params[i]);
  return oparams;
}
 
Example 55
Project: monarch   File: OpenMethod.java   Source Code and License 5 votes vote down vote up
private OpenMethod(Method m) throws OpenDataException {
  this.method = m;
  returnTypeConverter = OpenTypeConverter.toConverter(m.getGenericReturnType());
  Type[] params = m.getGenericParameterTypes();
  paramTypeConverters = new OpenTypeConverter[params.length];
  boolean identity = true;
  for (int i = 0; i < params.length; i++) {
    paramTypeConverters[i] = OpenTypeConverter.toConverter(params[i]);
    identity &= paramTypeConverters[i].isIdentity();
  }
  paramConversionIsIdentity = identity;
}
 
Example 56
Project: ChronoBike   File: CompositeTypeDesc.java   Source Code and License 5 votes vote down vote up
public CompositeType generateCompositeType()
{
	try
	{
		int nNbItems = m_arrItemDesc.size();
		OpenType [] openTypes = new OpenType [nNbItems];
		String [] itemTypeNames = new String [nNbItems];
		String [] itemTypeDescriptions = new String [nNbItems];
		for(int n=0; n<nNbItems; n++)
		{
			CompositeTypeDescItem itemDesc = m_arrItemDesc.get(n);
			openTypes[n] = itemDesc.m_openType;
			itemTypeNames[n] = itemDesc.m_csName;
			itemTypeDescriptions[n] = itemDesc.m_csDescription;			
		}
		
		CompositeType compositeType = new CompositeType(
			m_csName,
		    m_csDescription,
		    itemTypeNames,
		    itemTypeDescriptions,
		    openTypes);
		return compositeType;
	}
	catch (OpenDataException e)
	{
		e.printStackTrace();
	}
	return null;
}
 
Example 57
Project: openjdk-jdk10   File: TigerMXBean.java   Source Code and License 5 votes vote down vote up
static TabularType make(String typeName, String description,
                        CompositeType rowType, String[] indexNames) {
    try {
        return new TabularType(typeName, description, rowType,
                               indexNames);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example 58
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 5 votes vote down vote up
private MXBeanMapping
    makeArrayOrCollectionMapping(Type collectionType, Type elementType,
                                 MXBeanMappingFactory factory)
        throws OpenDataException {

    final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
    final OpenType<?> elementOpenType = elementMapping.getOpenType();
    final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
    final Class<?> elementOpenClass = elementMapping.getOpenClass();

    final Class<?> openArrayClass;
    final String openArrayClassName;
    if (elementOpenClass.isArray())
        openArrayClassName = "[" + elementOpenClass.getName();
    else
        openArrayClassName = "[L" + elementOpenClass.getName() + ";";
    try {
        openArrayClass = Class.forName(openArrayClassName);
    } catch (ClassNotFoundException e) {
        throw openDataException("Cannot obtain array class", e);
    }

    if (collectionType instanceof ParameterizedType) {
        return new CollectionMapping(collectionType,
                                     openType, openArrayClass,
                                     elementMapping);
    } else {
        if (isIdentity(elementMapping)) {
            return new IdentityMapping(collectionType,
                                       openType);
        } else {
            return new ArrayMapping(collectionType,
                                      openType,
                                      openArrayClass,
                                      elementMapping);
        }
    }
}
 
Example 59
Project: jdk8u-jdk   File: MonitorInfoCompositeData.java   Source Code and License 5 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // monitorInfoItemNames!

    int len = monitorInfoItemNames.length;
    Object[] values = new Object[len];
    CompositeData li = LockInfoCompositeData.toCompositeData(lock);

    for (int i = 0; i < len; i++) {
        String item = monitorInfoItemNames[i];
        if (item.equals(LOCKED_STACK_FRAME)) {
            StackTraceElement ste = lock.getLockedStackFrame();
            values[i] = (ste != null ? StackTraceElementCompositeData.
                                           toCompositeData(ste)
                                     : null);
        } else if (item.equals(LOCKED_STACK_DEPTH)) {
            values[i] = new Integer(lock.getLockedStackDepth());
        } else {
            values[i] = li.get(item);
        }
    }

    try {
        return new CompositeDataSupport(monitorInfoCompositeType,
                                        monitorInfoItemNames,
                                        values);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 60
Project: jdk8u-jdk   File: GcInfoCompositeData.java   Source Code and License 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageBeforeGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC);
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}