com-sun-tools-visualvm-threaddump

16:34:03.751 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-threaddump.jar
package com.sun.tools.visualvm.threaddump;

import org.openide.modules.ModuleInstall;

class Installer
  extends ModuleInstall
{
  public void restored()
  {
    ThreadDumpSupport.getInstance();
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.Installer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import com.sun.tools.visualvm.core.snapshot.SnapshotsSupport;
import java.io.File;
import org.openide.util.NbBundle;

public abstract class ThreadDump
  extends Snapshot
{
  public ThreadDump(File file)
  {
    this(file, null);
  }
  
  public ThreadDump(File file, DataSource master)
  {
    super(file, ThreadDumpSupport.getInstance().getCategory(), master);
  }
  
  public boolean supportsSaveAs()
  {
    return true;
  }
  
  public void saveAs()
  {
    SnapshotsSupport.getInstance().saveAs(this, NbBundle.getMessage(ThreadDump.class, "MSG_Save_Thread_Dump_As"));
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.ThreadDump
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump;

import com.sun.tools.visualvm.core.snapshot.SnapshotDescriptor;
import com.sun.tools.visualvm.core.snapshot.SnapshotsSupport;
import java.awt.Image;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;

public class ThreadDumpDescriptor
  extends SnapshotDescriptor<ThreadDump>
{
  private static final Image ICON = SnapshotsSupport.getInstance().createSnapshotIcon(ImageUtilities.loadImage("com/sun/tools/visualvm/threaddump/resources/threaddumpBase.png", true));
  
  public ThreadDumpDescriptor(ThreadDump threadDump)
  {
    super(threadDump, NbBundle.getMessage(ThreadDumpDescriptor.class, "DESCR_ThreadDump"), ICON);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.ThreadDumpDescriptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.snapshot.RegisteredSnapshotCategories;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.PluggableDataSourceViewProvider;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.threaddump.impl.ThreadDumpCategory;
import com.sun.tools.visualvm.threaddump.impl.ThreadDumpDescriptorProvider;
import com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider;
import com.sun.tools.visualvm.threaddump.impl.ThreadDumpViewProvider;

public final class ThreadDumpSupport
{
  private static ThreadDumpSupport instance;
  private final SnapshotCategory category = new ThreadDumpCategory();
  private final ThreadDumpProvider threadDumpProvider;
  private final ThreadDumpViewProvider threadDumpViewProvider;
  
  public static synchronized ThreadDumpSupport getInstance()
  {
    if (instance == null) {
      instance = new ThreadDumpSupport();
    }
    return instance;
  }
  
  public SnapshotCategory getCategory()
  {
    return category;
  }
  
  public boolean supportsThreadDump(Application application)
  {
    if (application.getState() != 1) {
      return false;
    }
    return JvmFactory.getJVMFor(application).isTakeThreadDumpSupported();
  }
  
  public void takeThreadDump(Application application, boolean openView)
  {
    threadDumpProvider.createThreadDump(application, openView);
  }
  
  public void takeThreadDump(CoreDump coreDump, boolean openView)
  {
    threadDumpProvider.createThreadDump(coreDump, openView);
  }
  
  public PluggableDataSourceViewProvider<ThreadDump> getThreadDumpView()
  {
    return threadDumpViewProvider;
  }
  
  private ThreadDumpSupport()
  {
    DataSourceDescriptorFactory.getDefault().registerProvider(new ThreadDumpDescriptorProvider());
    threadDumpProvider = new ThreadDumpProvider();
    threadDumpProvider.initialize();
    
    threadDumpViewProvider = new ThreadDumpViewProvider();
    
    RegisteredSnapshotCategories.sharedInstance().registerCategory(category);
    
    threadDumpViewProvider.initialize();
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.ThreadDumpSupport
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

class ThreadDumpAction$1
  implements PropertyChangeListener
{
  ThreadDumpAction$1(ThreadDumpAction paramThreadDumpAction) {}
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    this$0.updateState(ActionUtils.getSelectedDataSources());
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpAction.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.ui.actions.ActionUtils;
import com.sun.tools.visualvm.core.ui.actions.MultiDataSourceAction;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.threaddump.ThreadDumpSupport;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
import java.util.Set;
import org.openide.util.NbBundle;

class ThreadDumpAction
  extends MultiDataSourceAction<DataSource>
{
  private Set<Application> lastSelectedApplications = new HashSet();
  private final PropertyChangeListener stateListener = new PropertyChangeListener()
  {
    public void propertyChange(PropertyChangeEvent evt)
    {
      updateState(ActionUtils.getSelectedDataSources());
    }
  };
  private static ThreadDumpAction instance;
  
  public static synchronized ThreadDumpAction instance()
  {
    if (instance == null) {
      instance = new ThreadDumpAction();
    }
    return instance;
  }
  
  protected void actionPerformed(Set<DataSource> dataSources, ActionEvent actionEvent)
  {
    for (DataSource dataSource : dataSources) {
      if ((dataSource instanceof Application))
      {
        Application application = (Application)dataSource;
        ThreadDumpSupport.getInstance().takeThreadDump(application, (actionEvent.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) == 0);
      }
      else if ((dataSource instanceof CoreDump))
      {
        CoreDump coreDump = (CoreDump)dataSource;
        ThreadDumpSupport.getInstance().takeThreadDump(coreDump, (actionEvent.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) == 0);
      }
    }
  }
  
  protected boolean isEnabled(Set<DataSource> dataSources)
  {
    for (DataSource dataSource : dataSources) {
      if ((dataSource instanceof Application))
      {
        Application application = (Application)dataSource;
        lastSelectedApplications.add(application);
        application.addPropertyChangeListener("prop_state", stateListener);
        if (application.getState() != 1) {
          return false;
        }
        if (!ThreadDumpSupport.getInstance().supportsThreadDump((Application)dataSource)) {
          return false;
        }
      }
      else if (!(dataSource instanceof CoreDump))
      {
        return false;
      }
    }
    return true;
  }
  
  protected void updateState(Set<DataSource> dataSources)
  {
    if (!lastSelectedApplications.isEmpty()) {
      for (Application application : lastSelectedApplications) {
        application.removePropertyChangeListener("prop_state", stateListener);
      }
    }
    lastSelectedApplications.clear();
    super.updateState(dataSources);
  }
  
  private ThreadDumpAction()
  {
    super(DataSource.class);
    putValue("Name", NbBundle.getMessage(ThreadDumpAction.class, "MSG_Thread_Dump"));
    putValue("ShortDescription", NbBundle.getMessage(ThreadDumpAction.class, "LBL_Thread_Dump"));
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpAction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.threaddump.ThreadDump;
import java.io.File;
import org.openide.util.NbBundle;

public class ThreadDumpCategory
  extends SnapshotCategory<ThreadDump>
{
  private static final String NAME = NbBundle.getMessage(ThreadDumpCategory.class, "MSG_Thread_Dumps");
  private static final String PREFIX = "threaddump";
  private static final String SUFFIX = ".tdump";
  
  public ThreadDumpCategory()
  {
    super(NAME, ThreadDump.class, "threaddump", ".tdump", 10);
  }
  
  public boolean supportsOpenSnapshot()
  {
    return true;
  }
  
  public void openSnapshot(File file)
  {
    DataSourceWindowManager.sharedInstance().openDataSource(new ThreadDumpImpl(file, null));
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpCategory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.model.AbstractModelProvider;
import com.sun.tools.visualvm.threaddump.ThreadDump;
import com.sun.tools.visualvm.threaddump.ThreadDumpDescriptor;

public class ThreadDumpDescriptorProvider
  extends AbstractModelProvider<DataSourceDescriptor, DataSource>
{
  public DataSourceDescriptor createModelFor(DataSource ds)
  {
    if ((ds instanceof ThreadDump)) {
      return new ThreadDumpDescriptor((ThreadDump)ds);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpDescriptorProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.datasource.DataSource;
import com.sun.tools.visualvm.threaddump.ThreadDump;
import java.io.File;

final class ThreadDumpImpl
  extends ThreadDump
{
  ThreadDumpImpl(File file, DataSource master)
  {
    super(file, master);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpImpl
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;

class ThreadDumpProvider$1$1
  implements Runnable
{
  ThreadDumpProvider$1$1(ThreadDumpProvider.1 param1, ThreadDumpImpl paramThreadDumpImpl) {}
  
  public void run()
  {
    DataSourceWindowManager.sharedInstance().openDataSource(val$threadDump);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.1.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import org.netbeans.api.progress.ProgressHandle;

class ThreadDumpProvider$1$2
  implements Runnable
{
  ThreadDumpProvider$1$2(ThreadDumpProvider.1 param1, ProgressHandle paramProgressHandle) {}
  
  public void run()
  {
    if (val$pHandleF != null) {
      val$pHandleF.finish();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.1.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import java.io.IOException;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor.Message;
import org.openide.util.NbBundle;

class ThreadDumpProvider$1
  implements Runnable
{
  ThreadDumpProvider$1(ThreadDumpProvider paramThreadDumpProvider, Application paramApplication, boolean paramBoolean) {}
  
  public void run()
  {
    Jvm jvm = JvmFactory.getJVMFor(val$application);
    if (!jvm.isTakeThreadDumpSupported())
    {
      DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Cannot_take_thread_dump_for_") + DataSourceDescriptorFactory.getDescriptor(val$application).getName(), 0));
      
      return;
    }
    ProgressHandle pHandle = null;
    try
    {
      pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Creating_Thread_Dump"));
      pHandle.setInitialDelay(0);
      pHandle.start();
      try
      {
        final ThreadDumpImpl threadDump = new ThreadDumpImpl(jvm.takeThreadDump(), val$application);
        val$application.getRepository().addDataSource(threadDump);
        if (val$openView) {
          SwingUtilities.invokeLater(new Runnable()
          {
            public void run()
            {
              DataSourceWindowManager.sharedInstance().openDataSource(threadDump);
            }
          });
        }
      }
      catch (IOException ex)
      {
        ErrorManager.getDefault().notify(ex);
      }
    }
    finally
    {
      final ProgressHandle pHandleF;
      ProgressHandle pHandleF = pHandle;
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          if (pHandleF != null) {
            pHandleF.finish();
          }
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;

class ThreadDumpProvider$2$1
  implements Runnable
{
  ThreadDumpProvider$2$1(ThreadDumpProvider.2 param2, ThreadDumpImpl paramThreadDumpImpl) {}
  
  public void run()
  {
    DataSourceWindowManager.sharedInstance().openDataSource(val$threadDump);
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.2.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import org.netbeans.api.progress.ProgressHandle;

class ThreadDumpProvider$2$2
  implements Runnable
{
  ThreadDumpProvider$2$2(ThreadDumpProvider.2 param2, ProgressHandle paramProgressHandle) {}
  
  public void run()
  {
    if (val$pHandleF != null) {
      val$pHandleF.finish();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.2.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.threaddump.ThreadDumpSupport;
import com.sun.tools.visualvm.tools.sa.SaModel;
import com.sun.tools.visualvm.tools.sa.SaModelFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;

class ThreadDumpProvider$2
  implements Runnable
{
  ThreadDumpProvider$2(ThreadDumpProvider paramThreadDumpProvider, CoreDump paramCoreDump, boolean paramBoolean) {}
  
  public void run()
  {
    ProgressHandle pHandle = null;
    try
    {
      pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Creating_Thread_Dump"));
      pHandle.setInitialDelay(0);
      pHandle.start();
      File snapshotDir = val$coreDump.getStorage().getDirectory();
      String name = ThreadDumpSupport.getInstance().getCategory().createFileName();
      File dumpFile = new File(snapshotDir, name);
      SaModel saAget = SaModelFactory.getSAAgentFor(val$coreDump);
      String dump = saAget.takeThreadDump();
      if (dump != null) {
        try
        {
          OutputStream os = new FileOutputStream(dumpFile);
          os.write(dump.getBytes("UTF-8"));
          os.close();
          final ThreadDumpImpl threadDump = new ThreadDumpImpl(dumpFile, val$coreDump);
          val$coreDump.getRepository().addDataSource(threadDump);
          if (val$openView) {
            SwingUtilities.invokeLater(new Runnable()
            {
              public void run()
              {
                DataSourceWindowManager.sharedInstance().openDataSource(threadDump);
              }
            });
          }
        }
        catch (Exception ex)
        {
          ErrorManager.getDefault().notify(ex);
        }
      }
    }
    finally
    {
      final ProgressHandle pHandleF;
      ProgressHandle pHandleF = pHandle;
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          if (pHandleF != null) {
            pHandleF.finish();
          }
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.application.Application;
import java.util.Iterator;
import java.util.Set;

class ThreadDumpProvider$ApplicationListener$1
  implements Runnable
{
  ThreadDumpProvider$ApplicationListener$1(ThreadDumpProvider.ApplicationListener paramApplicationListener, Set paramSet) {}
  
  public void run()
  {
    Application application;
    for (Iterator i$ = val$applications.iterator(); i$.hasNext(); ThreadDumpProvider.access$300(this$1.this$0, application)) {
      application = (Application)i$.next();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.ApplicationListener.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import java.util.Iterator;
import java.util.Set;
import org.openide.util.RequestProcessor;

class ThreadDumpProvider$ApplicationListener
  implements DataChangeListener<Application>
{
  private ThreadDumpProvider$ApplicationListener(ThreadDumpProvider paramThreadDumpProvider) {}
  
  public void dataChanged(DataChangeEvent<Application> event)
  {
    final Set<Application> applications = event.getAdded();
    if (!applications.isEmpty()) {
      RequestProcessor.getDefault().post(new Runnable()
      {
        public void run()
        {
          Application application;
          for (Iterator i$ = applications.iterator(); i$.hasNext(); ThreadDumpProvider.access$300(this$0, application)) {
            application = (Application)i$.next();
          }
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.ApplicationListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.snapshot.Snapshot;
import java.util.Iterator;
import java.util.Set;

class ThreadDumpProvider$SnapshotListener$1
  implements Runnable
{
  ThreadDumpProvider$SnapshotListener$1(ThreadDumpProvider.SnapshotListener paramSnapshotListener, Set paramSet) {}
  
  public void run()
  {
    Snapshot snapshot;
    for (Iterator i$ = val$snapshots.iterator(); i$.hasNext(); ThreadDumpProvider.access$200(this$1.this$0, snapshot)) {
      snapshot = (Snapshot)i$.next();
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.SnapshotListener.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import java.util.Iterator;
import java.util.Set;
import org.openide.util.RequestProcessor;

class ThreadDumpProvider$SnapshotListener
  implements DataChangeListener<Snapshot>
{
  private ThreadDumpProvider$SnapshotListener(ThreadDumpProvider paramThreadDumpProvider) {}
  
  public void dataChanged(DataChangeEvent<Snapshot> event)
  {
    final Set<Snapshot> snapshots = event.getAdded();
    if (!snapshots.isEmpty()) {
      RequestProcessor.getDefault().post(new Runnable()
      {
        public void run()
        {
          Snapshot snapshot;
          for (Iterator i$ = snapshots.iterator(); i$.hasNext(); ThreadDumpProvider.access$200(this$0, snapshot)) {
            snapshot = (Snapshot)i$.next();
          }
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider.SnapshotListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.datasource.DataSourceContainer;
import com.sun.tools.visualvm.core.datasource.DataSourceRepository;
import com.sun.tools.visualvm.core.datasource.Storage;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.datasupport.DataChangeEvent;
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
import com.sun.tools.visualvm.core.snapshot.Snapshot;
import com.sun.tools.visualvm.core.snapshot.SnapshotCategory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.coredump.CoreDump;
import com.sun.tools.visualvm.threaddump.ThreadDumpSupport;
import com.sun.tools.visualvm.tools.sa.SaModel;
import com.sun.tools.visualvm.tools.sa.SaModelFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.swing.SwingUtilities;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor.Message;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

public class ThreadDumpProvider
{
  public void createThreadDump(final Application application, final boolean openView)
  {
    RequestProcessor.getDefault().post(new Runnable()
    {
      public void run()
      {
        Jvm jvm = JvmFactory.getJVMFor(application);
        if (!jvm.isTakeThreadDumpSupported())
        {
          DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Cannot_take_thread_dump_for_") + DataSourceDescriptorFactory.getDescriptor(application).getName(), 0));
          
          return;
        }
        ProgressHandle pHandle = null;
        try
        {
          pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Creating_Thread_Dump"));
          pHandle.setInitialDelay(0);
          pHandle.start();
          try
          {
            final ThreadDumpImpl threadDump = new ThreadDumpImpl(jvm.takeThreadDump(), application);
            application.getRepository().addDataSource(threadDump);
            if (openView) {
              SwingUtilities.invokeLater(new Runnable()
              {
                public void run()
                {
                  DataSourceWindowManager.sharedInstance().openDataSource(threadDump);
                }
              });
            }
          }
          catch (IOException ex)
          {
            ErrorManager.getDefault().notify(ex);
          }
        }
        finally
        {
          final ProgressHandle pHandleF;
          ProgressHandle pHandleF = pHandle;
          SwingUtilities.invokeLater(new Runnable()
          {
            public void run()
            {
              if (pHandleF != null) {
                pHandleF.finish();
              }
            }
          });
        }
      }
    });
  }
  
  public void createThreadDump(final CoreDump coreDump, final boolean openView)
  {
    RequestProcessor.getDefault().post(new Runnable()
    {
      public void run()
      {
        ProgressHandle pHandle = null;
        try
        {
          pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(ThreadDumpProvider.class, "MSG_Creating_Thread_Dump"));
          pHandle.setInitialDelay(0);
          pHandle.start();
          File snapshotDir = coreDump.getStorage().getDirectory();
          String name = ThreadDumpSupport.getInstance().getCategory().createFileName();
          File dumpFile = new File(snapshotDir, name);
          SaModel saAget = SaModelFactory.getSAAgentFor(coreDump);
          String dump = saAget.takeThreadDump();
          if (dump != null) {
            try
            {
              OutputStream os = new FileOutputStream(dumpFile);
              os.write(dump.getBytes("UTF-8"));
              os.close();
              final ThreadDumpImpl threadDump = new ThreadDumpImpl(dumpFile, coreDump);
              coreDump.getRepository().addDataSource(threadDump);
              if (openView) {
                SwingUtilities.invokeLater(new Runnable()
                {
                  public void run()
                  {
                    DataSourceWindowManager.sharedInstance().openDataSource(threadDump);
                  }
                });
              }
            }
            catch (Exception ex)
            {
              ErrorManager.getDefault().notify(ex);
            }
          }
        }
        finally
        {
          final ProgressHandle pHandleF;
          ProgressHandle pHandleF = pHandle;
          SwingUtilities.invokeLater(new Runnable()
          {
            public void run()
            {
              if (pHandleF != null) {
                pHandleF.finish();
              }
            }
          });
        }
      }
    });
  }
  
  public void initialize()
  {
    DataSourceRepository.sharedInstance().addDataChangeListener(new SnapshotListener(null), Snapshot.class);
    DataSourceRepository.sharedInstance().addDataChangeListener(new ApplicationListener(null), Application.class);
  }
  
  private void processNewSnapshot(Snapshot snapshot)
  {
    if ((snapshot instanceof ThreadDumpImpl)) {
      return;
    }
    File snapshotFile = snapshot.getFile();
    if ((snapshotFile != null) && (snapshotFile.isDirectory()))
    {
      File[] files = snapshotFile.listFiles(ThreadDumpSupport.getInstance().getCategory().getFilenameFilter());
      if (files == null) {
        return;
      }
      Set<ThreadDumpImpl> threadDumps = new HashSet();
      for (File file : files) {
        threadDumps.add(new ThreadDumpImpl(file, snapshot));
      }
      snapshot.getRepository().addDataSources(threadDumps);
    }
  }
  
  private void processNewApplication(Application application)
  {
    Storage storage = application.getStorage();
    if (storage.directoryExists())
    {
      File[] files = storage.getDirectory().listFiles(ThreadDumpSupport.getInstance().getCategory().getFilenameFilter());
      if (files == null) {
        return;
      }
      Set<ThreadDumpImpl> threadDumps = new HashSet();
      for (File file : files) {
        threadDumps.add(new ThreadDumpImpl(file, application));
      }
      application.getRepository().addDataSources(threadDumps);
    }
  }
  
  private class SnapshotListener
    implements DataChangeListener<Snapshot>
  {
    private SnapshotListener() {}
    
    public void dataChanged(DataChangeEvent<Snapshot> event)
    {
      final Set<Snapshot> snapshots = event.getAdded();
      if (!snapshots.isEmpty()) {
        RequestProcessor.getDefault().post(new Runnable()
        {
          public void run()
          {
            Snapshot snapshot;
            for (Iterator i$ = snapshots.iterator(); i$.hasNext(); ThreadDumpProvider.this.processNewSnapshot(snapshot)) {
              snapshot = (Snapshot)i$.next();
            }
          }
        });
      }
    }
  }
  
  private class ApplicationListener
    implements DataChangeListener<Application>
  {
    private ApplicationListener() {}
    
    public void dataChanged(DataChangeEvent<Application> event)
    {
      final Set<Application> applications = event.getAdded();
      if (!applications.isEmpty()) {
        RequestProcessor.getDefault().post(new Runnable()
        {
          public void run()
          {
            Application application;
            for (Iterator i$ = applications.iterator(); i$.hasNext(); ThreadDumpProvider.this.processNewApplication(application)) {
              application = (Application)i$.next();
            }
          }
        });
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.uisupport.HTMLTextArea;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

class ThreadDumpView$MasterViewSupport$1
  implements Runnable
{
  ThreadDumpView$MasterViewSupport$1(ThreadDumpView.MasterViewSupport paramMasterViewSupport, File paramFile) {}
  
  public void run()
  {
    InputStream is = null;
    try
    {
      is = new FileInputStream(val$file);
      byte[] data = new byte[(int)val$file.length()];
      try
      {
        is.read(data);
      }
      catch (IOException ex)
      {
        ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
      }
      try
      {
        HTMLTextArea area = new HTMLTextArea();
        area.setForeground(new Color(204, 51, 0));
        area.setText("<pre>" + ThreadDumpView.MasterViewSupport.access$200(ThreadDumpView.MasterViewSupport.access$100(new String(data, "UTF-8"))) + "</pre>");
        area.setCaretPosition(0);
        area.setBorder(BorderFactory.createEmptyBorder(14, 8, 14, 8));
        ThreadDumpView.MasterViewSupport.access$400(this$0).remove(ThreadDumpView.MasterViewSupport.access$300(this$0));
        ThreadDumpView.MasterViewSupport.access$400(this$0).add(area, "Center");
        ThreadDumpView.MasterViewSupport.access$400(this$0).revalidate();
        ThreadDumpView.MasterViewSupport.access$400(this$0).repaint();
      }
      catch (Exception ex)
      {
        ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
      }
      return;
    }
    catch (FileNotFoundException ex)
    {
      ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
    }
    finally
    {
      if (is != null) {
        try
        {
          is.close();
        }
        catch (IOException e) {}
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpView.MasterViewSupport.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.ui.components.DataViewComponent.MasterView;
import com.sun.tools.visualvm.core.ui.components.ScrollableContainer;
import com.sun.tools.visualvm.threaddump.ThreadDump;
import com.sun.tools.visualvm.uisupport.HTMLTextArea;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

class ThreadDumpView$MasterViewSupport
  extends JPanel
{
  private JLabel progressLabel;
  private JPanel contentsPanel;
  
  public ThreadDumpView$MasterViewSupport(ThreadDump threadDump)
  {
    initComponents();
    loadThreadDump(threadDump.getFile());
  }
  
  public DataViewComponent.MasterView getMasterView()
  {
    return new DataViewComponent.MasterView(NbBundle.getMessage(ThreadDumpView.class, "LBL_Thread_Dump"), null, new ScrollableContainer(this));
  }
  
  private void initComponents()
  {
    setLayout(new BorderLayout());
    
    progressLabel = new JLabel(NbBundle.getMessage(ThreadDumpView.class, "MSG_Loading_Thread_Dump"), 0);
    
    contentsPanel = new JPanel(new BorderLayout());
    contentsPanel.add(progressLabel, "Center");
    contentsPanel.setOpaque(false);
    
    add(contentsPanel, "Center");
    setOpaque(false);
  }
  
  private static String htmlize(String value)
  {
    return value.replace("&", "&amp;").replace("<", "&lt;");
  }
  
  private static String transform(String value)
  {
    StringBuilder sb = new StringBuilder();
    String[] result = value.split("\\n");
    for (int i = 0; i < result.length; i++)
    {
      String line = result[i];
      if ((!line.isEmpty()) && (!Character.isWhitespace(line.charAt(0))))
      {
        sb.append("<span style=\"color: #0033CC\">");
        sb.append(line);
        sb.append("</span><br>");
      }
      else
      {
        sb.append(line);
        sb.append("<br>");
      }
    }
    return sb.toString();
  }
  
  private void loadThreadDump(final File file)
  {
    RequestProcessor.getDefault().post(new Runnable()
    {
      public void run()
      {
        InputStream is = null;
        try
        {
          is = new FileInputStream(file);
          byte[] data = new byte[(int)file.length()];
          try
          {
            is.read(data);
          }
          catch (IOException ex)
          {
            ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
          }
          try
          {
            HTMLTextArea area = new HTMLTextArea();
            area.setForeground(new Color(204, 51, 0));
            area.setText("<pre>" + ThreadDumpView.MasterViewSupport.transform(ThreadDumpView.MasterViewSupport.access$100(new String(data, "UTF-8"))) + "</pre>");
            area.setCaretPosition(0);
            area.setBorder(BorderFactory.createEmptyBorder(14, 8, 14, 8));
            contentsPanel.remove(progressLabel);
            contentsPanel.add(area, "Center");
            contentsPanel.revalidate();
            contentsPanel.repaint();
          }
          catch (Exception ex)
          {
            ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
          }
          return;
        }
        catch (FileNotFoundException ex)
        {
          ThreadDumpView.access$000().throwing(ThreadDumpView.class.getName(), "loadThreadDump", ex);
        }
        finally
        {
          if (is != null) {
            try
            {
              is.close();
            }
            catch (IOException e) {}
          }
        }
      }
    });
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.threaddump.impl.ThreadDumpView.MasterViewSupport
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.tools.visualvm.threaddump.impl;

import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
import com.sun.tools.visualvm.core.ui.DataSourceView;
import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
import com.sun.tools.visualvm.core.ui.components.DataViewComponent.MasterView;
import com.sun.tools.visualvm.core.ui.components.DataViewComponent.MasterViewConfiguration;
import com.sun.tools.visualvm.core.ui.components.ScrollableContainer;
import com.sun.tools.visualvm.threaddump.ThreadDump;
import com.sun.tools.visualvm.uisupport.HTMLTextArea;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

class ThreadDumpView
  extends DataSourceView
{
  private static final Logger LOGGER = Logger.getLogger(ThreadDumpView.class.getName());
  
  public ThreadDumpView(ThreadDump threadDump)
  {
    this(threadDump, DataSourceDescriptorFactory.getDescriptor(threadDump));
  }
  
  private ThreadDumpView(ThreadDump threadDump, DataSourceDescriptor descriptor)
  {
    super(threadDump, descriptor.getName(), descriptor.getIcon(), 0, true);
  }
  
  protected DataViewComponent createComponent()
  {
    ThreadDump threadDump = (ThreadDump)getDataSource();
    DataViewComponent dvc = new DataViewComponent(new MasterViewSupport(threadDump).getMasterView(), new DataViewComponent.MasterViewConfiguration(true));
    
    return dvc;
  }
  
  private static class MasterViewSupport
    extends JPanel
  {
    private JLabel progressLabel;
    private JPanel contentsPanel;
    
    public MasterViewSupport(ThreadDump threadDump)
    {
      initComponents();
      loadThreadDump(threadDump.getFile());
    }
    
    public DataViewComponent.MasterView getMasterView()
    {
      return new DataViewComponent.MasterView(NbBundle.getMessage(ThreadDumpView.class, "LBL_Thread_Dump"), null, new ScrollableContainer(this));
    }
    
    private void initComponents()
    {
      setLayout(new BorderLayout());
      
      progressLabel = new JLabel(NbBundle.getMessage(ThreadDumpView.class, "MSG_Loading_Thread_Dump"), 0);
      
      contentsPanel = new JPanel(new BorderLayout());
      contentsPanel.add(progressLabel, "Center");
      contentsPanel.setOpaque(false);
      
      add(contentsPanel, "Center");
      setOpaque(false);
    }
    
    private static String htmlize(String value)
    {
      return value.replace("&", "&amp;").replace("<", "&lt;");
    }
    
    private static String transform(String value)
    {
      StringBuilder sb = new StringBuilder();
      String[] result = value.split("\\n");
      for
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd