Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/attach/VirtualMachine.java
38920 views
1
/*
2
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.tools.attach;
27
28
import com.sun.tools.attach.spi.AttachProvider;
29
import java.util.ArrayList;
30
import java.util.List;
31
import java.util.Properties;
32
import java.io.IOException;
33
34
35
/**
36
* A Java virtual machine.
37
*
38
* <p> A <code>VirtualMachine</code> represents a Java virtual machine to which this
39
* Java virtual machine has attached. The Java virtual machine to which it is
40
* attached is sometimes called the <i>target virtual machine</i>, or <i>target VM</i>.
41
* An application (typically a tool such as a managemet console or profiler) uses a
42
* VirtualMachine to load an agent into the target VM. For example, a profiler tool
43
* written in the Java Language might attach to a running application and load its
44
* profiler agent to profile the running application. </p>
45
*
46
* <p> A VirtualMachine is obtained by invoking the {@link #attach(String) attach} method
47
* with an identifier that identifies the target virtual machine. The identifier is
48
* implementation-dependent but is typically the process identifier (or pid) in
49
* environments where each Java virtual machine runs in its own operating system process.
50
* Alternatively, a <code>VirtualMachine</code> instance is obtained by invoking the
51
* {@link #attach(VirtualMachineDescriptor) attach} method with a {@link
52
* com.sun.tools.attach.VirtualMachineDescriptor VirtualMachineDescriptor} obtained
53
* from the list of virtual machine descriptors returned by the {@link #list list} method.
54
* Once a reference to a virtual machine is obtained, the {@link #loadAgent loadAgent},
55
* {@link #loadAgentLibrary loadAgentLibrary}, and {@link #loadAgentPath loadAgentPath}
56
* methods are used to load agents into target virtual machine. The {@link
57
* #loadAgent loadAgent} method is used to load agents that are written in the Java
58
* Language and deployed in a {@link java.util.jar.JarFile JAR file}. (See
59
* {@link java.lang.instrument} for a detailed description on how these agents
60
* are loaded and started). The {@link #loadAgentLibrary loadAgentLibrary} and
61
* {@link #loadAgentPath loadAgentPath} methods are used to load agents that
62
* are deployed either in a dynamic library or statically linked into the VM and make use of the <a
63
* href="../../../../../../../../technotes/guides/jvmti/index.html">JVM Tools
64
* Interface</a>. </p>
65
*
66
* <p> In addition to loading agents a VirtualMachine provides read access to the
67
* {@link java.lang.System#getProperties() system properties} in the target VM.
68
* This can be useful in some environments where properties such as
69
* <code>java.home</code>, <code>os.name</code>, or <code>os.arch</code> are
70
* used to construct the path to agent that will be loaded into the target VM.
71
*
72
* <p> The following example demonstrates how VirtualMachine may be used:</p>
73
*
74
* <pre>
75
*
76
* // attach to target VM
77
* VirtualMachine vm = VirtualMachine.attach("2177");
78
*
79
* // start management agent
80
* Properties props = new Properties();
81
* props.put("com.sun.management.jmxremote.port", "5000");
82
* vm.startManagementAgent(props);
83
*
84
* // detach
85
* vm.detach();
86
*
87
* </pre>
88
*
89
* <p> In this example we attach to a Java virtual machine that is identified by
90
* the process identifier <code>2177</code>. Then the JMX management agent is
91
* started in the target process using the supplied arguments. Finally, the
92
* client detaches from the target VM. </p>
93
*
94
* <p> A VirtualMachine is safe for use by multiple concurrent threads. </p>
95
*
96
* @since 1.6
97
*/
98
99
@jdk.Exported
100
public abstract class VirtualMachine {
101
private AttachProvider provider;
102
private String id;
103
private volatile int hash; // 0 => not computed
104
105
/**
106
* Initializes a new instance of this class.
107
*
108
* @param provider
109
* The attach provider creating this class.
110
* @param id
111
* The abstract identifier that identifies the Java virtual machine.
112
*
113
* @throws NullPointerException
114
* If <code>provider</code> or <code>id</code> is <code>null</code>.
115
*/
116
protected VirtualMachine(AttachProvider provider, String id) {
117
if (provider == null) {
118
throw new NullPointerException("provider cannot be null");
119
}
120
if (id == null) {
121
throw new NullPointerException("id cannot be null");
122
}
123
this.provider = provider;
124
this.id = id;
125
}
126
127
/**
128
* Return a list of Java virtual machines.
129
*
130
* <p> This method returns a list of Java {@link
131
* com.sun.tools.attach.VirtualMachineDescriptor} elements.
132
* The list is an aggregation of the virtual machine
133
* descriptor lists obtained by invoking the {@link
134
* com.sun.tools.attach.spi.AttachProvider#listVirtualMachines
135
* listVirtualMachines} method of all installed
136
* {@link com.sun.tools.attach.spi.AttachProvider attach providers}.
137
* If there are no Java virtual machines known to any provider
138
* then an empty list is returned.
139
*
140
* @return The list of virtual machine descriptors.
141
*/
142
public static List<VirtualMachineDescriptor> list() {
143
ArrayList<VirtualMachineDescriptor> l =
144
new ArrayList<VirtualMachineDescriptor>();
145
List<AttachProvider> providers = AttachProvider.providers();
146
for (AttachProvider provider: providers) {
147
l.addAll(provider.listVirtualMachines());
148
}
149
return l;
150
}
151
152
/**
153
* Attaches to a Java virtual machine.
154
*
155
* <p> This method obtains the list of attach providers by invoking the
156
* {@link com.sun.tools.attach.spi.AttachProvider#providers()
157
* AttachProvider.providers()} method. It then iterates overs the list
158
* and invokes each provider's {@link
159
* com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
160
* attachVirtualMachine} method in turn. If a provider successfully
161
* attaches then the iteration terminates, and the VirtualMachine created
162
* by the provider that successfully attached is returned by this method.
163
* If the <code>attachVirtualMachine</code> method of all providers throws
164
* {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
165
* then this method also throws <code>AttachNotSupportedException</code>.
166
* This means that <code>AttachNotSupportedException</code> is thrown when
167
* the identifier provided to this method is invalid, or the identifier
168
* corresponds to a Java virtual machine that does not exist, or none
169
* of the providers can attach to it. This exception is also thrown if
170
* {@link com.sun.tools.attach.spi.AttachProvider#providers()
171
* AttachProvider.providers()} returns an empty list. </p>
172
*
173
* @param id
174
* The abstract identifier that identifies the Java virtual machine.
175
*
176
* @return A VirtualMachine representing the target VM.
177
*
178
* @throws SecurityException
179
* If a security manager has been installed and it denies
180
* {@link com.sun.tools.attach.AttachPermission AttachPermission}
181
* <tt>("attachVirtualMachine")</tt>, or another permission
182
* required by the implementation.
183
*
184
* @throws AttachNotSupportedException
185
* If the <code>attachVirtualmachine</code> method of all installed
186
* providers throws <code>AttachNotSupportedException</code>, or
187
* there aren't any providers installed.
188
*
189
* @throws IOException
190
* If an I/O error occurs
191
*
192
* @throws NullPointerException
193
* If <code>id</code> is <code>null</code>.
194
*/
195
public static VirtualMachine attach(String id)
196
throws AttachNotSupportedException, IOException
197
{
198
if (id == null) {
199
throw new NullPointerException("id cannot be null");
200
}
201
List<AttachProvider> providers = AttachProvider.providers();
202
if (providers.size() == 0) {
203
throw new AttachNotSupportedException("no providers installed");
204
}
205
AttachNotSupportedException lastExc = null;
206
for (AttachProvider provider: providers) {
207
try {
208
return provider.attachVirtualMachine(id);
209
} catch (AttachNotSupportedException x) {
210
lastExc = x;
211
}
212
}
213
throw lastExc;
214
}
215
216
/**
217
* Attaches to a Java virtual machine.
218
*
219
* <p> This method first invokes the {@link
220
* com.sun.tools.attach.VirtualMachineDescriptor#provider() provider()} method
221
* of the given virtual machine descriptor to obtain the attach provider. It
222
* then invokes the attach provider's {@link
223
* com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(VirtualMachineDescriptor)
224
* attachVirtualMachine} to attach to the target VM.
225
*
226
* @param vmd
227
* The virtual machine descriptor.
228
*
229
* @return A VirtualMachine representing the target VM.
230
*
231
* @throws SecurityException
232
* If a security manager has been installed and it denies
233
* {@link com.sun.tools.attach.AttachPermission AttachPermission}
234
* <tt>("attachVirtualMachine")</tt>, or another permission
235
* required by the implementation.
236
*
237
* @throws AttachNotSupportedException
238
* If the attach provider's <code>attachVirtualmachine</code>
239
* throws <code>AttachNotSupportedException</code>.
240
*
241
* @throws IOException
242
* If an I/O error occurs
243
*
244
* @throws NullPointerException
245
* If <code>vmd</code> is <code>null</code>.
246
*/
247
public static VirtualMachine attach(VirtualMachineDescriptor vmd)
248
throws AttachNotSupportedException, IOException
249
{
250
return vmd.provider().attachVirtualMachine(vmd);
251
}
252
253
/**
254
* Detach from the virtual machine.
255
*
256
* <p> After detaching from the virtual machine, any further attempt to invoke
257
* operations on that virtual machine will cause an {@link java.io.IOException
258
* IOException} to be thrown. If an operation (such as {@link #loadAgent
259
* loadAgent} for example) is in progress when this method is invoked then
260
* the behaviour is implementation dependent. In other words, it is
261
* implementation specific if the operation completes or throws
262
* <tt>IOException</tt>.
263
*
264
* <p> If already detached from the virtual machine then invoking this
265
* method has no effect. </p>
266
*
267
* @throws IOException
268
* If an I/O error occurs
269
*/
270
public abstract void detach() throws IOException;
271
272
/**
273
* Returns the provider that created this virtual machine.
274
*
275
* @return The provider that created this virtual machine.
276
*/
277
public final AttachProvider provider() {
278
return provider;
279
}
280
281
/**
282
* Returns the identifier for this Java virtual machine.
283
*
284
* @return The identifier for this Java virtual machine.
285
*/
286
public final String id() {
287
return id;
288
}
289
290
/**
291
* Loads an agent library.
292
*
293
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
294
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
295
* A JVM TI agent is deployed in a platform specific manner but it is typically the
296
* platform equivalent of a dynamic library. Alternatively, it may be statically linked into the VM.
297
* This method causes the given agent library to be loaded into the target
298
* VM (if not already loaded or if not statically linked into the VM).
299
* It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
300
* or, for a statically linked agent named 'L', the <code>Agent_OnAttach_L</code> function
301
* as specified in the
302
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
303
* Interface</a> specification. Note that the <code>Agent_OnAttach[_L]</code>
304
* function is invoked even if the agent library was loaded prior to invoking
305
* this method.
306
*
307
* <p> The agent library provided is the name of the agent library. It is interpreted
308
* in the target virtual machine in an implementation-dependent manner. Typically an
309
* implementation will expand the library name into an operating system specific file
310
* name. For example, on UNIX systems, the name <tt>L</tt> might be expanded to
311
* <tt>libL.so</tt>, and located using the search path specified by the
312
* <tt>LD_LIBRARY_PATH</tt> environment variable. If the agent named 'L' is
313
* statically linked into the VM then the VM must export a function named
314
* <code>Agent_OnAttach_L</code>.</p>
315
*
316
* <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
317
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
318
* thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
319
* obtained by invoking the {@link
320
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
321
* method on the exception. </p>
322
*
323
* @param agentLibrary
324
* The name of the agent library.
325
*
326
* @param options
327
* The options to provide to the <code>Agent_OnAttach[_L]</code>
328
* function (can be <code>null</code>).
329
*
330
* @throws AgentLoadException
331
* If the agent library does not exist, the agent library is not
332
* statically linked with the VM, or the agent library cannot be
333
* loaded for another reason.
334
*
335
* @throws AgentInitializationException
336
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
337
*
338
* @throws IOException
339
* If an I/O error occurs
340
*
341
* @throws NullPointerException
342
* If <code>agentLibrary</code> is <code>null</code>.
343
*
344
* @see com.sun.tools.attach.AgentInitializationException#returnValue()
345
*/
346
public abstract void loadAgentLibrary(String agentLibrary, String options)
347
throws AgentLoadException, AgentInitializationException, IOException;
348
349
/**
350
* Loads an agent library.
351
*
352
* <p> This convenience method works as if by invoking:
353
*
354
* <blockquote><tt>
355
* {@link #loadAgentLibrary(String, String) loadAgentLibrary}(agentLibrary,&nbsp;null);
356
* </tt></blockquote>
357
*
358
* @param agentLibrary
359
* The name of the agent library.
360
*
361
* @throws AgentLoadException
362
* If the agent library does not exist, the agent library is not
363
* statically linked with the VM, or the agent library cannot be
364
* loaded for another reason.
365
*
366
* @throws AgentInitializationException
367
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
368
*
369
* @throws IOException
370
* If an I/O error occurs
371
*
372
* @throws NullPointerException
373
* If <code>agentLibrary</code> is <code>null</code>.
374
*/
375
public void loadAgentLibrary(String agentLibrary)
376
throws AgentLoadException, AgentInitializationException, IOException
377
{
378
loadAgentLibrary(agentLibrary, null);
379
}
380
381
/**
382
* Load a native agent library by full pathname.
383
*
384
* <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
385
* TI</a> client is called an <i>agent</i>. It is developed in a native language.
386
* A JVM TI agent is deployed in a platform specific manner but it is typically the
387
* platform equivalent of a dynamic library. Alternatively, the native
388
* library specified by the agentPath parameter may be statically
389
* linked with the VM. The parsing of the agentPath parameter into
390
* a statically linked library name is done in a platform
391
* specific manner in the VM. For example, in UNIX, an agentPath parameter
392
* of <code>/a/b/libL.so</code> would name a library 'L'.
393
*
394
* See the JVM TI Specification for more details.
395
*
396
* This method causes the given agent library to be loaded into the target
397
* VM (if not already loaded or if not statically linked into the VM).
398
* It then causes the target VM to invoke the <code>Agent_OnAttach</code>
399
* function or, for a statically linked agent named 'L', the
400
* <code>Agent_OnAttach_L</code> function as specified in the
401
* <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
402
* Interface</a> specification.
403
* Note that the <code>Agent_OnAttach[_L]</code>
404
* function is invoked even if the agent library was loaded prior to invoking
405
* this method.
406
*
407
* <p> The agent library provided is the absolute path from which to load the
408
* agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
409
* is not expanded in the target virtual machine. </p>
410
*
411
* <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
412
* an error then an {@link com.sun.tools.attach.AgentInitializationException} is
413
* thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
414
* obtained by invoking the {@link
415
* com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
416
* method on the exception. </p>
417
*
418
* @param agentPath
419
* The full path of the agent library.
420
*
421
* @param options
422
* The options to provide to the <code>Agent_OnAttach[_L]</code>
423
* function (can be <code>null</code>).
424
*
425
* @throws AgentLoadException
426
* If the agent library does not exist, the agent library is not
427
* statically linked with the VM, or the agent library cannot be
428
* loaded for another reason.
429
*
430
* @throws AgentInitializationException
431
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
432
*
433
* @throws IOException
434
* If an I/O error occurs
435
*
436
* @throws NullPointerException
437
* If <code>agentPath</code> is <code>null</code>.
438
*
439
* @see com.sun.tools.attach.AgentInitializationException#returnValue()
440
*/
441
public abstract void loadAgentPath(String agentPath, String options)
442
throws AgentLoadException, AgentInitializationException, IOException;
443
444
/**
445
* Load a native agent library by full pathname.
446
*
447
* <p> This convenience method works as if by invoking:
448
*
449
* <blockquote><tt>
450
* {@link #loadAgentPath(String, String) loadAgentPath}(agentLibrary,&nbsp;null);
451
* </tt></blockquote>
452
*
453
* @param agentPath
454
* The full path to the agent library.
455
*
456
* @throws AgentLoadException
457
* If the agent library does not exist, the agent library is not
458
* statically linked with the VM, or the agent library cannot be
459
* loaded for another reason.
460
*
461
* @throws AgentInitializationException
462
* If the <code>Agent_OnAttach[_L]</code> function returns an error.
463
*
464
* @throws IOException
465
* If an I/O error occurs
466
*
467
* @throws NullPointerException
468
* If <code>agentPath</code> is <code>null</code>.
469
*/
470
public void loadAgentPath(String agentPath)
471
throws AgentLoadException, AgentInitializationException, IOException
472
{
473
loadAgentPath(agentPath, null);
474
}
475
476
477
/**
478
* Loads an agent.
479
*
480
* <p> The agent provided to this method is a path name to a JAR file on the file
481
* system of the target virtual machine. This path is passed to the target virtual
482
* machine where it is interpreted. The target virtual machine attempts to start
483
* the agent as specified by the {@link java.lang.instrument} specification.
484
* That is, the specified JAR file is added to the system class path (of the target
485
* virtual machine), and the <code>agentmain</code> method of the agent class, specified
486
* by the <code>Agent-Class</code> attribute in the JAR manifest, is invoked. This
487
* method completes when the <code>agentmain</code> method completes.
488
*
489
* @param agent
490
* Path to the JAR file containing the agent.
491
*
492
* @param options
493
* The options to provide to the agent's <code>agentmain</code>
494
* method (can be <code>null</code>).
495
*
496
* @throws AgentLoadException
497
* If the agent does not exist, or cannot be started in the manner
498
* specified in the {@link java.lang.instrument} specification.
499
*
500
* @throws AgentInitializationException
501
* If the <code>agentmain</code> throws an exception
502
*
503
* @throws IOException
504
* If an I/O error occurs
505
*
506
* @throws NullPointerException
507
* If <code>agent</code> is <code>null</code>.
508
*/
509
public abstract void loadAgent(String agent, String options)
510
throws AgentLoadException, AgentInitializationException, IOException;
511
512
/**
513
* Loads an agent.
514
*
515
* <p> This convenience method works as if by invoking:
516
*
517
* <blockquote><tt>
518
* {@link #loadAgent(String, String) loadAgent}(agent,&nbsp;null);
519
* </tt></blockquote>
520
*
521
* @param agent
522
* Path to the JAR file containing the agent.
523
*
524
* @throws AgentLoadException
525
* If the agent does not exist, or cannot be started in the manner
526
* specified in the {@link java.lang.instrument} specification.
527
*
528
* @throws AgentInitializationException
529
* If the <code>agentmain</code> throws an exception
530
*
531
* @throws IOException
532
* If an I/O error occurs
533
*
534
* @throws NullPointerException
535
* If <code>agent</code> is <code>null</code>.
536
*/
537
public void loadAgent(String agent)
538
throws AgentLoadException, AgentInitializationException, IOException
539
{
540
loadAgent(agent, null);
541
}
542
543
/**
544
* Returns the current system properties in the target virtual machine.
545
*
546
* <p> This method returns the system properties in the target virtual
547
* machine. Properties whose key or value is not a <tt>String</tt> are
548
* omitted. The method is approximately equivalent to the invocation of the
549
* method {@link java.lang.System#getProperties System.getProperties}
550
* in the target virtual machine except that properties with a key or
551
* value that is not a <tt>String</tt> are not included.
552
*
553
* <p> This method is typically used to decide which agent to load into
554
* the target virtual machine with {@link #loadAgent loadAgent}, or
555
* {@link #loadAgentLibrary loadAgentLibrary}. For example, the
556
* <code>java.home</code> or <code>user.dir</code> properties might be
557
* use to create the path to the agent library or JAR file.
558
*
559
* @return The system properties
560
*
561
* @throws AttachOperationFailedException
562
* If the target virtual machine is unable to complete the
563
* attach operation. A more specific error message will be
564
* given by {@link AttachOperationFailedException#getMessage()}.
565
*
566
* @throws IOException
567
* If an I/O error occurs, a communication error for example,
568
* that cannot be identified as an error to indicate that the
569
* operation failed in the target VM.
570
*
571
* @see java.lang.System#getProperties
572
* @see #loadAgentLibrary
573
* @see #loadAgent
574
*/
575
public abstract Properties getSystemProperties() throws IOException;
576
577
/**
578
* Returns the current <i>agent properties</i> in the target virtual
579
* machine.
580
*
581
* <p> The target virtual machine can maintain a list of properties on
582
* behalf of agents. The manner in which this is done, the names of the
583
* properties, and the types of values that are allowed, is implementation
584
* specific. Agent properties are typically used to store communication
585
* end-points and other agent configuration details. For example, a debugger
586
* agent might create an agent property for its transport address.
587
*
588
* <p> This method returns the agent properties whose key and value is a
589
* <tt>String</tt>. Properties whose key or value is not a <tt>String</tt>
590
* are omitted. If there are no agent properties maintained in the target
591
* virtual machine then an empty property list is returned.
592
*
593
* @return The agent properties
594
*
595
* @throws AttachOperationFailedException
596
* If the target virtual machine is unable to complete the
597
* attach operation. A more specific error message will be
598
* given by {@link AttachOperationFailedException#getMessage()}.
599
*
600
* @throws IOException
601
* If an I/O error occurs, a communication error for example,
602
* that cannot be identified as an error to indicate that the
603
* operation failed in the target VM.
604
*/
605
public abstract Properties getAgentProperties() throws IOException;
606
607
/**
608
* Starts the JMX management agent in the target virtual machine.
609
*
610
* <p> The configuration properties are the same as those specified on
611
* the command line when starting the JMX management agent. In the same
612
* way as on the command line, you need to specify at least the
613
* {@code com.sun.management.jmxremote.port} property.
614
*
615
* <p> See the online documentation for <a
616
* href="../../../../../../../../technotes/guides/management/agent.html">
617
* Monitoring and Management Using JMX Technology</a> for further details.
618
*
619
* @param agentProperties
620
* A Properties object containing the configuration properties
621
* for the agent.
622
*
623
* @throws AttachOperationFailedException
624
* If the target virtual machine is unable to complete the
625
* attach operation. A more specific error message will be
626
* given by {@link AttachOperationFailedException#getMessage()}.
627
*
628
* @throws IOException
629
* If an I/O error occurs, a communication error for example,
630
* that cannot be identified as an error to indicate that the
631
* operation failed in the target VM.
632
*
633
* @throws IllegalArgumentException
634
* If keys or values in agentProperties are invalid.
635
*
636
* @throws NullPointerException
637
* If agentProperties is null.
638
*
639
* @since 1.8
640
*/
641
public abstract void startManagementAgent(Properties agentProperties) throws IOException;
642
643
/**
644
* Starts the local JMX management agent in the target virtual machine.
645
*
646
* <p> See the online documentation for <a
647
* href="../../../../../../../../technotes/guides/management/agent.html">
648
* Monitoring and Management Using JMX Technology</a> for further details.
649
*
650
* @return The String representation of the local connector's service address.
651
* The value can be parsed by the
652
* {@link javax.management.remote.JMXServiceURL#JMXServiceURL(String)}
653
* constructor.
654
*
655
* @throws AttachOperationFailedException
656
* If the target virtual machine is unable to complete the
657
* attach operation. A more specific error message will be
658
* given by {@link AttachOperationFailedException#getMessage()}.
659
*
660
* @throws IOException
661
* If an I/O error occurs, a communication error for example,
662
* that cannot be identified as an error to indicate that the
663
* operation failed in the target VM.
664
*
665
* @since 1.8
666
*/
667
public abstract String startLocalManagementAgent() throws IOException;
668
669
/**
670
* Returns a hash-code value for this VirtualMachine. The hash
671
* code is based upon the VirtualMachine's components, and satifies
672
* the general contract of the {@link java.lang.Object#hashCode()
673
* Object.hashCode} method.
674
*
675
* @return A hash-code value for this virtual machine
676
*/
677
public int hashCode() {
678
if (hash != 0) {
679
return hash;
680
}
681
hash = provider.hashCode() * 127 + id.hashCode();
682
return hash;
683
}
684
685
/**
686
* Tests this VirtualMachine for equality with another object.
687
*
688
* <p> If the given object is not a VirtualMachine then this
689
* method returns <tt>false</tt>. For two VirtualMachines to
690
* be considered equal requires that they both reference the same
691
* provider, and their {@link VirtualMachineDescriptor#id() identifiers} are equal. </p>
692
*
693
* <p> This method satisfies the general contract of the {@link
694
* java.lang.Object#equals(Object) Object.equals} method. </p>
695
*
696
* @param ob The object to which this object is to be compared
697
*
698
* @return <tt>true</tt> if, and only if, the given object is
699
* a VirtualMachine that is equal to this
700
* VirtualMachine.
701
*/
702
public boolean equals(Object ob) {
703
if (ob == this)
704
return true;
705
if (!(ob instanceof VirtualMachine))
706
return false;
707
VirtualMachine other = (VirtualMachine)ob;
708
if (other.provider() != this.provider()) {
709
return false;
710
}
711
if (!other.id().equals(this.id())) {
712
return false;
713
}
714
return true;
715
}
716
717
/**
718
* Returns the string representation of the <code>VirtualMachine</code>.
719
*/
720
public String toString() {
721
return provider.toString() + ": " + id;
722
}
723
}
724
725