author | mchung |
Tue, 31 Jan 2017 20:06:32 -0800 | |
changeset 43494 | 11801b2ff456 |
parent 25859 | jdk/src/java.management/share/classes/sun/management/jdp/JdpJmxPacket.java@3317bb8137f4 |
permissions | -rw-r--r-- |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
1 |
/* |
15653
ce470531e852
8007536: Incorrect copyright header in JDP files
dsamersoff
parents:
15531
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
4 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
15653
ce470531e852
8007536: Incorrect copyright header in JDP files
dsamersoff
parents:
15531
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
ce470531e852
8007536: Incorrect copyright header in JDP files
dsamersoff
parents:
15531
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
ce470531e852
8007536: Incorrect copyright header in JDP files
dsamersoff
parents:
15531
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
10 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
15 |
* accompanied this code). |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
16 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
20 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
23 |
* questions. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
24 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
25 |
package sun.management.jdp; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
26 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
27 |
import java.io.IOException; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
28 |
import java.util.HashMap; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
29 |
import java.util.Map; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
30 |
import java.util.Objects; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
31 |
import java.util.UUID; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
32 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
33 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
34 |
* A packet to broadcasts JMX URL |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
35 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
36 |
* Fields: |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
37 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
38 |
* <ul> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
39 |
* <li>UUID - broadcast session ID, changed every time when we start/stop |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
40 |
* discovery service</li> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
41 |
* <li>JMX_URL - URL to connect to JMX service</li> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
42 |
* <li>MAIN_CLASS - optional name of main class, filled from sun.java.command stripped for |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
43 |
* security reason to first space</li> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
44 |
* <li>INSTANCE_NAME - optional custom name of particular instance as provided by customer</li> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
45 |
* </ul> |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
46 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
47 |
public final class JdpJmxPacket |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
48 |
extends JdpGenericPacket |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
49 |
implements JdpPacket { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
50 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
51 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
52 |
* Session ID |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
53 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
54 |
public final static String UUID_KEY = "DISCOVERABLE_SESSION_UUID"; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
55 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
56 |
* Name of main class |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
57 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
58 |
public final static String MAIN_CLASS_KEY = "MAIN_CLASS"; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
59 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
60 |
* JMX service URL |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
61 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
62 |
public final static String JMX_SERVICE_URL_KEY = "JMX_SERVICE_URL"; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
63 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
64 |
* Name of Java instance |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
65 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
66 |
public final static String INSTANCE_NAME_KEY = "INSTANCE_NAME"; |
21295
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
67 |
/** |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
68 |
* PID of java process, optional presented if it could be obtained |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
69 |
*/ |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
70 |
public final static String PROCESS_ID_KEY = "PROCESS_ID"; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
71 |
/** |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
72 |
* Hostname of rmi server, optional presented if user overrides rmi server |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
73 |
* hostname by java.rmi.server.hostname property |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
74 |
*/ |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
75 |
public final static String RMI_HOSTNAME_KEY = "RMI_HOSTNAME"; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
76 |
/** |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
77 |
* Configured broadcast interval, optional |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
78 |
*/ |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
79 |
public final static String BROADCAST_INTERVAL_KEY = "BROADCAST_INTERVAL"; |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
80 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
81 |
private UUID id; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
82 |
private String mainClass; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
83 |
private String jmxServiceUrl; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
84 |
private String instanceName; |
21295
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
85 |
private String processId; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
86 |
private String rmiHostname; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
87 |
private String broadcastInterval; |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
88 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
89 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
90 |
* Create new instance from user provided data. Set mandatory fields |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
91 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
92 |
* @param id - java instance id |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
93 |
* @param jmxServiceUrl - JMX service url |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
94 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
95 |
public JdpJmxPacket(UUID id, String jmxServiceUrl) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
96 |
this.id = id; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
97 |
this.jmxServiceUrl = jmxServiceUrl; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
98 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
99 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
100 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
101 |
* Create new instance from network data Parse packet and set fields. |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
102 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
103 |
* @param data - raw packet data as it came from a Net |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
104 |
* @throws JdpException |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
105 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
106 |
public JdpJmxPacket(byte[] data) |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
107 |
throws JdpException { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
108 |
JdpPacketReader reader; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
109 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
110 |
reader = new JdpPacketReader(data); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
111 |
Map<String, String> p = reader.getDiscoveryDataAsMap(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
112 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
113 |
String sId = p.get(UUID_KEY); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
114 |
this.id = (sId == null) ? null : UUID.fromString(sId); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
115 |
this.jmxServiceUrl = p.get(JMX_SERVICE_URL_KEY); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
116 |
this.mainClass = p.get(MAIN_CLASS_KEY); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
117 |
this.instanceName = p.get(INSTANCE_NAME_KEY); |
21295
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
118 |
this.processId = p.get(PROCESS_ID_KEY); |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
119 |
this.rmiHostname = p.get(RMI_HOSTNAME_KEY); |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
120 |
this.broadcastInterval = p.get(BROADCAST_INTERVAL_KEY); |
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
121 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
122 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
123 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
124 |
* Set main class field |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
125 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
126 |
* @param mainClass - main class of running app |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
127 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
128 |
public void setMainClass(String mainClass) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
129 |
this.mainClass = mainClass; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
130 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
131 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
132 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
133 |
* Set instance name field |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
134 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
135 |
* @param instanceName - name of instance as provided by customer |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
136 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
137 |
public void setInstanceName(String instanceName) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
138 |
this.instanceName = instanceName; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
139 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
140 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
141 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
142 |
* @return id of discovery session |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
143 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
144 |
public UUID getId() { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
145 |
return id; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
146 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
147 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
148 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
149 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
150 |
* @return main class field |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
151 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
152 |
public String getMainClass() { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
153 |
return mainClass; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
154 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
155 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
156 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
157 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
158 |
* @return JMX service URL |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
159 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
160 |
public String getJmxServiceUrl() { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
161 |
return jmxServiceUrl; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
162 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
163 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
164 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
165 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
166 |
* @return instance name |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
167 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
168 |
public String getInstanceName() { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
169 |
return instanceName; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
170 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
171 |
|
21295
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
172 |
public String getProcessId() { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
173 |
return processId; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
174 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
175 |
|
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
176 |
public void setProcessId(String processId) { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
177 |
this.processId = processId; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
178 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
179 |
|
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
180 |
public String getRmiHostname() { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
181 |
return rmiHostname; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
182 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
183 |
|
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
184 |
public void setRmiHostname(String rmiHostname) { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
185 |
this.rmiHostname = rmiHostname; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
186 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
187 |
|
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
188 |
public String getBroadcastInterval() { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
189 |
return broadcastInterval; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
190 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
191 |
|
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
192 |
public void setBroadcastInterval(String broadcastInterval) { |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
193 |
this.broadcastInterval = broadcastInterval; |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
194 |
} |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
195 |
|
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
196 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
197 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
198 |
* @return assembled packet ready to be sent across a Net |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
199 |
* @throws IOException |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
200 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
201 |
@Override |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
202 |
public byte[] getPacketData() throws IOException { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
203 |
// Assemble packet from fields to byte array |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
204 |
JdpPacketWriter writer; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
205 |
writer = new JdpPacketWriter(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
206 |
writer.addEntry(UUID_KEY, (id == null) ? null : id.toString()); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
207 |
writer.addEntry(MAIN_CLASS_KEY, mainClass); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
208 |
writer.addEntry(JMX_SERVICE_URL_KEY, jmxServiceUrl); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
209 |
writer.addEntry(INSTANCE_NAME_KEY, instanceName); |
21295
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
210 |
writer.addEntry(PROCESS_ID_KEY, processId); |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
211 |
writer.addEntry(RMI_HOSTNAME_KEY, rmiHostname); |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
212 |
writer.addEntry(BROADCAST_INTERVAL_KEY, broadcastInterval); |
5c73446feb1f
8004213: JDP packet needs pid, broadcast interval and rmi server hostname fields
dsamersoff
parents:
15653
diff
changeset
|
213 |
|
15531
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
214 |
return writer.getPacketBytes(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
215 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
216 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
217 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
218 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
219 |
* @return packet hash code |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
220 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
221 |
@Override |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
222 |
public int hashCode() { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
223 |
int hash = 1; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
224 |
hash = hash * 31 + id.hashCode(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
225 |
hash = hash * 31 + jmxServiceUrl.hashCode(); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
226 |
return hash; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
227 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
228 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
229 |
/** |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
230 |
* Compare two packets |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
231 |
* |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
232 |
* @param o - packet to compare |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
233 |
* @return either packet equals or not |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
234 |
*/ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
235 |
@Override |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
236 |
public boolean equals(Object o) { |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
237 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
238 |
if (o == null || ! (o instanceof JdpJmxPacket) ){ |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
239 |
return false; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
240 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
241 |
|
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
242 |
JdpJmxPacket p = (JdpJmxPacket) o; |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
243 |
return Objects.equals(id, p.getId()) && Objects.equals(jmxServiceUrl, p.getJmxServiceUrl()); |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
244 |
} |
071efc9f31ad
8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents:
diff
changeset
|
245 |
} |