Search in sources :

Example 41 with JvmCoreException

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

the class Host method refreshSnapshots.

/**
     * Refreshes the snapshots.
     */
private void refreshSnapshots() {
    IPath hostDir;
    try {
        hostDir = getHostDir();
    } catch (JvmCoreException e) {
        // do nothing
        return;
    }
    File[] files = hostDir.toFile().listFiles();
    if (files == null) {
        return;
    }
    for (File file : files) {
        if (!file.isDirectory()) {
            continue;
        }
        String jvmDir = file.getName();
        if (!jvmDir.endsWith(IJvm.DIR_SUFFIX)) {
            continue;
        }
        IPath filePath = hostDir.append(File.separator + jvmDir + File.separator + IJvm.PROPERTIES_FILE);
        if (!filePath.toFile().exists() || file.list().length == 1) {
            Util.deleteDir(file);
            continue;
        }
        Properties props = Util.loadProperties(filePath);
        if (props == null) {
            Util.deleteDir(file);
            continue;
        }
        String host = props.getProperty(IJvm.HOST_PROP_KEY);
        if (!hostName.equals(host)) {
            Util.deleteDir(file);
            continue;
        }
        String pidString = props.getProperty(IJvm.PID_PROP_KEY);
        int pid = (pidString == null) ? -1 : Integer.valueOf(pidString);
        String portString = props.getProperty(IJvm.PORT_PROP_KEY);
        int port = (portString == null) ? -1 : Integer.valueOf(portString);
        String mainClass = props.getProperty(IJvm.MAIN_CLASS_PROP_KEY);
        addTerminatedJvm(pid, port, mainClass);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Properties(java.util.Properties) File(java.io.File) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 42 with JvmCoreException

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

the class MBeanNotification method isSupported.

/*
     * @see IMBeanNotification#isSupported(javax.management.ObjectName)
     */
@Override
public boolean isSupported(ObjectName objectName) {
    MBeanInfo info = null;
    try {
        info = activeJvm.getMBeanServer().getMBeanInfo(objectName);
    } catch (JvmCoreException e) {
        return false;
    }
    if (info == null) {
        return false;
    }
    MBeanNotificationInfo[] notificationInfoArray = info.getNotifications();
    if (notificationInfoArray == null || notificationInfoArray.length == 0) {
        return false;
    }
    return true;
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 43 with JvmCoreException

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

the class ActiveJvm method refreshHost.

/**
     * Refreshes the host.
     * 
     * @return True if JVM has been added to host
     * @throws JvmCoreException
     */
private boolean refreshHost() throws JvmCoreException {
    //$NON-NLS-1$
    String[] elements = mBeanServer.getRuntimeName().split("@");
    if (elements == null || elements.length != 2) {
        throw new JvmCoreException(IStatus.ERROR, Messages.getHostNameFailedMsg, new Exception());
    }
    String hostName = elements[1];
    Host host = (Host) JvmModel.getInstance().getHost(hostName);
    if (host == null) {
        host = new Host(hostName);
    } else {
        for (IJvm jvm : host.getActiveJvms()) {
            if (jvm.getPid() == getPid()) {
                return false;
            }
        }
    }
    host.addActiveJvm(this);
    setHost(host);
    return true;
}
Also used : IHost(org.talend.designer.runtime.visualization.IHost) IJvm(org.talend.designer.runtime.visualization.IJvm) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 44 with JvmCoreException

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

Example 45 with JvmCoreException

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

the class Host method removeJvm.

/*
     * @see IHost#removeJvm(int)
     */
@Override
public void removeJvm(int pid) {
    IPath hostDir = null;
    try {
        hostDir = getHostDir();
    } catch (JvmCoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.removeJvmFailedMsg, +pid), e);
        return;
    }
    for (ITerminatedJvm jvm : terminatedJvms) {
        if (jvm.getPid() == pid) {
            terminatedJvms.remove(jvm);
            int id = (jvm.getPid() != -1) ? jvm.getPid() : jvm.getPort();
            IPath dirPath = hostDir.append(File.separator + id + IJvm.DIR_SUFFIX);
            Util.deleteDir(dirPath.toFile());
            JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmRemoved, null));
            break;
        }
    }
    for (IActiveJvm jvm : activeJvms) {
        if (jvm.getPid() == pid) {
            if (jvm.isConnected()) {
                jvm.disconnect();
            }
            if (jvm.getShapshots().size() > 0) {
                addTerminatedJvm(jvm.getPid(), -1, jvm.getMainClass());
            } else {
                int id = (jvm.getPid() != -1) ? jvm.getPid() : jvm.getPort();
                IPath dirPath = hostDir.append(File.separator + id + IJvm.DIR_SUFFIX);
                Util.deleteDir(dirPath.toFile());
            }
            activeJvms.remove(jvm);
            JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.JvmRemoved, null));
            break;
        }
    }
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) IPath(org.eclipse.core.runtime.IPath) ITerminatedJvm(org.talend.designer.runtime.visualization.ITerminatedJvm) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) 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