author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45714 | jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/GenericAttachingConnector.java@1820d351198d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11277
diff
changeset
|
2 |
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.jdi; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.util.Map; |
|
30 |
||
31 |
import com.sun.jdi.Bootstrap; |
|
32 |
import com.sun.jdi.VirtualMachine; |
|
45714 | 33 |
import com.sun.jdi.connect.AttachingConnector; |
34 |
import com.sun.jdi.connect.Connector; |
|
35 |
import com.sun.jdi.connect.IllegalConnectorArgumentsException; |
|
36 |
import com.sun.jdi.connect.Transport; |
|
37 |
import com.sun.jdi.connect.spi.Connection; |
|
38 |
import com.sun.jdi.connect.spi.TransportService; |
|
2 | 39 |
|
40 |
/* |
|
41 |
* An AttachingConnector to attach to a running VM using any |
|
42 |
* TransportService. |
|
43 |
*/ |
|
44 |
||
45 |
public class GenericAttachingConnector |
|
46 |
extends ConnectorImpl implements AttachingConnector |
|
47 |
{ |
|
48 |
/* |
|
49 |
* The arguments that this connector supports |
|
50 |
*/ |
|
51 |
static final String ARG_ADDRESS = "address"; |
|
52 |
static final String ARG_TIMEOUT = "timeout"; |
|
53 |
||
54 |
TransportService transportService; |
|
55 |
Transport transport; |
|
56 |
||
57 |
/* |
|
58 |
* Initialize a new instance of this connector. The connector |
|
59 |
* encapsulates a transport service and optionally has an |
|
60 |
* "address" connector argument. |
|
61 |
*/ |
|
62 |
private GenericAttachingConnector(TransportService ts, |
|
63 |
boolean addAddressArgument) |
|
64 |
{ |
|
65 |
transportService = ts; |
|
66 |
transport = new Transport() { |
|
45714 | 67 |
public String name() { |
68 |
// delegate name to the transport service |
|
69 |
return transportService.name(); |
|
70 |
} |
|
71 |
}; |
|
2 | 72 |
|
73 |
if (addAddressArgument) { |
|
74 |
addStringArgument( |
|
75 |
ARG_ADDRESS, |
|
76 |
getString("generic_attaching.address.label"), |
|
77 |
getString("generic_attaching.address"), |
|
78 |
"", |
|
79 |
true); |
|
80 |
} |
|
81 |
||
82 |
addIntegerArgument( |
|
83 |
ARG_TIMEOUT, |
|
84 |
getString("generic_attaching.timeout.label"), |
|
85 |
getString("generic_attaching.timeout"), |
|
86 |
"", |
|
87 |
false, |
|
88 |
0, Integer.MAX_VALUE); |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Initializes a new instance of this connector. This constructor |
|
93 |
* is used when sub-classing - the resulting connector will have |
|
94 |
* a "timeout" connector argument. |
|
95 |
*/ |
|
96 |
protected GenericAttachingConnector(TransportService ts) { |
|
97 |
this(ts, false); |
|
98 |
} |
|
99 |
||
100 |
/* |
|
101 |
* Create an instance of this connector. The resulting AttachingConnector |
|
102 |
* will have address and timeout connector arguments. |
|
103 |
*/ |
|
104 |
public static GenericAttachingConnector create(TransportService ts) { |
|
105 |
return new GenericAttachingConnector(ts, true); |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Attach to a target VM using the specified address and Connector arguments. |
|
110 |
*/ |
|
11277 | 111 |
public VirtualMachine attach(String address, Map<String, ? extends Connector.Argument> args) |
2 | 112 |
throws IOException, IllegalConnectorArgumentsException |
113 |
{ |
|
114 |
String ts = argument(ARG_TIMEOUT, args).value(); |
|
115 |
int timeout = 0; |
|
116 |
if (ts.length() > 0) { |
|
117 |
timeout = Integer.decode(ts).intValue(); |
|
118 |
} |
|
119 |
Connection connection = transportService.attach(address, timeout, 0); |
|
120 |
return Bootstrap.virtualMachineManager().createVirtualMachine(connection); |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* Attach to a target VM using the specified arguments - the address |
|
125 |
* of the target VM is specified by the <code>address</code> connector |
|
126 |
* argument. |
|
127 |
*/ |
|
45714 | 128 |
public VirtualMachine attach(Map<String, ? extends Connector.Argument> args) |
2 | 129 |
throws IOException, IllegalConnectorArgumentsException |
130 |
{ |
|
131 |
String address = argument(ARG_ADDRESS, args).value(); |
|
132 |
return attach(address, args); |
|
133 |
} |
|
134 |
||
135 |
public String name() { |
|
136 |
return transport.name() + "Attach"; |
|
137 |
} |
|
138 |
||
139 |
public String description() { |
|
140 |
return transportService.description(); |
|
141 |
} |
|
142 |
||
143 |
public Transport transport() { |
|
144 |
return transport; |
|
145 |
} |
|
146 |
} |