Search in sources :

Example 1 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class HeapDumpHandler method getHeapHistogram.

/**
     * Gets the heap histogram from target JVM.
     * <p>
     * e.g.
     * 
     * <pre>
     *  num     #instances         #bytes  class name
     * ----------------------------------------------
     *    1:         18329        2104376  &lt;constMethodKlass&gt;
     *    2:         18329        1479904  &lt;methodKlass&gt;
     *    3:          2518        1051520  [B
     *    4:         11664         989856  [C
     *    5:         11547         277128  java.lang.String
     * </pre>
     * 
     * @param virtualMachine The virtual machine
     * @param isLive True to dump only live objects
     * @return The heap histogram
     * @throws JvmCoreException
     */
private static String getHeapHistogram(Object virtualMachine, boolean isLive) throws JvmCoreException {
    InputStream in = Tools.getInstance().invokeHeapHisto(virtualMachine, isLive);
    byte[] bytes = new byte[BUFFER_SIZE];
    int length;
    StringBuilder builder = new StringBuilder();
    try {
        while ((length = in.read(bytes)) != -1) {
            String string = new String(bytes, 0, length, IConstants.UTF8);
            builder.append(string);
        }
    } catch (UnsupportedEncodingException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.charsetNotSupportedMsg, e);
    } catch (IOException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.readInputStreamFailedMsg, e);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
        // ignore
        }
    }
    return builder.toString();
}
Also used : InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 2 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class Tools method invokeFindByName.

/**
     * Invokes the findByName method of MonitoredVm with reflection.
     * 
     * @param monitoredVm The monitored VM
     * @param name The name
     * @return The monitor
     * @throws JvmCoreException
     */
protected Object invokeFindByName(Object monitoredVm, String name) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(MONITORED_VM_CLASS);
        Method method = clazz.getDeclaredMethod(FIND_BY_NAME_METHOD, new Class[] { String.class });
        return method.invoke(monitoredVm, name);
    } catch (Throwable t) {
        throw new JvmCoreException(IStatus.ERROR, t.getMessage(), t);
    }
}
Also used : Method(java.lang.reflect.Method) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 3 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class Tools method invokeDetach.

/**
     * Invokes the detach method of VirtualMachine with reflection.
     * 
     * @param vm The virtual machine
     * @throws JvmCoreException
     */
protected void invokeDetach(Object vm) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(VIRTUAL_MACHINE_CLASS);
        Method method = clazz.getDeclaredMethod(DETACH_METHOD);
        method.invoke(vm);
    } catch (Throwable t) {
        throw new JvmCoreException(IStatus.ERROR, t.getMessage(), t);
    }
}
Also used : Method(java.lang.reflect.Method) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 4 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class Tools method invokeGetValue.

/**
     * Invokes the getValue method of Monitor with reflection.
     * 
     * @param monitor The monitor
     * @return The value
     * @throws JvmCoreException
     */
protected Object invokeGetValue(Object monitor) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(MONITOR_CLASS);
        Method method = clazz.getDeclaredMethod(GET_VALUE_METHOD);
        return method.invoke(monitor);
    } catch (Throwable t) {
        throw new JvmCoreException(IStatus.ERROR, t.getMessage(), t);
    }
}
Also used : Method(java.lang.reflect.Method) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 5 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class Tools method invokeGetMonitoredVm.

/**
     * Invokes the getMonitoredVm of MonitoredHost with reflection.
     * 
     * @param monitoredHost The monitored host
     * @param vmIdentifier The VM identifier
     * @return The monitored VM
     * @throws JvmCoreException
     */
protected synchronized Object invokeGetMonitoredVm(Object monitoredHost, Object vmIdentifier) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(MONITORED_HOST_CLASS);
        Class<?> clazz2 = Class.forName(VM_IDENTIFIER_CLASS);
        Method method = clazz.getDeclaredMethod(GET_MONITORED_VM_METHOD, new Class[] { clazz2 });
        return method.invoke(monitoredHost, vmIdentifier);
    } catch (Throwable t) {
        throw new JvmCoreException(IStatus.ERROR, t.getMessage(), t);
    }
}
Also used : Method(java.lang.reflect.Method) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Aggregations

JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)64 IOException (java.io.IOException)16 IActiveJvm (org.talend.designer.runtime.visualization.IActiveJvm)14 Method (java.lang.reflect.Method)11 ObjectName (javax.management.ObjectName)10 IFileStore (org.eclipse.core.filesystem.IFileStore)6 CoreException (org.eclipse.core.runtime.CoreException)6 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)6 File (java.io.File)5 Properties (java.util.Properties)5 IPath (org.eclipse.core.runtime.IPath)5 OutputStream (java.io.OutputStream)4 JMException (javax.management.JMException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IHost (org.talend.designer.runtime.visualization.IHost)4 JvmModelEvent (org.talend.designer.runtime.visualization.JvmModelEvent)4 Date (java.util.Date)3 Timer (java.util.Timer)3 TimerTask (java.util.TimerTask)3 RGB (org.eclipse.swt.graphics.RGB)3