public static LocalVirtualMachine getDelegateMachine(VirtualMachine vm) throws IOException { // privileges. boolean attachable = false; String address = null; String name = String.valueOf(vm.id()); // default display name to pid attachable = true; Properties agentProps = vm.getAgentProperties(); address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP); vm.detach(); return new LocalVirtualMachine(Integer.parseInt(vm.id()), name, attachable, address); }
System.out.println("attached to: "+vm.id()+'/'+vm.provider().type()); vm.loadAgent(createJar().getAbsolutePath()); synchronized(SelfAttacher.class) {
private static String getJmxUriFromVirtualMachine(VirtualMachine vm) { String connectorAddress = null; try { // Get the local JMX connector URI connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } catch (IOException e) { throw new IllegalStateException("IOException when fetching JMX URI from JVM with ID: " + vm.id(), e); } // If there is no local JMX connector URI, we need to launch the // JMX agent via this VirtualMachine attachment. if (connectorAddress == null) { LOG.info("Starting local management agent in JVM with ID: " + vm.id()); try { vm.startLocalManagementAgent(); } catch (IOException e) { throw new IllegalStateException("IOException when starting local JMX management agent in JVM with ID: " + vm.id(), e); } // Agent is started, get the connector address try { connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS); } catch (IOException e) { throw new IllegalStateException("IOException when fetching JMX URI from JVM with ID: " + vm.id(), e); } } return connectorAddress; }
/** * Tests this VirtualMachine for equality with another object. * <p/> * <p> If the given object is not a VirtualMachine then this * method returns <tt>false</tt>. For two VirtualMachines to * be considered equal requires that they both reference the same * provider, and their {@link VirtualMachineDescriptor#id() identifiers} are equal. </p> * <p/> * <p> This method satisfies the general contract of the method. </p> * * @param ob The object to which this object is to be compared * @return <tt>true</tt> if, and only if, the given object is * a VirtualMachine that is equal to this * VirtualMachine. */ @Override public boolean equals(Object ob) { if (ob == this) { return true; } if (!(ob instanceof VirtualMachine)) { return false; } VirtualMachine other = (VirtualMachine) ob; return other.provider() == provider() && other.id().equals(id()); }
/** * Tests this VirtualMachine for equality with another object. * <p/> * <p> If the given object is not a VirtualMachine then this * method returns <tt>false</tt>. For two VirtualMachines to * be considered equal requires that they both reference the same * provider, and their {@link VirtualMachineDescriptor#id() identifiers} are equal. </p> * <p/> * <p> This method satisfies the general contract of the {@link * java.lang.Object#equals(Object) Object.equals} method. </p> * * @param ob The object to which this object is to be compared * @return <tt>true</tt> if, and only if, the given object is * a VirtualMachine that is equal to this * VirtualMachine. */ public boolean equals(Object ob) { if (ob == this) { return true; } if (!(ob instanceof VirtualMachine)) { return false; } VirtualMachine other = (VirtualMachine) ob; return other.provider() == provider() && other.id().equals(id()); }
/** * For testing / investigation purposes. Dumps out as much information as possible * that can be onbtained from the jvm, without accessing JMX. */ public void dumpJvmInfo() throws IOException { System.out.println("--- vm infos ----"); System.out.println("id = "+vm.id()); System.out.println("displayName = "+vmd.displayName()); dump("agentProperties", vm.getAgentProperties()); dump("systemProps", vm.getSystemProperties()); System.out.println("-----------------"); }