Search in sources :

Example 6 with JvmCoreException

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

the class Tools method invokeGetSystemProperties.

/**
     * Invokes the getSystemProperties method of VirtualMachine with reflection.
     * 
     * @param vm The virtual machine
     * @return The system properties
     * @throws JvmCoreException
     */
protected Object invokeGetSystemProperties(Object vm) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(VIRTUAL_MACHINE_CLASS);
        Method method = clazz.getDeclaredMethod(GET_SYSTEM_PROPERTIES_METHOD);
        return 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 7 with JvmCoreException

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

the class Tools method invokeGetAgentProperties.

/**
     * Invokes the getAgentProperties method of VirtualMachine
     * 
     * @param virtualMachine The virtual machine
     * @return The agent properties
     * @throws JvmCoreException
     */
protected Properties invokeGetAgentProperties(Object virtualMachine) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(VIRTUAL_MACHINE_CLASS);
        Method method = clazz.getDeclaredMethod(GET_AGENT_PROPERTIES_METHOD);
        return (Properties) method.invoke(virtualMachine);
    } catch (Throwable t) {
        throw new JvmCoreException(IStatus.ERROR, t.getMessage(), t);
    }
}
Also used : Method(java.lang.reflect.Method) Properties(java.util.Properties) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 8 with JvmCoreException

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

the class Tools method invokeLoadAgent.

/**
     * Invokes the loadAgent method of VirtualMachine with reflection.
     * 
     * @param virtualMachine The virtual machine
     * @param path The path for agent jar file
     * @param options The options given to agent
     * @throws JvmCoreException
     */
protected void invokeLoadAgent(Object virtualMachine, String path, String options) throws JvmCoreException {
    try {
        Class<?> clazz = Class.forName(VIRTUAL_MACHINE_CLASS);
        Method method = clazz.getDeclaredMethod(LOAD_AGENT_METHOD, new Class[] { String.class, String.class });
        method.invoke(virtualMachine, path, options);
    } catch (Throwable t) {
        String message = t.getMessage();
        if (message == null) {
            Throwable cause = t.getCause();
            while (cause != null) {
                message = cause.getMessage();
                if (message != null) {
                    break;
                }
                cause = cause.getCause();
            }
        }
        throw new JvmCoreException(IStatus.ERROR, message, t);
    }
}
Also used : Method(java.lang.reflect.Method) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 9 with JvmCoreException

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

the class CpuProfiler method refreshBciProfileCache.

/*
     * @see ICpuProfiler#refreshBciProfileCache(IProgressMonitor)
     */
@Override
public void refreshBciProfileCache(IProgressMonitor monitor) throws JvmCoreException {
    if (type != ProfilerType.BCI) {
        return;
    }
    validateAgent();
    if (!isBciProfilerRunning()) {
        return;
    }
    String dumpString = (String) invokeCpuProfilerMXBeanMethod(DUMP, null, null);
    if (dumpString == null) {
        return;
    }
    ByteArrayInputStream input = null;
    try {
        input = new ByteArrayInputStream(dumpString.getBytes());
        CpuDumpParser parser = new CpuDumpParser(input, cpuModel, monitor);
        parser.parse();
    } catch (ParserConfigurationException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
    } catch (SAXException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
    } catch (IOException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : CpuDumpParser(org.talend.designer.runtime.visualization.core.dump.CpuDumpParser) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) SAXException(org.xml.sax.SAXException)

Example 10 with JvmCoreException

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

the class CpuProfiler method dump.

/*
     * @see ICpuProfiler#dump()
     */
@Override
public IFileStore dump() throws JvmCoreException {
    String dump = cpuModel.getCpuDumpString(//$NON-NLS-1$
    jvm.getPid() + "@" + jvm.getHost().getName(), jvm.getMainClass(), jvm.getMBeanServer().getJvmArguments());
    StringBuffer fileName = new StringBuffer();
    fileName.append(new Date().getTime()).append('.').append(SnapshotType.Cpu.getExtension());
    IFileStore fileStore = Util.getFileStore(fileName.toString(), jvm.getBaseDirectory());
    // restore the terminated JVM if already removed
    AbstractJvm abstractJvm = jvm;
    if (!((Host) jvm.getHost()).getJvms().contains(jvm)) {
        jvm.saveJvmProperties();
        abstractJvm = (AbstractJvm) ((Host) jvm.getHost()).addTerminatedJvm(jvm.getPid(), jvm.getPort(), jvm.getMainClass());
    }
    OutputStream os = null;
    try {
        os = fileStore.openOutputStream(EFS.NONE, null);
        os.write(dump.getBytes());
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, jvm, snapshot));
    } catch (CoreException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.dumpCpuProfileDataFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : Snapshot(org.talend.designer.runtime.visualization.internal.core.Snapshot) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) AbstractJvm(org.talend.designer.runtime.visualization.internal.core.AbstractJvm) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) Host(org.talend.designer.runtime.visualization.internal.core.Host) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) 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