Search in sources :

Example 1 with JvmModelEvent

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

the class MBeanServer method dump.

/**
     * Dumps the profile data into file.
     * 
     * @param type The snapshot type
     * @param dumpFileName The dump file name
     * @param monitor The progress monitor
     * @return The file store
     * @throws JvmCoreException
     */
private IFileStore dump(SnapshotType type, String dumpFileName, IProgressMonitor monitor) throws JvmCoreException {
    String simpleFileName;
    if (dumpFileName == null) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(new Date().getTime()).append('.').append(type.getExtension());
        simpleFileName = stringBuffer.toString();
    } else {
        simpleFileName = new File(dumpFileName).getName();
    }
    IFileStore fileStore = Util.getFileStore(simpleFileName, 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 {
        if (type == SnapshotType.Heap || type == SnapshotType.Thread) {
            String dump = getDumpString(type);
            os = fileStore.openOutputStream(EFS.NONE, null);
            os.write(dump.getBytes());
        } else if (type == SnapshotType.Hprof && jvm.isRemote()) {
            ObjectName objectName = getObjectName(DATA_TRANSFER_MXBEAN_NAME);
            os = fileStore.openOutputStream(EFS.NONE, null);
            byte[] bytes;
            int offset = 0;
            final int SIZE = 4096;
            //$NON-NLS-1$ //$NON-NLS-2$
            final String[] SIGNATURES = new String[] { String.class.getCanonicalName(), "int", "int" };
            do {
                bytes = (byte[]) invoke(objectName, "read", new Object[] { //$NON-NLS-1$
                dumpFileName, offset, SIZE }, SIGNATURES);
                os.write(bytes);
                offset += SIZE;
                if (monitor != null && monitor.isCanceled()) {
                    break;
                }
            } while (bytes.length > 0);
        }
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, abstractJvm, 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.dumpFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : OutputStream(java.io.OutputStream) IHost(org.talend.designer.runtime.visualization.IHost) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) ObjectName(javax.management.ObjectName) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File)

Example 2 with JvmModelEvent

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

the class MBeanServer method refresh.

/**
     * Refreshes the MBean model.
     * 
     * @throws JvmCoreException
     */
protected void refresh() throws JvmCoreException {
    if (!checkReachability()) {
        return;
    }
    for (IMonitoredMXBeanGroup group : monitoredAttributeGroups) {
        for (IMonitoredMXBeanAttribute attribute : group.getAttributes()) {
            String attributeName = attribute.getAttributeName();
            Object attributeObject = getAttribute(attribute.getObjectName(), attributeName);
            Number value = getAttributeValue(attributeObject, attributeName);
            if (value == null) {
                continue;
            }
            // exceptional handling for process CPU time
            if (MonitorAttributeName.CPU_TIME.equals(attribute.getAttributeName())) {
                if (previousProcessCpuTime == 0) {
                    previousProcessCpuTime = (Long) value;
                    continue;
                }
                Double percent = ((Long) value - previousProcessCpuTime) / 1000000000d;
                previousProcessCpuTime = (Long) value;
                value = percent > 1 ? 1 : percent;
            }
            ((MonitoredMXBeanAttribute) attribute).add(value, new Date());
        }
    }
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmModified, jvm));
}
Also used : IMonitoredMXBeanGroup(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup) IMonitoredMXBeanAttribute(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanAttribute) IMonitoredMXBeanAttribute(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanAttribute) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date)

Example 3 with JvmModelEvent

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

the class RefreshAction method run.

/*
     * @see Action#run()
     */
@Override
public void run() {
    boolean isChecked = isChecked();
    section.suspendRefresh(!isChecked);
    if (isChecked) {
        section.jvmModelChanged(new JvmModelEvent(State.JvmModified, section.getJvm()));
    }
}
Also used : JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent)

Example 4 with JvmModelEvent

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

the class AbstractJvm method deleteSnapshot.

/*
     * @see IJvm#deleteSnapshot(ISnapshot)
     */
@Override
public void deleteSnapshot(ISnapshot snapshot) {
    snapshots.remove(snapshot);
    try {
        snapshot.getFileStore().delete(EFS.NONE, null);
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.deleteFileFailedMsg, snapshot.getFileStore().getName()), e);
    }
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotRemoved, this));
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent)

Example 5 with JvmModelEvent

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

the class CpuProfiler method setProfiledPackages.

/*
     * @see ICpuProfiler#setProfiledPackages(Set<String>)
     */
@Override
public void setProfiledPackages(Set<String> packages) throws JvmCoreException {
    if (type == ProfilerType.BCI) {
        validateAgent();
        ProfilerState state = getState();
        if (state != ProfilerState.READY && state != ProfilerState.RUNNING) {
            return;
        }
        StringBuffer buffer = new StringBuffer();
        for (String item : packages) {
            if (buffer.length() > 0) {
                buffer.append(',');
            }
            buffer.append(item);
        }
        invokeCpuProfilerMXBeanMethod(SET_FILTER, new String[] { PROFILED_PACKAGES_PROP_KEY, buffer.toString() }, new String[] { String.class.getName(), String.class.getName() });
    } else {
        this.profiledPackages = packages;
    }
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.CpuProfilerConfigChanged, jvm));
}
Also used : JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent)

Aggregations

JvmModelEvent (org.talend.designer.runtime.visualization.JvmModelEvent)13 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)5 Date (java.util.Date)3 CoreException (org.eclipse.core.runtime.CoreException)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Notification (javax.management.Notification)2 NotificationListener (javax.management.NotificationListener)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IActiveJvm (org.talend.designer.runtime.visualization.IActiveJvm)2 IMBeanNotification (org.talend.designer.runtime.visualization.MBean.IMBeanNotification)2 File (java.io.File)1 ObjectName (javax.management.ObjectName)1 IPath (org.eclipse.core.runtime.IPath)1 IHost (org.talend.designer.runtime.visualization.IHost)1 ITerminatedJvm (org.talend.designer.runtime.visualization.ITerminatedJvm)1 IMonitoredMXBeanAttribute (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanAttribute)1 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)1 AbstractJvm (org.talend.designer.runtime.visualization.internal.core.AbstractJvm)1 Host (org.talend.designer.runtime.visualization.internal.core.Host)1