本文整理匯總了Java中com.sun.tools.attach.VirtualMachineDescriptor類的典型用法代碼示例。如果您正苦於以下問題:Java VirtualMachineDescriptor類的具體用法?Java VirtualMachineDescriptor怎麽用?Java VirtualMachineDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
VirtualMachineDescriptor類屬於com.sun.tools.attach包,在下文中一共展示了VirtualMachineDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: attach
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
/**
* Spawn recaf in the JVM by the given descriptor.
*
* @param vm
*/
public static void attach(VirtualMachineDescriptor vm) {
try {
// Run attach
VirtualMachine target = VirtualMachine.attach(vm);
String agentPath = getAgentJar();
if (!agentPath.endsWith(".jar")) {
Recaf.INSTANCE.logging.error(new RuntimeException("Recaf could not resolve a path to itself."));
return;
}
File agent = new File(agentPath);
if (agent.exists()) {
Recaf.INSTANCE.logging.info("Attempting to attach to '" + vm.displayName() + "' with agent '" + agent.getAbsolutePath() + "'.");
target.loadAgent(agent.getAbsolutePath());
target.detach();
} else {
Recaf.INSTANCE.logging.error(new RuntimeException("Recaf could not resolve a path to itself, attempt gave: " + agent.getAbsolutePath()));
}
} catch (Exception e) {
Recaf.INSTANCE.logging.error(e);
}
}
示例2: getMainClass
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
private static String getMainClass(VirtualMachineDescriptor vmd)
throws URISyntaxException, MonitorException {
try {
String mainClass = null;
VmIdentifier vmId = new VmIdentifier(vmd.id());
MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
monitoredHost.detach(monitoredVm);
return mainClass;
} catch(NullPointerException e) {
// There is a potential race, where a running java app is being
// queried, unfortunately the java app has shutdown after this
// method is started but before getMonitoredVM is called.
// If this is the case, then the /tmp/hsperfdata_xxx/pid file
// will have disappeared and we will get a NullPointerException.
// Handle this gracefully....
return null;
}
}
示例3: getConnectorAddress
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
private JMXConnectUrlInfo getConnectorAddress(VirtualMachineDescriptor desc){
if(AgentConfiguration.INSTANCE.isAgentJMXLocalConnect()){
String connectorAddress = AbstractJmxCommand.findJMXLocalUrlByProcessId(Integer.parseInt(desc.id()));
if(connectorAddress != null){
return new JMXConnectUrlInfo(connectorAddress);
}
}
JMXConnectUrlInfo jmxConnectUrlInfo = null;
try {
jmxConnectUrlInfo = AbstractJmxCommand.findJMXRemoteUrlByProcessId(null,Integer.parseInt(desc.id()), HostUtil.getHostIp());
if(jmxConnectUrlInfo != null){
log.info("JMX Remote URL:{}",jmxConnectUrlInfo);
}else if(!AgentConfiguration.INSTANCE.isAgentJMXLocalConnect()){
log.warn("應用未配置JMX Remote功能,請給應用配置JMX Remote");
}
} catch (Exception e) {
log.error("JMX連接本機地址獲取失敗",e);
}
return jmxConnectUrlInfo;
}
示例4: getVmDescByServerName
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
/**
* 獲取指定服務名的本地JMX VM 描述對象
* @param serverName
* @return
*/
public static List<VirtualMachineDescriptor> getVmDescByServerName(String serverName){
List<VirtualMachineDescriptor> vmDescList = new ArrayList<>();
if (StringUtils.isEmpty(serverName)){
return vmDescList;
}
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor desc : vms) {
//java -jar 形式啟動的Java應用
if(desc.displayName().matches(".*\\.jar(\\s*-*.*)*") && desc.displayName().contains(serverName)){
vmDescList.add(desc);
}else if(hasContainsServerName(desc.displayName(),serverName)){
vmDescList.add(desc);
}else if (isJSVC(desc.id(),serverName)){
VirtualMachineDescriptor descriptor = new VirtualMachineDescriptor(desc.provider(),desc.id(),serverName);
vmDescList.add(descriptor);
}
}
return vmDescList;
}
示例5: attachVirtualMachine
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
throws AttachNotSupportedException, IOException
{
if (vmd.provider() != this) {
throw new AttachNotSupportedException("provider mismatch");
}
// To avoid re-checking if the VM if attachable, we check if the descriptor
// is for a hotspot VM - these descriptors are created by the listVirtualMachines
// implementation which only returns a list of attachable VMs.
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
checkAttachPermission();
return new SolarisVirtualMachine(this, vmd.id());
} else {
return attachVirtualMachine(vmd.id());
}
}
示例6: attachVirtualMachine
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
throws AttachNotSupportedException, IOException
{
if (vmd.provider() != this) {
throw new AttachNotSupportedException("provider mismatch");
}
// To avoid re-checking if the VM if attachable, we check if the descriptor
// is for a hotspot VM - these descriptors are created by the listVirtualMachines
// implementation which only returns a list of attachable VMs.
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
checkAttachPermission();
return new BsdVirtualMachine(this, vmd.id());
} else {
return attachVirtualMachine(vmd.id());
}
}
示例7: attachVirtualMachine
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
throws AttachNotSupportedException, IOException
{
if (vmd.provider() != this) {
throw new AttachNotSupportedException("provider mismatch");
}
// To avoid re-checking if the VM if attachable, we check if the descriptor
// is for a hotspot VM - these descriptors are created by the listVirtualMachines
// implementation which only returns a list of attachable VMs.
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
checkAttachPermission();
return new LinuxVirtualMachine(this, vmd.id());
} else {
return attachVirtualMachine(vmd.id());
}
}
示例8: attachVirtualMachine
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
throws AttachNotSupportedException, IOException
{
if (vmd.provider() != this) {
throw new AttachNotSupportedException("provider mismatch");
}
// To avoid re-checking if the VM if attachable, we check if the descriptor
// is for a hotspot VM - these descriptors are created by the listVirtualMachines
// implementation which only returns a list of attachable VMs.
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
checkAttachPermission();
return new AixVirtualMachine(this, vmd.id());
} else {
return attachVirtualMachine(vmd.id());
}
}
示例9: attachVirtualMachine
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
throws AttachNotSupportedException, IOException
{
if (vmd.provider() != this) {
throw new AttachNotSupportedException("provider mismatch");
}
// To avoid re-checking if the VM if attachable, we check if the descriptor
// is for a hotspot VM - these descriptors are created by the listVirtualMachines
// implementation which only returns a list of attachable VMs.
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
checkAttachPermission();
return new VirtualMachineImpl(this, vmd.id());
} else {
return attachVirtualMachine(vmd.id());
}
}
示例10: showProcessList
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
public void showProcessList()
{
List<VirtualMachineDescriptor> virtualMachineDescriptorList = VirtualMachine.list();
String version = null;
for (VirtualMachineDescriptor virtualMachineDescriptor : virtualMachineDescriptorList)
{
VirtualMachine virtualMachine = attach(virtualMachineDescriptor);
if (virtualMachine != null)
{
version = readSystemProperty(virtualMachine, "java.version");
}
logger.info("Show JVM : pid = {}, DisplayName = {}, Java Version = {}", virtualMachineDescriptor.id(), virtualMachineDescriptor.displayName(), version);
detach(virtualMachine);
}
}
示例11: attach
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
private VirtualMachine attach(VirtualMachineDescriptor virtualMachineDescriptor)
{
VirtualMachine virtualMachine = null;
try
{
virtualMachine = VirtualMachine.attach(virtualMachineDescriptor);
// Properties props = new Properties();
// props.put("com.sun.management.jmxremote.port", "5000");
// props.put("bootclasspath", "");
// virtualMachine.startManagementAgent(props);
}
catch (AttachNotSupportedException | IOException attachNotSupportedException)
{
logger.info(attachNotSupportedException);
}
return virtualMachine;
}
示例12: hasJMXServerInLocal
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
/**
* 獲取本地是否已開啟指定的JMX服務
* @param serverName
* @return
*/
public static boolean hasJMXServerInLocal(String serverName){
if(!StringUtils.isEmpty(serverName)){
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor desc : vms) {
File file = new File(desc.displayName());
if(file.exists()){
//java -jar 形式啟動的Java應用
if(file.toPath().getFileName().toString().equals(serverName)){
return true;
}
}else if(desc.displayName().contains(serverName)){
return true;
}
}
}
return false;
}
示例13: getVmDescByServerName
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
/**
* 獲取指定服務名的本地JMX VM 描述對象
* @param serverName
* @return
*/
public static List<VirtualMachineDescriptor> getVmDescByServerName(String serverName){
List<VirtualMachineDescriptor> vmDescList = new ArrayList<>();
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor desc : vms) {
File file = new File(desc.displayName());
if(file.exists()){
//java -jar 形式啟動的Java應用
if(file.toPath().getFileName().toString().equals(serverName)){
vmDescList.add(desc);
}
}else if(desc.displayName().contains(serverName)){
vmDescList.add(desc);
}
}
return vmDescList;
}
示例14: getConnectorAddress
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
private JMXConnectUrlInfo getConnectorAddress(VirtualMachineDescriptor desc){
if(AgentConfiguration.INSTANCE.isAgentJMXLocalConnect()){
String connectorAddress = AbstractJmxCommand.findJMXLocalUrlByProcessId(Integer.parseInt(desc.id()));
if(connectorAddress != null){
return new JMXConnectUrlInfo(connectorAddress);
}
}
JMXConnectUrlInfo jmxConnectUrlInfo = null;
try {
jmxConnectUrlInfo = AbstractJmxCommand.findJMXRemoteUrlByProcessId(Integer.parseInt(desc.id()), InetAddress.getLocalHost().getHostAddress());
if(jmxConnectUrlInfo != null){
log.info("JMX Remote URL:{}",jmxConnectUrlInfo);
}else if(!AgentConfiguration.INSTANCE.isAgentJMXLocalConnect()){
log.warn("應用未配置JMX Remote功能,請給應用配置JMX Remote");
}
} catch (UnknownHostException e) {
log.error("JMX連接本機地址獲取失敗",e);
}
return jmxConnectUrlInfo;
}
示例15: hasJMXServerInLocal
import com.sun.tools.attach.VirtualMachineDescriptor; //導入依賴的package包/類
/**
* 獲取本地是否已開啟指定的JMX服務
*
* @param serverName
* @return
*/
public static boolean hasJMXServerInLocal(String serverName) {
if (!StringUtils.isEmpty(serverName)) {
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor desc : vms) {
File file = new File(desc.displayName());
if (file.exists()) {
// java -jar 形式啟動的Java應用
if (file.toPath().getFileName().toString().equals(serverName)) {
return true;
}
} else if (desc.displayName().contains(serverName)) {
return true;
}
}
}
return false;
}