sun.jvmstat.monitor.HostIdentifier Java Examples

The following examples show how to use sun.jvmstat.monitor.HostIdentifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void rescheduleProcessNewHost(final Host host,final HostIdentifier hostId) {
    int timerInterval = GlobalPreferences.sharedInstance().getMonitoredHostPoll();
    Timer timer = new Timer(timerInterval*1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // do not block EQ - use request processor, processNewHost() can take a long time
            PROCESSOR.post(new Runnable() {
                public void run() {
                    if (!host.isRemoved()) {
                        Set<ConnectionDescriptor> descriptors = HostPropertiesProvider.descriptorsForHost(host);
                        
                        for (ConnectionDescriptor desc : descriptors) {
                            if (hostId.equals(desc.createHostIdentifier(host))) {
                                int interval = (int)(desc.getRefreshRate()*1000);
                                registerJvmstatConnection(host,hostId,interval);
                            }
                        }
                    }
                }
            });
        }
    });
    timer.setRepeats(false);
    timer.start();
}
 
Example #2
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void processDisconnectedJvmstat(Host host, JvmstatConnection listener) {
    HostIdentifier hostId = listener.monitoredHost.getHostIdentifier();
    try { listener.monitoredHost.removeHostListener(listener); } catch (MonitorException ex) {}
    unregisterHostListener(host,hostId);
    Set<JvmstatApplication> jvmstatApplications = host.getRepository().getDataSources(JvmstatApplication.class);
    Iterator<JvmstatApplication> appIt = jvmstatApplications.iterator();
    while (appIt.hasNext()) {
        JvmstatApplication application = appIt.next();
        
        if (application.getHostIdentifier().equals(hostId)) {
            application.setStateImpl(Stateful.STATE_UNAVAILABLE);
            if (application.handleControlledRemove()) appIt.remove();
        } else {
            appIt.remove();
        }
    }
    host.getRepository().removeDataSources(jvmstatApplications);
}
 
Example #3
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void processRemovedJvmstatConnection(final Host host, HostIdentifier hostId) {
    if (host == Host.UNKNOWN_HOST) return;
    
    synchronized (hostsListeners) {
        Map<HostIdentifier,JvmstatConnection> hostListeners = hostsListeners.get(host);
        
        if (hostListeners != null) {
            JvmstatConnection listener = hostListeners.get(hostId);
            if (listener != null) {
                processDisconnectedJvmstat(host, listener);
            }
        }
    }
}
 
Example #4
Source File: IgniteNodeRunner.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Kill all Jvm runned by {#link IgniteNodeRunner}. Works based on jps command.
 *
 * @return List of killed process ids.
 * @throws Exception If exception.
 */
public static List<Integer> killAll() throws Exception {
    MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));

    Set<Integer> jvms = monitoredHost.activeVms();

    List<Integer> res = new ArrayList<>();

    for (Integer jvmId : jvms) {
        try {
            MonitoredVm vm = monitoredHost.getMonitoredVm(new VmIdentifier("//" + jvmId + "?mode=r"), 0);

            if (IgniteNodeRunner.class.getName().equals(MonitoredVmUtil.mainClass(vm, true))) {
                Process killProc = Runtime.getRuntime().exec(U.isWindows() ?
                    new String[] {"taskkill", "/pid", jvmId.toString(), "/f", "/t"} :
                    new String[] {"kill", "-9", jvmId.toString()});

                killProc.waitFor();

                res.add(jvmId);
            }
        }
        catch (Exception e) {
            // Print stack trace just for information.
            X.printerrln("Could not kill IgniteNodeRunner java processes. Jvm pid = " + jvmId, e);
        }
    }

    return res;
}
 
Example #5
Source File: LocalVirtualMachine.java    From jmxmon with Apache License 2.0 5 votes vote down vote up
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
    MonitoredHost host;
    Set vms;
    try {
        host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
        vms = host.activeVms();
    } catch (java.net.URISyntaxException sx) {
        throw new InternalError(sx.getMessage());
    } catch (MonitorException mx) {
        throw new InternalError(mx.getMessage());
    }
    for (Object vmid: vms) {
        if (vmid instanceof Integer) {
            int pid = ((Integer) vmid).intValue();
            String name = vmid.toString(); // default to pid if name not available
            boolean attachable = false;
            String address = null;
            try {
                 MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
                 // use the command line as the display name
                 name =  MonitoredVmUtil.commandLine(mvm);
                 attachable = MonitoredVmUtil.isAttachable(mvm);
                 address = ConnectorAddressLink.importFrom(pid);
                 mvm.detach();
            } catch (Exception x) {
                 // ignore
            }
            map.put((Integer) vmid, 
                    new LocalVirtualMachine(pid, name, attachable, address));
        }
    }
}
 
Example #6
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private MonitoredHost getMonitoredHost(HostIdentifier hostId) {
    try {
        return MonitoredHost.getMonitoredHost(hostId);
    } catch (MonitorException ex) {
        // NOTE: valid state, jstatd not running, Host will be scheduled for later MonitoredHost resolving
        //            ErrorManager.getDefault().log(ErrorManager.WARNING,ex.getLocalizedMessage());
    }
    return null;
}
 
Example #7
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void registerJvmstatConnection(Host host, HostIdentifier hostId, int interval) {
    // Monitor the Host for new/finished Applications
    // NOTE: the code relies on the fact that the provider is the first listener registered in MonitoredHost of the Host
    // in which case the first obtained event contains all applications already running on the Host
    JvmstatConnection hostListener = null;
    
    // Get the MonitoredHost for Host
    final MonitoredHost monitoredHost = getMonitoredHost(hostId);
    
    if (monitoredHost == null) { // monitored host not available reschedule
        rescheduleProcessNewHost(host,hostId);
        return;
    }
    hostId = monitoredHost.getHostIdentifier();
    monitoredHost.setInterval(interval);
    if (host == Host.LOCALHOST) checkForBrokenLocalJps(monitoredHost);
    try {
        // Fetch already running applications on the host
        processNewApplicationsByPids(host, hostId, monitoredHost.activeVms());
        hostListener = new JvmstatConnection(host, monitoredHost);
        monitoredHost.addHostListener(hostListener);
        registerHostListener(host, hostId, hostListener);
    } catch (MonitorException e) {
        Throwable t = e.getCause();
        monitoredHost.setLastException(e);
        if (!(t instanceof ConnectException)) {
            DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(
                    NbBundle.getMessage(JvmstatApplicationProvider.class, "MSG_Broken_Jvmstat", // NOI18N
                    DataSourceDescriptorFactory.getDescriptor(host).getName()),
                    NotifyDescriptor.ERROR_MESSAGE));
            LOGGER.log(Level.INFO, "Jvmstat connection to " + host + " failed.", t); // NOI18N
        } else {
            rescheduleProcessNewHost(host,hostId);
        }
    }
}
 
Example #8
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void unregisterHostListener(Host host,HostIdentifier hostId) {
    synchronized (hostsListeners) {
        Map<HostIdentifier,JvmstatConnection> hostListeners = hostsListeners.get(host);
        
        assert hostListeners != null;
        hostListeners.remove(hostId);
    }
}
 
Example #9
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void processNewApplicationsByPids(Host host, HostIdentifier hostId, Set<Integer> applicationPids) {
    Set<JvmstatApplication> newApplications = new HashSet();
    
    for (int applicationPid : applicationPids) {
        // Do not provide instance for Application.CURRENT_APPLICATION
        if (Application.CURRENT_APPLICATION.getPid() == applicationPid && Host.LOCALHOST.equals(host)) {
            continue;
        }
        
        String appId = createId(host, applicationPid);
        JvmstatApplication application = new JvmstatApplication(host, hostId, appId, applicationPid);
        if (!applications.containsKey(appId)) {
            // precompute JVM
            application.jvm = JvmFactory.getJVMFor(application);
            applications.put(appId, application);
            newApplications.add(application);
        } else {
            JvmstatApplication zombieApp = applications.get(appId);
            if (zombieApp != null && zombieApp.getState() == Stateful.STATE_UNAVAILABLE) {
                zombieApp.setStateImpl(Stateful.STATE_AVAILABLE);
                zombieApp.jvm = JvmFactory.getJVMFor(zombieApp);
            }
        }
    }
    
    host.getRepository().addDataSources(newApplications);
}
 
Example #10
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void processFinishedHost(final Host host) {
    if (host == Host.UNKNOWN_HOST) return;
    
    synchronized (hostsListeners) {
        Map<HostIdentifier,JvmstatConnection> hostListeners = hostsListeners.get(host);
        
        if (hostListeners != null) {
            for (JvmstatConnection listener : new ArrayList<JvmstatConnection>(hostListeners.values())) {
                processDisconnectedJvmstat(host, listener);
            }
        }
    }
}
 
Example #11
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void processChangedJvmstatConnection(Host host, ConnectionDescriptor changedConnection) {
    HostIdentifier hostId = changedConnection.createHostIdentifier(host);
    MonitoredHost monitoredHost = getMonitoredHost(hostId);
    if (monitoredHost != null) {
        int interval = (int)(changedConnection.getRefreshRate()*1000);
        monitoredHost.setInterval(interval);
    }
}
 
Example #12
Source File: JvmstatApplicationProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void registerJvmstatConnections(final Host host, final Set<ConnectionDescriptor> descrs) {
    for (ConnectionDescriptor desc : descrs) {
        int interval = (int)(desc.getRefreshRate()*1000);
        HostIdentifier hostId = desc.createHostIdentifier(host);
        registerJvmstatConnection(host,hostId,interval);
    }
}
 
Example #13
Source File: ConnectionDescriptor.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
final HostIdentifier createHostIdentifier(Host host) {
    String hostId = null;
    if (this != DEFAULT_LOCAL_DESCRIPTOR) {
        hostId = "rmi://" + host.getHostName(); // NOI18N
        if (port != Registry.REGISTRY_PORT) hostId += ":" + port; // NOI18N
    }
    try {
        return new HostIdentifier(hostId);
    } catch (URISyntaxException e) {
        Exceptions.printStackTrace(e);
        return null;
    }
}
 
Example #14
Source File: Arguments.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
public Arguments(String[] args) throws IllegalArgumentException {
    int argc = 0;

    if (args.length == 1) {
        if ((args[0].compareTo("-?") == 0)
                || (args[0].compareTo("-h") == 0)
                || (args[0].compareTo("--help") == 0)
                // -help: legacy.
                || (args[0].compareTo("-help") == 0)) {
            help = true;
            return;
        }
    }

    for (argc = 0; (argc < args.length) && (args[argc].startsWith("-"));
         argc++) {
        String arg = args[argc];

        if (arg.compareTo("-q") == 0) {
            quiet = true;
        } else if (arg.startsWith("-")) {
            for (int j = 1; j < arg.length(); j++) {
                switch (arg.charAt(j)) {
                    case 'm':
                        mainArgs = true;
                        break;
                    case 'l':
                        longPaths = true;
                        break;
                    case 'v':
                        vmArgs = true;
                        break;
                    case 'V':
                        vmFlags = true;
                        break;
                    default:
                        throw new IllegalArgumentException("illegal argument: "
                                + args[argc]);
                }
            }
        } else {
            throw new IllegalArgumentException("illegal argument: "
                    + args[argc]);
        }
    }

    switch (args.length - argc) {
        case 0:
            hostname = null;
            break;
        case 1:
            hostname = args[args.length - 1];
            break;
        default:
            throw new IllegalArgumentException("invalid argument count");
    }

    try {
        hostId = new HostIdentifier(hostname);
    } catch (URISyntaxException e) {
        IllegalArgumentException iae =
                new IllegalArgumentException("Malformed Host Identifier: "
                        + hostname);
        iae.initCause(e);
        throw iae;
    }
}
 
Example #15
Source File: JvmstatApplication.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
HostIdentifier getHostIdentifier() {
   return hostId; 
}
 
Example #16
Source File: JvmstatApplication.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
JvmstatApplication(Host host, HostIdentifier hostId, String id, int pid) {
    super(host, id);
    this.pid = pid;
    this.hostId = hostId;
}
 
Example #17
Source File: MonitoredHostRmiService.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MonitoredHost getMonitoredHost(HostIdentifier hostId) throws MonitorException {
    return new MonitoredHostProvider(hostId);
}
 
Example #18
Source File: MonitoredHostFileService.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MonitoredHost getMonitoredHost(HostIdentifier hostId)
        throws MonitorException {
    return new MonitoredHostProvider(hostId);
}
 
Example #19
Source File: PropertiesImpl.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
static boolean isLocalConnection(JvmstatApplication dataSource) {
    HostIdentifier hi = dataSource.getHostIdentifier();
    return LOCAL_JVMSTAT_URI.equals(hi.getURI().toString());
}
 
Example #20
Source File: MonitoredHostLocalService.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MonitoredHost getMonitoredHost(HostIdentifier hostId)
        throws MonitorException {
    return new MonitoredHostProvider(hostId);
}
 
Example #21
Source File: LocalVirtualMachine.java    From jvmtop with GNU General Public License v2.0 4 votes vote down vote up
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map,
    Map<Integer, LocalVirtualMachine> existingMap)
{
  //Unsupported on J9
  if (J9Mode)
  {
    return;
  }
  MonitoredHost host;
  Set vms;
  try
  {
    host = MonitoredHost.getMonitoredHost(new HostIdentifier((String) null));
    vms = host.activeVms();
  }
  catch (java.net.URISyntaxException sx)
  {
    throw new InternalError(sx.getMessage());
  }
  catch (MonitorException mx)
  {
    throw new InternalError(mx.getMessage());
  }
  for (Object vmid : vms)
  {
    if (existingMap.containsKey(vmid))
    {
      continue;
    }
    if (vmid instanceof Integer)
    {
      int pid = ((Integer) vmid).intValue();
      String name = vmid.toString(); // default to pid if name not available
      boolean attachable = false;
      String address = null;
      try
      {
        MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
        // use the command line as the display name
        name = MonitoredVmUtil.commandLine(mvm);
        attachable = MonitoredVmUtil.isAttachable(mvm);
        address = ConnectorAddressLink.importFrom(pid);
        mvm.detach();
      }
      catch (Exception x)
      {
        // ignore
      }
      map.put((Integer) vmid, new LocalVirtualMachine(pid, name, attachable,
          address));
    }
  }
}
 
Example #22
Source File: Arguments.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
public HostIdentifier hostId() {
    return hostId;
}