Search in sources :

Example 6 with JvmModelEvent

use of org.talend.designer.runtime.visualization.JvmModelEvent 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)

Example 7 with JvmModelEvent

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

the class Host method addActiveJvm.

/**
     * Adds the active JVM.
     * 
     * @param jvm The active JVM.
     * @return The active JVM
     */
protected IActiveJvm addActiveJvm(IActiveJvm jvm) {
    for (IActiveJvm activeJvm : activeJvms) {
        if (activeJvm.getPid() == jvm.getPid()) {
            return jvm;
        }
    }
    activeJvms.add(jvm);
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmAdded, jvm));
    return jvm;
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent)

Example 8 with JvmModelEvent

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

the class MBeanNotification method clear.

/*
     * @see IMBeanNotification#clear(ObjectName)
     */
@Override
public void clear(ObjectName objectName) {
    List<Notification> notification = notifications.get(objectName);
    if (notification == null) {
        return;
    }
    notification.clear();
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmModified, activeJvm));
}
Also used : JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Notification(javax.management.Notification) IMBeanNotification(org.talend.designer.runtime.visualization.MBean.IMBeanNotification)

Example 9 with JvmModelEvent

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

the class MBeanNotification method subscribe.

/*
     * @see IMBeanNotification#subscribe(ObjectName)
     */
@Override
public void subscribe(final ObjectName objectName) throws JvmCoreException {
    NotificationListener listener = new NotificationListener() {

        @Override
        public void handleNotification(Notification notification, Object handback) {
            List<Notification> list = notifications.get(objectName);
            if (list == null) {
                list = new ArrayList<Notification>();
            }
            list.add(new DecoratedNotification(notification));
            notifications.put(objectName, list);
        }
    };
    activeJvm.getMBeanServer().addNotificationListener(objectName, listener);
    listeners.put(objectName, listener);
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmModified, activeJvm));
}
Also used : JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Notification(javax.management.Notification) IMBeanNotification(org.talend.designer.runtime.visualization.MBean.IMBeanNotification) NotificationListener(javax.management.NotificationListener)

Example 10 with JvmModelEvent

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

the class ActiveJvm method disconnect.

/*
     * @see IActiveJvm#disconnect()
     */
@Override
public void disconnect() {
    isConnected = false;
    mBeanServer.dispose();
    try {
        if (swtResourceMonitor.isSupported()) {
            swtResourceMonitor.setTracking(false);
        }
    } catch (JvmCoreException e) {
    // do nothing
    }
    JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmDisconnected, this));
}
Also used : JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

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