本文整理匯總了Java中com.sun.tools.attach.AttachNotSupportedException類的典型用法代碼示例。如果您正苦於以下問題:Java AttachNotSupportedException類的具體用法?Java AttachNotSupportedException怎麽用?Java AttachNotSupportedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AttachNotSupportedException類屬於com.sun.tools.attach包,在下文中一共展示了AttachNotSupportedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String[] args) throws IOException,
AttachNotSupportedException, AgentLoadException,
AgentInitializationException, InterruptedException {
// 獲取當前jvm的進程pid
String pid = ManagementFactory.getRuntimeMXBean().getName();
int indexOf = pid.indexOf('@');
if (indexOf > 0) {
pid = pid.substring(0, indexOf);
}
System.out.println("當前JVM Process ID: " + pid);
// 獲取當前jvm
VirtualMachine vm = VirtualMachine.attach(pid);
// 當前jvm加載代理jar包,參數1是jar包路徑地址,參數2是給jar包代理類傳遞的參數
vm.loadAgent("D:/123.jar", "my agent:123.jar");
Thread.sleep(1000);
vm.detach();
}
示例2: main
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String[] args) throws AttachNotSupportedException,
IOException, AgentLoadException, AgentInitializationException,
InterruptedException {
VirtualMachine vm=AgentUtil.getCurrentVm();
//先載入agent
vm.loadAgent("d:/springloaded-1.2.1.RELEASE.jar","myagent");
System.out.println("加載agent成功");
vm.detach();
TestSpringLoacedClass t1=new TestSpringLoacedClass();
for(int i=0;i<10000;i++)
{
TestSpringLoacedClass t2=new TestSpringLoacedClass();
t1.say2();
t2.say2();
Thread.sleep(1000);
}
}
示例3: attach
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static VirtualMachine attach(String pid) {
try {
return VirtualMachine.attach(pid);
} catch (Exception x) {
String msg = x.getMessage();
if (msg != null) {
System.err.println(pid + ": " + msg);
} else {
x.printStackTrace();
}
if ((x instanceof AttachNotSupportedException) && haveSA()) {
System.err.println("The -F option can be used when the " +
"target process is not responding");
}
System.exit(1);
return null; // keep compiler happy
}
}
示例4: loadManagementAgent
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private void loadManagementAgent() throws IOException {
VirtualMachine vm = null;
String name = String.valueOf(vmid);
try {
vm = VirtualMachine.attach(name);
} catch (AttachNotSupportedException x) {
IOException ioe = new IOException(x.getMessage());
ioe.initCause(x);
throw ioe;
}
vm.startLocalManagementAgent();
// get the connector address
Properties agentProps = vm.getAgentProperties();
address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
vm.detach();
}
示例5: attachVirtualMachine
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的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.AttachNotSupportedException; //導入依賴的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.AttachNotSupportedException; //導入依賴的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.AttachNotSupportedException; //導入依賴的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: main
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
throw new RuntimeException("Test configuration error - no security manager set");
}
String pid = args[0];
boolean shouldFail = Boolean.parseBoolean(args[1]);
try {
VirtualMachine.attach(pid).detach();
if (shouldFail) {
throw new RuntimeException("SecurityException should be thrown");
}
System.out.println(" - attached to target VM as expected.");
} catch (Exception x) {
// AttachNotSupportedException thrown when no providers can be loaded
if (shouldFail && ((x instanceof AttachNotSupportedException) ||
(x instanceof SecurityException))) {
System.out.println(" - exception thrown as expected.");
} else {
throw x;
}
}
}
示例10: attach
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
public static void attach(Class<? extends Agent> agentClass, List<Class<?>> classes, File... libs) throws AgentInstantiationException, AttachNotSupportedException, AgentLoadException, AgentInitializationException, NotFoundException, CannotCompileException, IOException {
try {
Agent agent = agentClass.newInstance();
VirtualMachine vm;
switch (agent.type()) {
case MAIN:
vm = get1(agent.target());
break;
case PID:
vm = get2(agent.target());
break;
default:
vm = null;
break;
}
load(vm, agent, classes, libs);
} catch (IllegalAccessException | InstantiationException e) {
throw new AgentInstantiationException();
}
}
示例11: executeCommandForPid
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static void executeCommandForPid(String pid, String command, Object ... args)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
VirtualMachine vm = VirtualMachine.attach(pid);
// Cast to HotSpotVirtualMachine as this is an
// implementation specific method.
HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
try (InputStream in = hvm.executeCommand(command, args)) {
// read to EOF and just print output
byte b[] = new byte[256];
int n;
do {
n = in.read(b);
if (n > 0) {
String s = new String(b, 0, n, "UTF-8");
System.out.print(s);
}
} while (n > 0);
}
vm.detach();
}
示例12: histo
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
private static void histo(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
String liveopt = "-all";
if (options.equals("") || options.equals("all")) {
// pass
}
else if (options.equals("live")) {
liveopt = "-live";
}
else {
usage(1);
}
// inspectHeap is not the same as jcmd GC.class_histogram
executeCommandForPid(pid, "inspectheap", liveopt);
}
示例13: HotSpotVirtualMachine
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
HotSpotVirtualMachine(AttachProvider provider, String id)
throws AttachNotSupportedException, IOException
{
super(provider, id);
int pid;
try {
pid = Integer.parseInt(id);
} catch (NumberFormatException e) {
throw new AttachNotSupportedException("Invalid process identifier");
}
// The tool should be a different VM to the target. This check will
// eventually be enforced by the target VM.
if (!ALLOW_ATTACH_SELF && (pid == 0 || pid == CURRENT_PID)) {
throw new IOException("Can not attach to current VM");
}
}
示例14: attachVirtualMachine
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的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());
}
}
示例15: getTaskPort
import com.sun.tools.attach.AttachNotSupportedException; //導入依賴的package包/類
@Override
public int getTaskPort(BTraceTask task) {
VirtualMachine vm = null;
try {
vm = attach(valueOf(task.getPid()));
String portStr = vm.getSystemProperties().getProperty(PORT_PROPERTY);
return portStr != null ? parseInt(portStr) : findFreePort();
} catch (AttachNotSupportedException | IOException ex) {
getLogger(PortLocatorImpl.class.getName()).log(SEVERE, null, ex);
} finally {
if (vm != null) {
try {
vm.detach();
} catch (IOException e) {
LOGGER.log(SEVERE, null, e);
}
}
}
return findFreePort();
}