public JvmJvmstatModel createModelFor(Application app) { JvmstatModel jvmstat = JvmstatModelFactory.getJvmstatFor(app); if (jvmstat != null) { String vmVersion = jvmstat.findByName("java.property.java.vm.version"); // NOI18N JvmJvmstatModel model = null; // Check for Sun VM (and maybe other?) // JVM 1.4 if (vmVersion.startsWith("1.4.")) model = new JvmJvmstatModel_4(app, jvmstat); // NOI18N // JVM 1.5 else if (vmVersion.startsWith("1.5.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N // JVM 1.6 else if (vmVersion.startsWith("1.6.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N // JVM 1.7 else if (vmVersion.startsWith("1.7.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N // Hotspot Express else if (vmVersion.startsWith("10.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N else if (vmVersion.startsWith("11.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N else if (vmVersion.startsWith("12.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N else if (vmVersion.startsWith("13.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N else if (vmVersion.startsWith("14.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N if (model == null) { // try java.property.java.version from HotSpot Express 14.0 String javaVersion = jvmstat.findByName("java.property.java.version"); // NOI18N if (javaVersion != null) { // JVM 1.6 if (javaVersion.startsWith("1.6.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N // JVM 1.7 else if (javaVersion.startsWith("1.7.")) model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N // JVM 1.8 else if (javaVersion.startsWith("1.8.")) model = new JvmJvmstatModel_8(app, jvmstat); // NOI18N // JVM 1.9 else if (javaVersion.startsWith("1.9.")) model = new JvmJvmstatModel_8(app, jvmstat); // NOI18N } if (model == null) { // still not recognized, fallback to JvmJvmstatModel_5 LOGGER.log(Level.WARNING, "Unrecognized java.vm.version " + vmVersion); // NOI18N model = new JvmJvmstatModel_5(app, jvmstat); // NOI18N } } return model; } return null; }
/** * Creates an instance of {@code JmxModel} for a {@link JvmstatApplication}. * * @param application the {@link JvmstatApplication}. */ public JmxModelImpl(Application application, JvmstatModel jvmstat) { try { JvmJvmstatModel jvmstatModel = JvmJvmstatModelFactory.getJvmstatModelFor(application); // Create ProxyClient (i.e. create the JMX connection to the JMX agent) ProxyClient proxyClient = null; if (Application.CURRENT_APPLICATION.equals(application)) { // Monitor self proxyClient = new ProxyClient(this); } else if (application.isLocalApplication()) { // Create a ProxyClient from local pid String connectorAddress = jvmstat.findByName("sun.management.JMXConnectorServer.address"); // NOI18N String javaHome = jvmstat.findByName("java.property.java.home"); // NOI18N LocalVirtualMachine lvm = new LocalVirtualMachine( application.getPid(), AttachModelFactory.getAttachFor(application) != null, connectorAddress, javaHome); if (!lvm.isManageable()) { if (lvm.isAttachable()) { proxyClient = new ProxyClient(this, lvm); } else { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "The JMX management agent " + // NOI18N "cannot be enabled in this application (pid " + // NOI18N application.getPid() + ")"); // NOI18N } } } else { proxyClient = new ProxyClient(this, lvm); } } if (proxyClient == null) { // Create a ProxyClient for the remote out-of-the-box // JMX management agent using the port and security // related information retrieved through jvmstat. List<String> urls = jvmstat.findByPattern( "sun.management.JMXConnectorServer.[0-9]+.remoteAddress"); // NOI18N if (urls.size() != 0) { List<String> auths = jvmstat.findByPattern( "sun.management.JMXConnectorServer.[0-9]+.authenticate"); // NOI18N proxyClient = new ProxyClient(this, urls.get(0)); if ("true".equals(auths.get(0))) { // NOI18N supplyCredentials(application, proxyClient); } } else { // Create a ProxyClient for the remote out-of-the-box // JMX management agent using the port specified in // the -Dcom.sun.management.jmxremote.port=<port> // system property String jvmArgs = jvmstatModel.getJvmArgs(); StringTokenizer st = new StringTokenizer(jvmArgs); int port = -1; boolean authenticate = false; while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.startsWith("-Dcom.sun.management.jmxremote.port=")) { // NOI18N port = Integer.parseInt(token.substring(token.indexOf("=") + 1)); // NOI18N } else if (token.equals("-Dcom.sun.management.jmxremote.authenticate=true")) { // NOI18N authenticate = true; } } if (port != -1) { proxyClient = new ProxyClient(this, application.getHost(), port); if (authenticate) { supplyCredentials(application, proxyClient); } } } } if (proxyClient != null) { client = proxyClient; removedListener = new ApplicationRemovedListener(); availabilityListener = new ApplicationAvailabilityListener(); connect(application, proxyClient, removedListener, availabilityListener); } } catch (Exception e) { LOGGER.throwing(JmxModelImpl.class.getName(), "<init>", e); // NOI18N client = null; } }