activeVms;
public RemoteHostImpl() throws MonitorException {
try {
- monitoredHost = MonitoredHost.getMonitoredHost("localhost");
+ this.monitoredHost = MonitoredHost.getMonitoredHost("localhost");
} catch (URISyntaxException e) { }
- activeVms = monitoredHost.activeVms();
- monitoredHost.addHostListener(this);
+ this.activeVms = this.monitoredHost.activeVms();
+ this.monitoredHost.addHostListener(this);
}
- public RemoteVm attachVm(int lvmid, String mode)
- throws RemoteException, MonitorException {
- RemoteVm stub = null;
- StringBuffer sb = new StringBuffer();
+ public RemoteVm attachVm(final int lvmid, final String mode) throws RemoteException, MonitorException {
+ RemoteVm stub;
+ final StringBuilder sb = new StringBuilder();
sb.append("local://").append(lvmid).append("@localhost");
if (mode != null) {
- sb.append("?mode=" + mode);
+ sb.append("?mode=").append(mode);
}
-
- String vmidStr = sb.toString();
+ final String vmidStr = sb.toString();
try {
- VmIdentifier vmid = new VmIdentifier(vmidStr);
- MonitoredVm mvm = monitoredHost.getMonitoredVm(vmid);
- RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm);
+ final VmIdentifier vmid = new VmIdentifier(vmidStr);
+ final MonitoredVm mvm = this.monitoredHost.getMonitoredVm(vmid);
+ final RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm);
stub = (RemoteVm) UnicastRemoteObject.exportObject(rvm, Integer.parseInt(System.getProperty("ejstatd.remoteVm.port", "0")));
}
- catch (URISyntaxException e) {
- throw new RuntimeException("Malformed VmIdentifier URI: "
- + vmidStr, e);
+ catch (final URISyntaxException e) {
+ throw new RuntimeException("Malformed VmIdentifier URI: " + vmidStr, e);
}
return stub;
}
- public void detachVm(RemoteVm rvm) throws RemoteException {
+ public void detachVm(final RemoteVm rvm) throws RemoteException {
rvm.detach();
}
public int[] activeVms() throws MonitorException {
- Object[] vms = null;
- int[] vmids = null;
-
- vms = monitoredHost.activeVms().toArray();
- vmids = new int[vms.length];
+ Object[] vms = this.monitoredHost.activeVms().toArray();
+ int[] vmids = new int[vms.length];
for (int i = 0; i < vmids.length; i++) {
- vmids[i] = ((Integer)vms[i]).intValue();
+ vmids[i] = (Integer) vms[i];
}
return vmids;
}
- public void vmStatusChanged(VmStatusChangeEvent ev) {
+ public void vmStatusChanged(final VmStatusChangeEvent ev) {
synchronized(this.activeVms) {
- activeVms.retainAll(ev.getActive());
+ this.activeVms.retainAll(ev.getActive());
}
}
- public void disconnected(HostEvent ev) {
+ public void disconnected(final HostEvent ev) {
// we only monitor the local host, so this event shouldn't occur.
}
}
diff --git a/src/main/java/com/github/anthony_o/ejstatd/RemoteVmImpl.java b/src/main/java1.8/com/github/anthony_o/ejstatd/RemoteVmImpl.java
similarity index 88%
rename from src/main/java/com/github/anthony_o/ejstatd/RemoteVmImpl.java
rename to src/main/java1.8/com/github/anthony_o/ejstatd/RemoteVmImpl.java
index 7a5abae..7840b03 100644
--- a/src/main/java/com/github/anthony_o/ejstatd/RemoteVmImpl.java
+++ b/src/main/java1.8/com/github/anthony_o/ejstatd/RemoteVmImpl.java
@@ -41,25 +41,25 @@
*/
public class RemoteVmImpl implements RemoteVm {
- private BufferedMonitoredVm mvm;
+ private final BufferedMonitoredVm mvm;
- RemoteVmImpl(BufferedMonitoredVm mvm) {
+ RemoteVmImpl(final BufferedMonitoredVm mvm) {
this.mvm = mvm;
}
public byte[] getBytes() {
- return mvm.getBytes();
+ return this.mvm.getBytes();
}
public int getCapacity() {
- return mvm.getCapacity();
+ return this.mvm.getCapacity();
}
public void detach() {
- mvm.detach();
+ this.mvm.detach();
}
public int getLocalVmId() {
- return mvm.getVmIdentifier().getLocalVmId();
+ return this.mvm.getVmIdentifier().getLocalVmId();
}
}
diff --git a/src/main/java11 b/src/main/java11
new file mode 120000
index 0000000..704cce5
--- /dev/null
+++ b/src/main/java11
@@ -0,0 +1 @@
+java9
\ No newline at end of file
diff --git a/src/main/java8 b/src/main/java8
new file mode 120000
index 0000000..fb30be1
--- /dev/null
+++ b/src/main/java8
@@ -0,0 +1 @@
+java1.8
\ No newline at end of file
diff --git a/src/main/java9/com/github/anthony_o/ejstatd/RemoteHostImpl.java b/src/main/java9/com/github/anthony_o/ejstatd/RemoteHostImpl.java
new file mode 100644
index 0000000..74c339e
--- /dev/null
+++ b/src/main/java9/com/github/anthony_o/ejstatd/RemoteHostImpl.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.github.anthony_o.ejstatd;
+
+import sun.jvmstat.monitor.MonitorException;
+import sun.jvmstat.monitor.MonitoredHost;
+import sun.jvmstat.monitor.MonitoredVm;
+import sun.jvmstat.monitor.VmIdentifier;
+import sun.jvmstat.monitor.event.HostEvent;
+import sun.jvmstat.monitor.event.HostListener;
+import sun.jvmstat.monitor.event.VmStatusChangeEvent;
+import sun.jvmstat.monitor.BufferedMonitoredVm;
+import sun.jvmstat.monitor.remote.RemoteHost;
+import sun.jvmstat.monitor.remote.RemoteVm;
+
+import java.net.URISyntaxException;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Set;
+
+/**
+ * Concrete implementation of the RemoteHost interface for the HotSpot
+ * PerfData rmi: protocol.
+ *
+ * This class provides remote access to the instrumentation exported
+ * by HotSpot Java Virtual Machines through the PerfData shared memory
+ * interface.
+ *
+ * @author Brian Doherty
+ * @since 1.5
+ */
+public class RemoteHostImpl implements RemoteHost, HostListener {
+
+ private MonitoredHost monitoredHost;
+ private final Set activeVms;
+
+ public RemoteHostImpl() throws MonitorException {
+ try {
+ this.monitoredHost = MonitoredHost.getMonitoredHost("localhost");
+ } catch (URISyntaxException e) { }
+
+ this.activeVms = this.monitoredHost.activeVms();
+ this.monitoredHost.addHostListener(this);
+ }
+
+ public RemoteVm attachVm(final int lvmid, final String mode) throws RemoteException, MonitorException {
+ RemoteVm stub;
+
+ final StringBuilder sb = new StringBuilder();
+ sb.append("local://").append(lvmid).append("@localhost");
+ if (mode != null) {
+ sb.append("?mode=").append(mode);
+ }
+ final String vmidStr = sb.toString();
+
+ try {
+ final VmIdentifier vmid = new VmIdentifier(vmidStr);
+ final MonitoredVm mvm = this.monitoredHost.getMonitoredVm(vmid);
+ final RemoteVmImpl rvm = new RemoteVmImpl((BufferedMonitoredVm)mvm);
+ stub = (RemoteVm) UnicastRemoteObject.exportObject(rvm, Integer.parseInt(System.getProperty("ejstatd.remoteVm.port", "0")));
+ }
+ catch (final URISyntaxException e) {
+ throw new RuntimeException("Malformed VmIdentifier URI: " + vmidStr, e);
+ }
+ return stub;
+ }
+
+ public void detachVm(final RemoteVm rvm) throws RemoteException {
+ rvm.detach();
+ }
+
+ public int[] activeVms() throws MonitorException {
+ Object[] vms = this.monitoredHost.activeVms().toArray();
+ int[] vmids = new int[vms.length];
+
+ for (int i = 0; i < vmids.length; i++) {
+ vmids[i] = (Integer) vms[i];
+ }
+ return vmids;
+ }
+
+ public void vmStatusChanged(final VmStatusChangeEvent ev) {
+ synchronized(this.activeVms) {
+ this.activeVms.retainAll(ev.getActive());
+ }
+ }
+
+ public void disconnected(final HostEvent ev) {
+ // we only monitor the local host, so this event shouldn't occur.
+ }
+}
diff --git a/src/main/java9/com/github/anthony_o/ejstatd/RemoteVmImpl.java b/src/main/java9/com/github/anthony_o/ejstatd/RemoteVmImpl.java
new file mode 100644
index 0000000..8191ef9
--- /dev/null
+++ b/src/main/java9/com/github/anthony_o/ejstatd/RemoteVmImpl.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.github.anthony_o.ejstatd;
+
+import sun.jvmstat.monitor.BufferedMonitoredVm;
+import sun.jvmstat.monitor.remote.RemoteVm;
+
+/**
+ * Concrete implementation of the RemoteVm interface for the HotSpot PerfData
+ * shared memory implementation of the jvmstat monitoring APIs. This class
+ * providing remote access to the instrumentation exported by a local HotSpot
+ * Java Virtual Machine. The instrumentation buffer is shipped in whole to
+ * the remote machine, which is responsible for parsing and provide access
+ * to the contained data.
+ *
+ * @author Brian Doherty
+ * @since 1.5
+ */
+public class RemoteVmImpl implements RemoteVm {
+
+ private final BufferedMonitoredVm mvm;
+
+ RemoteVmImpl(final BufferedMonitoredVm mvm) {
+ this.mvm = mvm;
+ }
+
+ public byte[] getBytes() {
+ return this.mvm.getBytes();
+ }
+
+ public int getCapacity() {
+ return this.mvm.getCapacity();
+ }
+
+ public void detach() {
+ this.mvm.detach();
+ }
+
+ public int getLocalVmId() {
+ return this.mvm.getVmIdentifier().getLocalVmId();
+ }
+}