Search in sources :

Example 26 with JvmCoreException

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

the class MBeanServer method getAttribute.

/*
     * @see IMBeanServer#getAttribute(ObjectName, String)
     */
@Override
public Object getAttribute(ObjectName objectName, String qualifiedAttributeName) throws JvmCoreException {
    Assert.isNotNull(objectName);
    Assert.isNotNull(qualifiedAttributeName);
    if (!checkReachability()) {
        return null;
    }
    String attributeName = qualifiedAttributeName;
    if (attributeName.contains(".")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        attributeName = attributeName.split("\\.")[0];
    }
    try {
        return connection.getAttribute(objectName, attributeName);
    } catch (JMException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getAttributeFailedMsg, attributeName), e);
    } catch (IOException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getAttributeFailedMsg, attributeName), e);
    }
}
Also used : JMException(javax.management.JMException) IOException(java.io.IOException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 27 with JvmCoreException

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

the class MBeanServer method dumpHprof.

/*
     * @see IMBeanServer#dumpHprof(String, boolean, IProgressMonitor)
     */
@Override
public IFileStore dumpHprof(String hprofFileName, boolean transfer, IProgressMonitor monitor) throws JvmCoreException {
    if (!checkReachability()) {
        throw new JvmCoreException(IStatus.WARNING, Messages.jvmNotReachableMsg, null);
    }
    IFileStore fileStore = null;
    String fileName;
    if (jvm.isRemote()) {
        fileName = hprofFileName;
    } else {
        fileStore = dump(SnapshotType.Hprof, null, null);
        fileName = fileStore.toString();
    }
    if (monitor.isCanceled()) {
        return null;
    }
    //$NON-NLS-1$
    ObjectName objectName = jvm.getMBeanServer().getObjectName("com.sun.management:type=HotSpotDiagnostic");
    invoke(//$NON-NLS-1$
    objectName, //$NON-NLS-1$
    "dumpHeap", //$NON-NLS-1$
    new Object[] { fileName, Boolean.TRUE }, //$NON-NLS-1$
    new String[] { String.class.getCanonicalName(), "boolean" });
    if (jvm.isRemote() && transfer) {
        fileStore = dump(SnapshotType.Hprof, hprofFileName, monitor);
    }
    return fileStore;
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) ObjectName(javax.management.ObjectName)

Example 28 with JvmCoreException

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

the class MBeanServer method refreshThreadCache.

/*
     * @see IMBeanServer#refreshThreadCache()
     */
@Override
public void refreshThreadCache() throws JvmCoreException {
    if (!checkReachability()) {
        return;
    }
    ThreadMXBean threadMXBean;
    try {
        threadMXBean = (ThreadMXBean) getMXBean(ThreadMXBean.class, ManagementFactory.THREAD_MXBEAN_NAME);
    } catch (IOException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), e);
    }
    if (threadMXBean == null) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), null);
    }
    long[] ids = threadMXBean.findDeadlockedThreads();
    LinkedHashMap<String, ThreadElement> newThreadListElements = new LinkedHashMap<String, ThreadElement>();
    List<ThreadInfo> allThreads = Arrays.asList(threadMXBean.dumpAllThreads(true, false));
    Collections.reverse(allThreads);
    for (ThreadInfo threadInfo : allThreads) {
        String threadName = threadInfo.getThreadName();
        long threadId = threadInfo.getThreadId();
        if (//$NON-NLS-1$
        threadInfo.getStackTrace().length == 0 || threadName.startsWith("RMI ") || threadName.startsWith("JMX ")) {
            //$NON-NLS-1$
            continue;
        }
        boolean isDeadlocked = false;
        if (ids != null) {
            Arrays.sort(ids);
            if (Arrays.binarySearch(ids, threadId) >= 0) {
                isDeadlocked = true;
            }
        }
        ThreadElement oldElement = threadListElements.get(threadName);
        long processCpuTime = threadMXBean.getThreadCpuTime(threadId);
        Long previousCpuTime = previousThreadProcessCpuTime.get(threadId);
        double cpuUsage = 0;
        previousThreadProcessCpuTime.put(threadId, processCpuTime);
        if (previousCpuTime != null) {
            cpuUsage = Math.min((processCpuTime - previousCpuTime) / 10000000d, 100);
        }
        previousThreadProcessCpuTime.put(threadId, processCpuTime);
        if (oldElement == null) {
            newThreadListElements.put(threadName, new ThreadElement(threadInfo, isDeadlocked, cpuUsage));
        } else {
            oldElement.setThreadInfo(threadInfo);
            oldElement.setDeadlocked(isDeadlocked);
            oldElement.setCpuUsage(cpuUsage);
            newThreadListElements.put(threadName, oldElement);
        }
    }
    threadListElements = newThreadListElements;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) IOException(java.io.IOException) IThreadElement(org.talend.designer.runtime.visualization.IThreadElement) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) LinkedHashMap(java.util.LinkedHashMap) ThreadInfo(java.lang.management.ThreadInfo)

Example 29 with JvmCoreException

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

the class MBeanServer method resumeSampling.

/**
     * Resumes the sampling.
     */
public void resumeSampling() {
    if (samplingTimer != null) {
        samplingTimer.cancel();
    }
    samplingTimer = new Timer(true);
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            try {
                sampleProfilingData();
            } catch (JvmCoreException e) {
                Activator.log(IStatus.ERROR, e.getMessage(), e);
                suspendSampling();
            } catch (Throwable t) {
                suspendSampling();
            }
        }
    };
    samplingTimer.schedule(timerTask, 0, samplingPeriod);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 30 with JvmCoreException

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

the class ActiveJvm method saveJvmProperties.

/**
     * Saves the JVM properties.
     */
public void saveJvmProperties() {
    IFileStore fileStore;
    try {
        fileStore = Util.getFileStore(IJvm.PROPERTIES_FILE, getBaseDirectory());
        if (fileStore.fetchInfo().exists()) {
            return;
        }
    } catch (JvmCoreException e) {
        Activator.log(IStatus.ERROR, Messages.savePropertiesFileFailedMsg, e);
        return;
    }
    Properties props = new Properties();
    OutputStream os = null;
    try {
        os = fileStore.openOutputStream(EFS.NONE, null);
        int pid = getPid();
        int port = getPort();
        String mainClass = getMainClass();
        props.setProperty(IJvm.PID_PROP_KEY, String.valueOf(pid));
        props.setProperty(IJvm.PORT_PROP_KEY, String.valueOf(port));
        if (mainClass != null) {
            props.setProperty(IJvm.MAIN_CLASS_PROP_KEY, mainClass);
        }
        props.setProperty(IJvm.HOST_PROP_KEY, getHost().getName());
        //$NON-NLS-1$
        props.storeToXML(os, "JVM Properties");
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        Activator.log(IStatus.ERROR, NLS.bind(Messages.writePropertiesFileFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Properties(java.util.Properties) 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