Exemplo n.º 1
0
  /**
   * Returns all the target VMs that are running at this launcher's target address. Note that these
   * target VMs may or may not have been launched by this launcher. Note also that if the list of
   * running VMs doesn't change on the target, two calls to this method return VMs that are equal.
   *
   * @return the list of running target VMs
   */
  public LocalVirtualMachine[] getRunningVirtualMachines() {
    // Select the VMs that are actually running
    Vector actuallyRunning = new Vector();
    Enumeration en = this.runningVMs.elements();
    while (en.hasMoreElements()) {
      LocalVirtualMachine vm = (LocalVirtualMachine) en.nextElement();
      if (vm.isRunning()) actuallyRunning.addElement(vm);
    }
    this.runningVMs = actuallyRunning;

    // Return the running VMs
    int size = actuallyRunning.size();
    LocalVirtualMachine[] result = new LocalVirtualMachine[size];
    for (int i = 0; i < size; i++) result[i] = (LocalVirtualMachine) actuallyRunning.elementAt(i);
    return result;
  }
Exemplo n.º 2
0
 public int getVmid() {
   return (lvm != null) ? lvm.vmid() : 0;
 }
Exemplo n.º 3
0
 private static String getCacheKey(LocalVirtualMachine lvm) {
   return Integer.toString(lvm.vmid());
 }
Exemplo n.º 4
0
 public static String getConnectionName(LocalVirtualMachine lvm) {
   return Integer.toString(lvm.vmid());
 }
Exemplo n.º 5
0
  private void tryConnect(boolean requireRemoteSSL) throws IOException {
    if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
      // Monitor self
      this.jmxc = null;
      this.mbsc = ManagementFactory.getPlatformMBeanServer();
      this.server = Snapshot.newSnapshot(mbsc);
    } else {
      // Monitor another process
      if (lvm != null) {
        if (!lvm.isManageable()) {
          lvm.startManagementAgent();
          if (!lvm.isManageable()) {
            // FIXME: what to throw
            throw new IOException(lvm + "not manageable");
          }
        }
        if (this.jmxUrl == null) {
          this.jmxUrl = new JMXServiceURL(lvm.connectorAddress());
        }
      }
      Map<String, Object> env = new HashMap<String, Object>();
      if (requireRemoteSSL) {
        env.put("jmx.remote.x.check.stub", "true");
      }
      // Need to pass in credentials ?
      if (userName == null && password == null) {
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      } else {
        env.put(JMXConnector.CREDENTIALS, new String[] {userName, password});
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      }
      this.mbsc = jmxc.getMBeanServerConnection();
      this.server = Snapshot.newSnapshot(mbsc);
    }
    this.isDead = false;

    try {
      ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
      this.hasPlatformMXBeans = server.isRegistered(on);
      this.hasHotSpotDiagnosticMXBean =
          server.isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME));
      // check if it has 6.0 new APIs
      if (this.hasPlatformMXBeans) {
        MBeanOperationInfo[] mopis = server.getMBeanInfo(on).getOperations();
        // look for findDeadlockedThreads operations;
        for (MBeanOperationInfo op : mopis) {
          if (op.getName().equals("findDeadlockedThreads")) {
            this.supportsLockUsage = true;
            break;
          }
        }

        on = new ObjectName(COMPILATION_MXBEAN_NAME);
        this.hasCompilationMXBean = server.isRegistered(on);
      }
    } catch (MalformedObjectNameException e) {
      // should not reach here
      throw new InternalError(e.getMessage());
    } catch (IntrospectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (InstanceNotFoundException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (ReflectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    }

    if (hasPlatformMXBeans) {
      // WORKAROUND for bug 5056632
      // Check if the access role is correct by getting a RuntimeMXBean
      getRuntimeMXBean();
    }
  }
Exemplo n.º 6
0
 private ProxyClient(LocalVirtualMachine lvm) throws IOException {
   this.lvm = lvm;
   this.connectionName = getConnectionName(lvm);
   this.displayName = "pid: " + lvm.vmid() + " " + lvm.displayName();
 }