com-sun-tools-visualvm-host-remote

16:33:50.187 INFO  jd.cli.Main - Decompiling com-sun-tools-visualvm-host-remote.jar
package com.sun.tools.visualvm.host.remote;

import com.sun.tools.visualvm.host.model.HostOverviewFactory;
import com.sun.tools.visualvm.host.remote.model.RemoteHostModelProvider;
import org.openide.modules.ModuleInstall;

public class Installer
  extends ModuleInstall
{
  public void restored()
  {
    HostOverviewFactory.getDefault().registerProvider(new RemoteHostModelProvider());
  }
}

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

import com.sun.tools.visualvm.core.model.AbstractModelProvider;
import com.sun.tools.visualvm.host.Host;
import com.sun.tools.visualvm.host.model.HostOverview;

public class RemoteHostModelProvider
  extends AbstractModelProvider<HostOverview, Host>
{
  public HostOverview createModelFor(Host host)
  {
    if (!Host.LOCALHOST.equals(host)) {
      return new RemoteHostOverview(host);
    }
    return null;
  }
}

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

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.host.Host;
import com.sun.tools.visualvm.host.model.HostOverview;
import com.sun.tools.visualvm.tools.jmx.JmxModel;
import com.sun.tools.visualvm.tools.jmx.JmxModel.ConnectionState;
import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeans;
import com.sun.tools.visualvm.tools.jmx.JvmMXBeansFactory;
import java.io.IOException;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.InetAddress;
import java.rmi.ConnectException;
import java.util.Properties;
import java.util.Set;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

class RemoteHostOverview
  extends HostOverview
{
  private static final ObjectName osMXBeanName = ;
  private static final String TotalPhysicalMemorySizeAttr = "TotalPhysicalMemorySize";
  private static final String TotalPhysicalMemorySizeAttr1 = "TotalPhysicalMemory";
  private static final String FreePhysicalMemorySizeAttr = "FreePhysicalMemorySize";
  private static final String TotalSwapSpaceSizeAttr = "TotalSwapSpaceSize";
  private static final String FreeSwapSpaceSizeAttr = "FreeSwapSpaceSize";
  private volatile OperatingSystemMXBean osMXBean;
  private volatile MBeanServerConnection connection;
  private volatile boolean loadAverageAvailable;
  private volatile Application jmxApp;
  private String totalPhysicalMemorySizeAttr;
  private Host remoteHost;
  private boolean staticDataInitialized;
  private String name;
  private String version;
  private String patchLevel;
  private String arch;
  
  RemoteHostOverview(Host h)
  {
    remoteHost = h;
  }
  
  public String getName()
  {
    initStaticData();
    return name;
  }
  
  public String getVersion()
  {
    initStaticData();
    return version;
  }
  
  public String getPatchLevel()
  {
    initStaticData();
    return patchLevel;
  }
  
  public String getArch()
  {
    initStaticData();
    return arch;
  }
  
  public int getAvailableProcessors()
  {
    checkJmxApp();
    if (jmxApp == null) {
      return -1;
    }
    try
    {
      return osMXBean.getAvailableProcessors();
    }
    catch (UndeclaredThrowableException ex)
    {
      if ((ex.getCause() instanceof ConnectException))
      {
        jmxApp = null;
        return getAvailableProcessors();
      }
      throw ex;
    }
  }
  
  public String getHostName()
  {
    return remoteHost.getHostName();
  }
  
  public double getSystemLoadAverage()
  {
    if (loadAverageAvailable)
    {
      checkJmxApp();
      if (jmxApp == null) {
        return -1.0D;
      }
      try
      {
        return osMXBean.getSystemLoadAverage();
      }
      catch (UndeclaredThrowableException ex)
      {
        if ((ex.getCause() instanceof ConnectException))
        {
          jmxApp = null;
          return getSystemLoadAverage();
        }
        throw ex;
      }
    }
    return -1.0D;
  }
  
  public long getTotalPhysicalMemorySize()
  {
    checkJmxApp();
    if (jmxApp == null) {
      return -1L;
    }
    try
    {
      return getAttribute(totalPhysicalMemorySizeAttr);
    }
    catch (IOException ex)
    {
      jmxApp = null;
    }
    return getTotalPhysicalMemorySize();
  }
  
  public long getFreePhysicalMemorySize()
  {
    checkJmxApp();
    if (jmxApp == null) {
      return -1L;
    }
    try
    {
      return getAttribute("FreePhysicalMemorySize");
    }
    catch (IOException ex)
    {
      jmxApp = null;
    }
    return getTotalPhysicalMemorySize();
  }
  
  public long getTotalSwapSpaceSize()
  {
    checkJmxApp();
    if (jmxApp == null) {
      return -1L;
    }
    try
    {
      return getAttribute("TotalSwapSpaceSize");
    }
    catch (IOException ex)
    {
      jmxApp = null;
    }
    return getTotalPhysicalMemorySize();
  }
  
  public long getFreeSwapSpaceSize()
  {
    checkJmxApp();
    if (jmxApp == null) {
      return -1L;
    }
    try
    {
      return getAttribute("FreeSwapSpaceSize");
    }
    catch (IOException ex)
    {
      jmxApp = null;
    }
    return getTotalPhysicalMemorySize();
  }
  
  public String getHostAddress()
  {
    return remoteHost.getInetAddress().getHostAddress();
  }
  
  private synchronized void initStaticData()
  {
    if (staticDataInitialized) {
      return;
    }
    checkJmxApp();
    if (jmxApp == null) {
      return;
    }
    Properties sysProp = JvmFactory.getJVMFor(jmxApp).getSystemProperties();
    name = osMXBean.getName();
    version = osMXBean.getVersion();
    patchLevel = sysProp.getProperty("sun.os.patch.level", "");
    arch = osMXBean.getArch();
    String bits = sysProp.getProperty("sun.arch.data.model");
    if (bits != null) {
      arch = (arch + " " + bits + "bit");
    }
    staticDataInitialized = true;
  }
  
  private Application getJMXApplication()
  {
    Set<Application> apps = remoteHost.getRepository().getDataSources(Application.class);
    for (Application app : apps) {
      if (app.getState() == 1)
      {
        JmxModel jmx = JmxModelFactory.getJmxModelFor(app);
        if ((jmx != null) && (jmx.getConnectionState().equals(JmxModel.ConnectionState.CONNECTED)))
        {
          JvmMXBeans mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmx);
          connection = jmx.getMBeanServerConnection();
          if ((mxbeans != null) && (connection != null))
          {
            osMXBean = mxbeans.getOperatingSystemMXBean();
            loadAverageAvailable = false;
            try
            {
              loadAverageAvailable = (osMXBean.getSystemLoadAverage() >= 0.0D);
            }
            catch (UndeclaredThrowableException ex)
            {
              Throwable cause = ex.getCause();
              if (!(cause instanceof AttributeNotFoundException)) {
                throw ex;
              }
            }
            try
            {
              connection.getAttribute(osMXBeanName, "TotalPhysicalMemorySize");
              totalPhysicalMemorySizeAttr = "TotalPhysicalMemorySize";
            }
            catch (AttributeNotFoundException ex)
            {
              totalPhysicalMemorySizeAttr = "TotalPhysicalMemory";
            }
            catch (InstanceNotFoundException ex)
            {
              throw new RuntimeException(ex);
            }
            catch (ReflectionException ex)
            {
              throw new RuntimeException(ex);
            }
            catch (MBeanException ex)
            {
              throw new RuntimeException(ex);
            }
            catch (IOException ex)
            {
              throw new RuntimeException(ex);
            }
            return app;
          }
        }
      }
    }
    return null;
  }
  
  private synchronized void checkJmxApp()
  {
    if ((jmxApp == null) || (jmxApp.getState() != 1)) {
      jmxApp = getJMXApplication();
    }
  }
  
  private long getAttribute(String name)
    throws IOException
  {
    Object val = null;
    try
    {
      val = connection.getAttribute(osMXBeanName, name);
    }
    catch (AttributeNotFoundException ex)
    {
      return -1L;
    }
    catch (InstanceNotFoundException ex)
    {
      throw new RuntimeException(ex);
    }
    catch (MBeanException ex)
    {
      throw new RuntimeException(ex);
    }
    catch (ReflectionException ex)
    {
      throw new RuntimeException(ex);
    }
    if ((val instanceof Number)) {
      return ((Number)val).longValue();
    }
    return -1L;
  }
  
  private static ObjectName getOperatingSystemMXBeanName()
  {
    try
    {
      return new ObjectName("java.lang:type=OperatingSystem");
    }
    catch (MalformedObjectNameException ex)
    {
      throw new IllegalArgumentException(ex);
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.tools.visualvm.host.remote.model.RemoteHostOverview
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

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