Produced by Araxis Merge on 9/25/2018 2:13:28 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\tools\jconsole | ProxyClient.java | Mon Jan 22 14:46:56 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\tools\jconsole | ProxyClient.java | Wed Sep 12 18:01:10 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 2114 |
Changed | 2 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 200 4, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package su n.tools.jc onsole; | |
27 | ||
28 | import com .sun.manag ement.HotS potDiagnos ticMXBean; | |
29 | import com .sun.tools .jconsole. JConsoleCo ntext; | |
30 | import jav a.beans.Pr opertyChan geListener ; | |
31 | import jav a.beans.Pr opertyChan geEvent; | |
32 | import jav a.io.IOExc eption; | |
33 | import jav a.lang.man agement.*; | |
34 | import sta tic java.l ang.manage ment.Manag ementFacto ry.*; | |
35 | import jav a.lang.ref .WeakRefer ence; | |
36 | import jav a.lang.ref lect.*; | |
37 | import jav a.rmi.*; | |
38 | import jav a.rmi.regi stry.*; | |
39 | import jav a.rmi.serv er.*; | |
40 | import jav a.util.*; | |
41 | import jav ax.managem ent.*; | |
42 | import jav ax.managem ent.remote .*; | |
43 | import jav ax.managem ent.remote .rmi.*; | |
44 | import jav ax.rmi.ssl .SslRMICli entSocketF actory; | |
45 | import jav ax.swing.e vent.Swing PropertyCh angeSuppor t; | |
46 | import sun .rmi.serve r.UnicastR ef2; | |
47 | import sun .rmi.trans port.LiveR ef; | |
48 | ||
49 | public cla ss ProxyCl ient imple ments JCon soleContex t { | |
50 | ||
51 | privat e Connecti onState co nnectionSt ate = Conn ectionStat e.DISCONNE CTED; | |
52 | ||
53 | // The SwingProp ertyChange Support wi ll fire ev ents on th e EDT | |
54 | privat e SwingPro pertyChang eSupport p ropertyCha ngeSupport = | |
55 | new Swin gPropertyC hangeSuppo rt(this, t rue); | |
56 | ||
57 | privat e static M ap<String, ProxyClie nt> cache = | |
58 | Co llections. synchroniz edMap(new HashMap<St ring, Prox yClient>() ); | |
59 | ||
60 | privat e volatile boolean i sDead = tr ue; | |
61 | privat e String h ostName = null; | |
62 | private in t PORT
|
|
63 | privat e String u serName = null; | |
64 | privat e String p assword = null; | |
65 | privat e boolean hasPlatfor mMXBeans = false; | |
66 | privat e boolean hasHotSpot Diagnostic MXBean= fa lse; | |
67 | privat e boolean hasCompila tionMXBean = false; | |
68 | privat e boolean supportsLo ckUsage = false; | |
69 | ||
70 | // REV ISIT: VMPa nel and ot her places relying u sing getUr l(). | |
71 | ||
72 | // set only if i t's create d for loca l monitori ng | |
73 | privat e LocalVir tualMachin e lvm; | |
74 | ||
75 | // set only if i t's create d from a g iven URL v ia the Adv anced tab | |
76 | privat e String a dvancedUrl = null; | |
77 | ||
78 | privat e JMXServi ceURL jmxU rl = null; | |
79 | privat e MBeanSer verConnect ion mbsc = null; | |
80 | privat e Snapshot MBeanServe rConnectio n server = null; | |
81 | privat e JMXConne ctor jmxc = null; | |
82 | privat e RMIServe r stub = n ull; | |
83 | privat e static f inal SslRM IClientSoc ketFactory sslRMICli entSocketF actory = | |
84 | new SslR MIClientSo cketFactor y(); | |
85 | privat e String r egistryHos tName = nu ll; | |
86 | private in t registry P ORT
|
|
87 | privat e boolean vmConnecto r = false; | |
88 | privat e boolean sslRegistr y = false; | |
89 | privat e boolean sslStub = false; | |
90 | final private St ring conne ctionName; | |
91 | final private St ring displ ayName; | |
92 | ||
93 | privat e ClassLoa dingMXBean classL oadingMBea n = null; | |
94 | privat e Compilat ionMXBean compil ationMBean = null; | |
95 | privat e MemoryMX Bean memory MBean = nu ll; | |
96 | privat e Operatin gSystemMXB ean operat ingSystemM Bean = nul l; | |
97 | privat e RuntimeM XBean runtim eMBean = n ull; | |
98 | privat e ThreadMX Bean thread MBean = nu ll; | |
99 | ||
100 | privat e com.sun. management .Operating SystemMXBe an sunOper atingSyste mMXBean = null; | |
101 | privat e HotSpotD iagnosticM XBean hotspot Diagnostic MXBean = n ull; | |
102 | ||
103 | privat e List<Mem oryPoolPro xy> memory PoolProxie s = null; | |
104 | privat e List<Gar bageCollec torMXBean> garbag eCollector MBeans = n ull; | |
105 | ||
106 | final static pri vate Strin g HOTSPOT_ DIAGNOSTIC _MXBEAN_NA ME = | |
107 | "c om.sun.man agement:ty pe=HotSpot Diagnostic "; | |
108 | ||
109 | privat e ProxyCli ent(String hostName, int port, | |
110 | String userName, String pa ssword) th rows IOExc eption { | |
111 | th is.connect ionName = getConnect ionName(ho stName, po rt, userNa me); | |
112 | th is.display Name = con nectionNam e; | |
113 | if (hostName .equals("l ocalhost") && port = = 0) { | |
114 | // Monit or self | |
115 | this.hos tName = ho stName; | |
116 | this.por t = port; | |
117 | } else { | |
118 | // Creat e an RMI c onnector c lient and connect it to | |
119 | // the R MI connect or server | |
120 | final St ring urlPa th = "/jnd i/rmi://" + hostName + ":" + p ort + | |
121 | "/jmx rmi"; | |
122 | JMXServi ceURL url = new JMXS erviceURL( "rmi", "", 0, urlPat h); | |
123 | setParam eters(url, userName, password) ; | |
124 | vmConnec tor = true ; | |
125 | registry HostName = hostName; | |
126 | registry Port = por t; | |
127 | checkSsl Config(); | |
128 | } | |
129 | } | |
130 | ||
131 | privat e ProxyCli ent(String url, | |
132 | String userName, String pa ssword) th rows IOExc eption { | |
133 | th is.advance dUrl = url ; | |
134 | th is.connect ionName = getConnect ionName(ur l, userNam e); | |
135 | th is.display Name = con nectionNam e; | |
136 | se tParameter s(new JMXS erviceURL( url), user Name, pass word); | |
137 | } | |
138 | ||
139 | privat e ProxyCli ent(LocalV irtualMach ine lvm) t hrows IOEx ception { | |
140 | th is.lvm = l vm; | |
141 | th is.connect ionName = getConnect ionName(lv m); | |
142 | th is.display Name = "pi d: " + lvm .vmid() + " " + lvm. displayNam e(); | |
143 | } | |
144 | ||
145 | privat e void set Parameters (JMXServic eURL url, String use rName, Str ing passwo rd) { | |
146 | th is.jmxUrl = url; | |
147 | th is.hostNam e = jmxUrl .getHost() ; | |
148 | th is.port = jmxUrl.get Port(); | |
149 | th is.userNam e = userNa me; | |
150 | th is.passwor d = passwo rd; | |
151 | } | |
152 | ||
153 | privat e static v oid checkS tub(Remote stub, | |
154 | Class< ? extends Remote> st ubClass) { | |
155 | // Check rem ote stub i s from the expected class. | |
156 | // | |
157 | if (stub.get Class() != stubClass ) { | |
158 | if (!Pro xy.isProxy Class(stub .getClass( ))) { | |
159 | thro w new Secu rityExcept ion( | |
160 | "Expecting a " + stu bClass.get Name() + " stub!"); | |
161 | } else { | |
162 | Invo cationHand ler handle r = Proxy. getInvocat ionHandler (stub); | |
163 | if ( handler.ge tClass() ! = RemoteOb jectInvoca tionHandle r.class) { | |
164 | throw new SecurityEx ception( | |
165 | "Expec ting a dyn amic proxy instance with a " + | |
166 | Remote ObjectInvo cationHand ler.class. getName() + | |
167 | " invo cation han dler!"); | |
168 | } el se { | |
169 | stub = (Re mote) hand ler; | |
170 | } | |
171 | } | |
172 | } | |
173 | // Check Rem oteRef in stub is fr om the exp ected clas s | |
174 | // "sun.rmi. server.Uni castRef2". | |
175 | // | |
176 | Re moteRef re f = ((Remo teObject)s tub).getRe f(); | |
177 | if (ref.getC lass() != UnicastRef 2.class) { | |
178 | throw ne w Security Exception( | |
179 | "Exp ecting a " + Unicast Ref2.class .getName() + | |
180 | " re mote refer ence in st ub!"); | |
181 | } | |
182 | // Check RMI ClientSock etFactory in stub is from the expected c lass | |
183 | // "javax.rm i.ssl.SslR MIClientSo cketFactor y". | |
184 | // | |
185 | Li veRef live Ref = ((Un icastRef2) ref).getLi veRef(); | |
186 | RM IClientSoc ketFactory csf = liv eRef.getCl ientSocket Factory(); | |
187 | if (csf == n ull || csf .getClass( ) != SslRM IClientSoc ketFactory .class) { | |
188 | throw ne w Security Exception( | |
189 | "Exp ecting a " + SslRMIC lientSocke tFactory.c lass.getNa me() + | |
190 | " RM I client s ocket fact ory in stu b!"); | |
191 | } | |
192 | } | |
193 | ||
194 | privat e static f inal Strin g rmiServe rImplStubC lassName = | |
195 | "j avax.manag ement.remo te.rmi.RMI ServerImpl _Stub"; | |
196 | privat e static f inal Class <? extends Remote> r miServerIm plStubClas s; | |
197 | ||
198 | static { | |
199 | // FIXME: RM IServerImp l_Stub is generated at build t ime | |
200 | // after jco nsole is b uilt. We need to in vestigate if | |
201 | // the Makef ile can be fixed to build jcon sole in th e | |
202 | // right ord er. As a workaround for now, we dynamic ally | |
203 | // load RMIS erverImpl_ Stub class instead o f statical ly | |
204 | // referenci ng it. | |
205 | Cl ass<? exte nds Remote > serverSt ubClass = null; | |
206 | tr y { | |
207 | serverSt ubClass = Class.forN ame(rmiSer verImplStu bClassName ).asSubcla ss(Remote. class); | |
208 | } catch (Cla ssNotFound Exception e) { | |
209 | // shoul d never re ach here | |
210 | throw ne w Internal Error(e.ge tMessage() , e); | |
211 | } | |
212 | rm iServerImp lStubClass = serverS tubClass; | |
213 | } | |
214 | ||
215 | privat e void che ckSslConfi g() throws IOExcepti on { | |
216 | // Get the r eference t o the RMI Registry a nd lookup RMIServer stub | |
217 | // | |
218 | Re gistry reg istry; | |
219 | tr y { | |
220 | registry = | |
221 | Loca teRegistry .getRegist ry(registr yHostName, registryP ort, | |
222 | sslRMIC lientSocke tFactory); | |
223 | try { | |
224 | stub = (RMISer ver) regis try.lookup ("jmxrmi") ; | |
225 | } catch (NotBoundE xception n be) { | |
226 | thro w (IOExcep tion) | |
227 | new IOExce ption(nbe. getMessage ()).initCa use(nbe); | |
228 | } | |
229 | sslRegis try = true ; | |
230 | } catch (IOE xception e ) { | |
231 | registry = | |
232 | Loca teRegistry .getRegist ry(registr yHostName, registryP ort); | |
233 | try { | |
234 | stub = (RMISer ver) regis try.lookup ("jmxrmi") ; | |
235 | } catch (NotBoundE xception n be) { | |
236 | thro w (IOExcep tion) | |
237 | new IOExce ption(nbe. getMessage ()).initCa use(nbe); | |
238 | } | |
239 | sslRegis try = fals e; | |
240 | } | |
241 | // Perform t he checks for secure stub | |
242 | // | |
243 | tr y { | |
244 | checkStu b(stub, rm iServerImp lStubClass ); | |
245 | sslStub = true; | |
246 | } catch (Sec urityExcep tion e) { | |
247 | sslStub = false; | |
248 | } | |
249 | } | |
250 | ||
251 | /** | |
252 | * Ret urns true if the und erlying RM I registry is SSL-pr otected. | |
253 | * | |
254 | * @ex ception Un supportedO perationEx ception If this {@co de ProxyCl ient} | |
255 | * doe s not deno te a JMX c onnector f or a JMX V M agent. | |
256 | */ | |
257 | public boolean i sSslRmiReg istry() { | |
258 | // Check for VM connec tor | |
259 | // | |
260 | if (!isVmCon nector()) { | |
261 | throw ne w Unsuppor tedOperati onExceptio n( | |
262 | "Pro xyClient.i sSslRmiReg istry() is only supp orted if t his " + | |
263 | "Pro xyClient i s a JMX co nnector fo r a JMX VM agent"); | |
264 | } | |
265 | re turn sslRe gistry; | |
266 | } | |
267 | ||
268 | /** | |
269 | * Ret urns true if the ret rieved RMI stub is S SL-protect ed. | |
270 | * | |
271 | * @ex ception Un supportedO perationEx ception If this {@co de ProxyCl ient} | |
272 | * doe s not deno te a JMX c onnector f or a JMX V M agent. | |
273 | */ | |
274 | public boolean i sSslRmiStu b() { | |
275 | // Check for VM connec tor | |
276 | // | |
277 | if (!isVmCon nector()) { | |
278 | throw ne w Unsuppor tedOperati onExceptio n( | |
279 | "Pro xyClient.i sSslRmiStu b() is onl y supporte d if this " + | |
280 | "Pro xyClient i s a JMX co nnector fo r a JMX VM agent"); | |
281 | } | |
282 | re turn sslSt ub; | |
283 | } | |
284 | ||
285 | /** | |
286 | * Ret urns true if this {@ code Proxy Client} de notes | |
287 | * a J MX connect or for a J MX VM agen t. | |
288 | */ | |
289 | public boolean i sVmConnect or() { | |
290 | re turn vmCon nector; | |
291 | } | |
292 | ||
293 | privat e void set Connection State(Conn ectionStat e state) { | |
294 | Co nnectionSt ate oldSta te = this. connection State; | |
295 | th is.connect ionState = state; | |
296 | pr opertyChan geSupport. fireProper tyChange(C ONNECTION_ STATE_PROP ERTY, | |
297 | o ldState, s tate); | |
298 | } | |
299 | ||
300 | public Connectio nState get Connection State() { | |
301 | re turn this. connection State; | |
302 | } | |
303 | ||
304 | void f lush() { | |
305 | if (server ! = null) { | |
306 | server.f lush(); | |
307 | } | |
308 | } | |
309 | ||
310 | void c onnect(boo lean requi reSSL) { | |
311 | se tConnectio nState(Con nectionSta te.CONNECT ING); | |
312 | tr y { | |
313 | tryConne ct(require SSL); | |
314 | setConne ctionState (Connectio nState.CON NECTED); | |
315 | } catch (Exc eption e) { | |
316 | if (JCon sole.isDeb ug()) { | |
317 | e.pr intStackTr ace(); | |
318 | } | |
319 | setConne ctionState (Connectio nState.DIS CONNECTED) ; | |
320 | } | |
321 | } | |
322 | ||
323 | privat e void try Connect(bo olean requ ireRemoteS SL) throws IOExcepti on { | |
324 | if (jmxUrl = = null && "localhost ".equals(h ostName) & & port == 0) { | |
325 | // Monit or self | |
326 | this.jmx c = null; | |
327 | this.mbs c = Manage mentFactor y.getPlatf ormMBeanSe rver(); | |
328 | this.ser ver = Snap shot.newSn apshot(mbs c); | |
329 | } else { | |
330 | // Monit or another process | |
331 | if (lvm != null) { | |
332 | if ( !lvm.isMan ageable()) { | |
333 | lvm.startM anagementA gent(); | |
334 | if (!lvm.i sManageabl e()) { | |
335 | // FIX ME: what t o throw | |
336 | throw new IOExce ption(lvm + "not man ageable"); | |
337 | } | |
338 | } | |
339 | if ( this.jmxUr l == null) { | |
340 | this.jmxUr l = new JM XServiceUR L(lvm.conn ectorAddre ss()); | |
341 | } | |
342 | } | |
343 | Map<Stri ng, Object > env = ne w HashMap< String, Ob ject>(); | |
344 | if (requ ireRemoteS SL) { | |
345 | env. put("jmx.r emote.x.ch eck.stub", "true"); | |
346 | } | |
347 | // Need to pass in credentia ls ? | |
348 | if (user Name == nu ll && pass word == nu ll) { | |
349 | if ( isVmConnec tor()) { | |
350 | // Check f or SSL con fig on rec onnection only | |
351 | if (stub = = null) { | |
352 | checkS slConfig() ; | |
353 | } | |
354 | this.jmxc = new RMIC onnector(s tub, null) ; | |
355 | jmxc.conne ct(env); | |
356 | } el se { | |
357 | this.jmxc = JMXConne ctorFactor y.connect( jmxUrl, en v); | |
358 | } | |
359 | } else { | |
360 | env. put(JMXCon nector.CRE DENTIALS, | |
361 | new St ring[] {us erName, pa ssword}); | |
362 | if ( isVmConnec tor()) { | |
363 | // Check f or SSL con fig on rec onnection only | |
364 | if (stub = = null) { | |
365 | checkS slConfig() ; | |
366 | } | |
367 | this.jmxc = new RMIC onnector(s tub, null) ; | |
368 | jmxc.conne ct(env); | |
369 | } el se { | |
370 | this.jmxc = JMXConne ctorFactor y.connect( jmxUrl, en v); | |
371 | } | |
372 | } | |
373 | this.mbs c = jmxc.g etMBeanSer verConnect ion(); | |
374 | this.ser ver = Snap shot.newSn apshot(mbs c); | |
375 | } | |
376 | th is.isDead = false; | |
377 | ||
378 | tr y { | |
379 | ObjectNa me on = ne w ObjectNa me(THREAD_ MXBEAN_NAM E); | |
380 | this.has PlatformMX Beans = se rver.isReg istered(on ); | |
381 | this.has HotSpotDia gnosticMXB ean = | |
382 | serv er.isRegis tered(new ObjectName (HOTSPOT_D IAGNOSTIC_ MXBEAN_NAM E)); | |
383 | // check if it has 6.0 new A PIs | |
384 | if (this .hasPlatfo rmMXBeans) { | |
385 | MBea nOperation Info[] mop is = serve r.getMBean Info(on).g etOperatio ns(); | |
386 | // l ook for fi ndDeadlock edThreads operations ; | |
387 | for (MBeanOper ationInfo op : mopis ) { | |
388 | if (op.get Name().equ als("findD eadlockedT hreads")) { | |
389 | this.s upportsLoc kUsage = t rue; | |
390 | break; | |
391 | } | |
392 | } | |
393 | ||
394 | on = new Objec tName(COMP ILATION_MX BEAN_NAME) ; | |
395 | this .hasCompil ationMXBea n = server .isRegiste red(on); | |
396 | } | |
397 | } catch (Mal formedObje ctNameExce ption e) { | |
398 | // shoul d not reac h here | |
399 | throw ne w Internal Error(e.ge tMessage() ); | |
400 | } catch (Int rospection Exception | | |
401 | Ins tanceNotFo undExcepti on | | |
402 | Ref lectionExc eption e) { | |
403 | throw ne w Internal Error(e.ge tMessage() , e); | |
404 | } | |
405 | ||
406 | if (hasPlatf ormMXBeans ) { | |
407 | // WORKA ROUND for bug 505663 2 | |
408 | // Check if the ac cess role is correct by gettin g a Runtim eMXBean | |
409 | getRunti meMXBean() ; | |
410 | } | |
411 | } | |
412 | ||
413 | /** | |
414 | * Get s a proxy client for a given l ocal virtu al machine . | |
415 | */ | |
416 | public static Pr oxyClient getProxyCl ient(Local VirtualMac hine lvm) | |
417 | th rows IOExc eption { | |
418 | fi nal String key = get CacheKey(l vm); | |
419 | Pr oxyClient proxyClien t = cache. get(key); | |
420 | if (proxyCli ent == nul l) { | |
421 | proxyCli ent = new ProxyClien t(lvm); | |
422 | cache.pu t(key, pro xyClient); | |
423 | } | |
424 | re turn proxy Client; | |
425 | } | |
426 | ||
427 | public static St ring getCo nnectionNa me(LocalVi rtualMachi ne lvm) { | |
428 | re turn Integ er.toStrin g(lvm.vmid ()); | |
429 | } | |
430 | ||
431 | privat e static S tring getC acheKey(Lo calVirtual Machine lv m) { | |
432 | re turn Integ er.toStrin g(lvm.vmid ()); | |
433 | } | |
434 | ||
435 | /** | |
436 | * Get s a proxy client for a given J MXServiceU RL. | |
437 | */ | |
438 | public static Pr oxyClient getProxyCl ient(Strin g url, | |
439 | Strin g userName , String p assword) | |
440 | th rows IOExc eption { | |
441 | fi nal String key = get CacheKey(u rl, userNa me, passwo rd); | |
442 | Pr oxyClient proxyClien t = cache. get(key); | |
443 | if (proxyCli ent == nul l) { | |
444 | proxyCli ent = new ProxyClien t(url, use rName, pas sword); | |
445 | cache.pu t(key, pro xyClient); | |
446 | } | |
447 | re turn proxy Client; | |
448 | } | |
449 | ||
450 | public static St ring getCo nnectionNa me(String url, | |
451 | String userName) { | |
452 | if (userName != null & & userName .length() > 0) { | |
453 | return u serName + "@" + url; | |
454 | } else { | |
455 | return u rl; | |
456 | } | |
457 | } | |
458 | ||
459 | privat e static S tring getC acheKey(St ring url, | |
460 | St ring userN ame, Strin g password ) { | |
461 | re turn (url == null ? "" : url) + ":" + | |
462 | (user Name == nu ll ? "" : userName) + ":" + | |
463 | (pass word == nu ll ? "" : password); | |
464 | } | |
465 | ||
466 | /** | |
467 | * Get s a proxy client for a given " hostname:p ort". | |
468 | */ | |
469 | public static Pr oxyClient getProxyCl ient(Strin g hostName , int port , | |
470 | Strin g userName , String p assword) | |
471 | th rows IOExc eption { | |
472 | fi nal String key = get CacheKey(h ostName, p ort, userN ame, passw ord); | |
473 | Pr oxyClient proxyClien t = cache. get(key); | |
474 | if (proxyCli ent == nul l) { | |
475 | proxyCli ent = new ProxyClien t(hostName , port, us erName, pa ssword); | |
476 | cache.pu t(key, pro xyClient); | |
477 | } | |
478 | re turn proxy Client; | |
479 | } | |
480 | ||
481 | public static St ring getCo nnectionNa me(String hostName, int port, | |
482 | String userName) { | |
483 | St ring name = hostName + ":" + p ort; | |
484 | if (userName != null & & userName .length() > 0) { | |
485 | return u serName + "@" + name ; | |
486 | } else { | |
487 | return n ame; | |
488 | } | |
489 | } | |
490 | ||
491 | privat e static S tring getC acheKey(St ring hostN ame, int p ort, | |
492 | St ring userN ame, Strin g password ) { | |
493 | re turn (host Name == nu ll ? "" : hostName) + ":" + | |
494 | port + ":" + | |
495 | (user Name == nu ll ? "" : userName) + ":" + | |
496 | (pass word == nu ll ? "" : password); | |
497 | } | |
498 | ||
499 | public String co nnectionNa me() { | |
500 | re turn conne ctionName; | |
501 | } | |
502 | ||
503 | public String ge tDisplayNa me() { | |
504 | re turn displ ayName; | |
505 | } | |
506 | ||
507 | public String to String() { | |
508 | if (!isConne cted()) { | |
509 | return R esources.f ormat(Mess ages.CONNE CTION_NAME __DISCONNE CTED_, dis playName); | |
510 | } else { | |
511 | return d isplayName ; | |
512 | } | |
513 | } | |
514 | ||
515 | public MBeanServe rConnectio n getMBean ServerConn ection() { | |
516 | ret urn mbsc; | |
517 | } | |
518 | ||
519 | public SnapshotM BeanServer Connection getSnapsh otMBeanSer verConnect ion() { | |
520 | re turn serve r; | |
521 | } | |
522 | ||
523 | public String ge tUrl() { | |
524 | re turn advan cedUrl; | |
525 | } | |
526 | ||
527 | public String ge tHostName( ) { | |
528 | re turn hostN ame; | |
529 | } | |
530 | ||
531 | public int getPo rt() { | |
532 | re turn port; | |
533 | } | |
534 | ||
535 | public int getVm id() { | |
536 | re turn (lvm != null) ? lvm.vmid( ) : 0; | |
537 | } | |
538 | ||
539 | public String ge tUserName( ) { | |
540 | re turn userN ame; | |
541 | } | |
542 | ||
543 | public String ge tPassword( ) { | |
544 | re turn passw ord; | |
545 | } | |
546 | ||
547 | public void disc onnect() { | |
548 | // Reset rem ote stub | |
549 | st ub = null; | |
550 | // Close MBe anServer c onnection | |
551 | if (jmxc != null) { | |
552 | try { | |
553 | jmxc .close(); | |
554 | } catch (IOExcepti on e) { | |
555 | // I gnore ??? | |
556 | } | |
557 | } | |
558 | // Reset pla tform MBea n referenc es | |
559 | cl assLoading MBean = nu ll; | |
560 | co mpilationM Bean = nul l; | |
561 | me moryMBean = null; | |
562 | op eratingSys temMBean = null; | |
563 | ru ntimeMBean = null; | |
564 | th readMBean = null; | |
565 | su nOperating SystemMXBe an = null; | |
566 | ga rbageColle ctorMBeans = null; | |
567 | // Set conne ction stat e to DISCO NNECTED | |
568 | if (!isDead) { | |
569 | isDead = true; | |
570 | setConne ctionState (Connectio nState.DIS CONNECTED) ; | |
571 | } | |
572 | } | |
573 | ||
574 | /** | |
575 | * Ret urns the l ist of dom ains in wh ich any MB ean is | |
576 | * cur rently reg istered. | |
577 | */ | |
578 | public String[] getDomains () throws IOExceptio n { | |
579 | re turn serve r.getDomai ns(); | |
580 | } | |
581 | ||
582 | /** | |
583 | * Ret urns a map of MBeans with Obje ctName as the key an d MBeanInf o value | |
584 | * of a given do main. If domain is <tt>null</ tt>, all M Beans | |
585 | * are returned. If no MB ean found, an empty map is ret urned. | |
586 | * | |
587 | */ | |
588 | public Map<Objec tName, MBe anInfo> ge tMBeans(St ring domai n) | |
589 | th rows IOExc eption { | |
590 | ||
591 | Ob jectName n ame = null ; | |
592 | if (domain ! = null) { | |
593 | try { | |
594 | name = new Obj ectName(do main + ":* "); | |
595 | } catch (Malformed ObjectName Exception e) { | |
596 | // s hould not reach here | |
597 | asse rt(false); | |
598 | } | |
599 | } | |
600 | Se t<ObjectNa me> mbeans = server. queryNames (name, nul l); | |
601 | Ma p<ObjectNa me,MBeanIn fo> result = | |
602 | new Hash Map<Object Name,MBean Info>(mbea ns.size()) ; | |
603 | It erator<Obj ectName> i terator = mbeans.ite rator(); | |
604 | wh ile (itera tor.hasNex t()) { | |
605 | Object o bject = it erator.nex t(); | |
606 | if (obje ct instanc eof Object Name) { | |
607 | Obje ctName o = (ObjectNa me)object; | |
608 | try { | |
609 | MBeanInfo info = ser ver.getMBe anInfo(o); | |
610 | result.put (o, info); | |
611 | } ca tch (Intro spectionEx ception e) { | |
612 | // TODO: s hould log the error | |
613 | } ca tch (Insta nceNotFoun dException e) { | |
614 | // TODO: s hould log the error | |
615 | } ca tch (Refle ctionExcep tion e) { | |
616 | // TODO: s hould log the error | |
617 | } | |
618 | } | |
619 | } | |
620 | re turn resul t; | |
621 | } | |
622 | ||
623 | /** | |
624 | * Ret urns a lis t of attri butes of a named MBe an. | |
625 | * | |
626 | */ | |
627 | public Attribute List getAt tributes(O bjectName name, Stri ng[] attri butes) | |
628 | th rows IOExc eption { | |
629 | At tributeLis t list = n ull; | |
630 | tr y { | |
631 | list = s erver.getA ttributes( name, attr ibutes); | |
632 | } catch (Ins tanceNotFo undExcepti on e) { | |
633 | // TODO: A MBean m ay have be en unregis tered. | |
634 | // need to set up listener t o listen f or MBeanSe rverNotifi cation. | |
635 | } catch (Ref lectionExc eption e) { | |
636 | // TODO: should lo g the erro r | |
637 | } | |
638 | re turn list; | |
639 | } | |
640 | ||
641 | /** | |
642 | * Set the value of a spec ific attri bute of a named MBea n. | |
643 | */ | |
644 | public void setA ttribute(O bjectName name, Attr ibute attr ibute) | |
645 | th rows Inval idAttribut eValueExce ption, | |
646 | MBean Exception, | |
647 | IOExc eption { | |
648 | tr y { | |
649 | server.s etAttribut e(name, at tribute); | |
650 | } catch (Ins tanceNotFo undExcepti on e) { | |
651 | // TODO: A MBean m ay have be en unregis tered. | |
652 | } catch (Att ributeNotF oundExcept ion e) { | |
653 | assert(f alse); | |
654 | } catch (Ref lectionExc eption e) { | |
655 | // TODO: should lo g the erro r | |
656 | } | |
657 | } | |
658 | ||
659 | /** | |
660 | * Inv okes an op eration of a named M Bean. | |
661 | * | |
662 | * @th rows MBean Exception Wraps an e xception t hrown by | |
663 | * the MBea n's invoke d method. | |
664 | */ | |
665 | public Object in voke(Objec tName name , String o perationNa me, | |
666 | Objec t[] params , String[] signature ) | |
667 | th rows IOExc eption, MB eanExcepti on { | |
668 | Ob ject resul t = null; | |
669 | tr y { | |
670 | result = server.in voke(name, operation Name, para ms, signat ure); | |
671 | } catch (Ins tanceNotFo undExcepti on e) { | |
672 | // TODO: A MBean m ay have be en unregis tered. | |
673 | } catch (Ref lectionExc eption e) { | |
674 | // TODO: should lo g the erro r | |
675 | } | |
676 | re turn resul t; | |
677 | } | |
678 | ||
679 | public synchroni zed ClassL oadingMXBe an getClas sLoadingMX Bean() thr ows IOExce ption { | |
680 | if (hasPlatf ormMXBeans && classL oadingMBea n == null) { | |
681 | classLoa dingMBean = | |
682 | newP latformMXB eanProxy(s erver, CLA SS_LOADING _MXBEAN_NA ME, | |
683 | C lassLoadin gMXBean.cl ass); | |
684 | } | |
685 | re turn class LoadingMBe an; | |
686 | } | |
687 | ||
688 | public synchroni zed Compil ationMXBea n getCompi lationMXBe an() throw s IOExcept ion { | |
689 | if (hasCompi lationMXBe an && comp ilationMBe an == null ) { | |
690 | compilat ionMBean = | |
691 | newP latformMXB eanProxy(s erver, COM PILATION_M XBEAN_NAME , | |
692 | C ompilation MXBean.cla ss); | |
693 | } | |
694 | re turn compi lationMBea n; | |
695 | } | |
696 | ||
697 | public Collectio n<MemoryPo olProxy> g etMemoryPo olProxies( ) | |
698 | th rows IOExc eption { | |
699 | ||
700 | // TODO: How to deal w ith change s to the l ist?? | |
701 | if (memoryPo olProxies == null) { | |
702 | ObjectNa me poolNam e = null; | |
703 | try { | |
704 | pool Name = new ObjectNam e(MEMORY_P OOL_MXBEAN _DOMAIN_TY PE + ",*") ; | |
705 | } catch (Malformed ObjectName Exception e) { | |
706 | // s hould not reach here | |
707 | asse rt(false); | |
708 | } | |
709 | Set<Obje ctName> mb eans = ser ver.queryN ames(poolN ame, null) ; | |
710 | if (mbea ns != null ) { | |
711 | memo ryPoolProx ies = new ArrayList< MemoryPool Proxy>(); | |
712 | Iter ator<Objec tName> ite rator = mb eans.itera tor(); | |
713 | whil e (iterato r.hasNext( )) { | |
714 | ObjectName objName = (ObjectNa me) iterat or.next(); | |
715 | MemoryPool Proxy p = new Memory PoolProxy( this, objN ame); | |
716 | memoryPool Proxies.ad d(p); | |
717 | } | |
718 | } | |
719 | } | |
720 | re turn memor yPoolProxi es; | |
721 | } | |
722 | ||
723 | public synchroni zed Collec tion<Garba geCollecto rMXBean> g etGarbageC ollectorMX Beans() | |
724 | th rows IOExc eption { | |
725 | ||
726 | // TODO: How to deal w ith change s to the l ist?? | |
727 | if (garbageC ollectorMB eans == nu ll) { | |
728 | ObjectNa me gcName = null; | |
729 | try { | |
730 | gcNa me = new O bjectName( GARBAGE_CO LLECTOR_MX BEAN_DOMAI N_TYPE + " ,*"); | |
731 | } catch (Malformed ObjectName Exception e) { | |
732 | // s hould not reach here | |
733 | asse rt(false); | |
734 | } | |
735 | Set<Obje ctName> mb eans = ser ver.queryN ames(gcNam e, null); | |
736 | if (mbea ns != null ) { | |
737 | garb ageCollect orMBeans = new Array List<Garba geCollecto rMXBean>() ; | |
738 | Iter ator<Objec tName> ite rator = mb eans.itera tor(); | |
739 | whil e (iterato r.hasNext( )) { | |
740 | ObjectName on = (Obj ectName) i terator.ne xt(); | |
741 | String nam e = GARBAG E_COLLECTO R_MXBEAN_D OMAIN_TYPE + | |
742 | ",name =" + on.ge tKeyProper ty("name") ; | |
743 | ||
744 | GarbageCol lectorMXBe an mBean = | |
745 | newPla tformMXBea nProxy(ser ver, name, | |
746 | Gar bageCollec torMXBean. class); | |
747 | garbag eCollector MBeans.add (mBean); | |
748 | } | |
749 | } | |
750 | } | |
751 | re turn garba geCollecto rMBeans; | |
752 | } | |
753 | ||
754 | public synchroni zed Memory MXBean get MemoryMXBe an() throw s IOExcept ion { | |
755 | if (hasPlatf ormMXBeans && memory MBean == n ull) { | |
756 | memoryMB ean = | |
757 | newP latformMXB eanProxy(s erver, MEM ORY_MXBEAN _NAME, | |
758 | M emoryMXBea n.class); | |
759 | } | |
760 | re turn memor yMBean; | |
761 | } | |
762 | ||
763 | public synchroni zed Runtim eMXBean ge tRuntimeMX Bean() thr ows IOExce ption { | |
764 | if (hasPlatf ormMXBeans && runtim eMBean == null) { | |
765 | runtimeM Bean = | |
766 | newP latformMXB eanProxy(s erver, RUN TIME_MXBEA N_NAME, | |
767 | R untimeMXBe an.class); | |
768 | } | |
769 | re turn runti meMBean; | |
770 | } | |
771 | ||
772 | ||
773 | public synchroni zed Thread MXBean get ThreadMXBe an() throw s IOExcept ion { | |
774 | if (hasPlatf ormMXBeans && thread MBean == n ull) { | |
775 | threadMB ean = | |
776 | newP latformMXB eanProxy(s erver, THR EAD_MXBEAN _NAME, | |
777 | T hreadMXBea n.class); | |
778 | } | |
779 | re turn threa dMBean; | |
780 | } | |
781 | ||
782 | public synchroni zed Operat ingSystemM XBean getO peratingSy stemMXBean () throws IOExceptio n { | |
783 | if (hasPlatf ormMXBeans && operat ingSystemM Bean == nu ll) { | |
784 | operatin gSystemMBe an = | |
785 | newP latformMXB eanProxy(s erver, OPE RATING_SYS TEM_MXBEAN _NAME, | |
786 | O peratingSy stemMXBean .class); | |
787 | } | |
788 | re turn opera tingSystem MBean; | |
789 | } | |
790 | ||
791 | public synchroni zed com.su n.manageme nt.Operati ngSystemMX Bean | |
792 | ge tSunOperat ingSystemM XBean() th rows IOExc eption { | |
793 | ||
794 | tr y { | |
795 | ObjectNa me on = ne w ObjectNa me(OPERATI NG_SYSTEM_ MXBEAN_NAM E); | |
796 | if (sunO peratingSy stemMXBean == null) { | |
797 | if ( server.isI nstanceOf( on, | |
798 | "com.s un.managem ent.Operat ingSystemM XBean")) { | |
799 | sunOperati ngSystemMX Bean = | |
800 | newPla tformMXBea nProxy(ser ver, | |
801 | OP ERATING_SY STEM_MXBEA N_NAME, | |
802 | co m.sun.mana gement.Ope ratingSyst emMXBean.c lass); | |
803 | } | |
804 | } | |
805 | } catch (Ins tanceNotFo undExcepti on e) { | |
806 | return null; | |
807 | } catch (Mal formedObje ctNameExce ption e) { | |
808 | return null; // s hould neve r reach he re | |
809 | } | |
810 | re turn sunOp eratingSys temMXBean; | |
811 | } | |
812 | ||
813 | public synchroni zed HotSpo tDiagnosti cMXBean ge tHotSpotDi agnosticMX Bean() thr ows IOExce ption { | |
814 | if (hasHotSp otDiagnost icMXBean & & hotspotD iagnosticM XBean == n ull) { | |
815 | hotspotD iagnosticM XBean = | |
816 | newP latformMXB eanProxy(s erver, HOT SPOT_DIAGN OSTIC_MXBE AN_NAME, | |
817 | H otSpotDiag nosticMXBe an.class); | |
818 | } | |
819 | re turn hotsp otDiagnost icMXBean; | |
820 | } | |
821 | ||
822 | public <T> T get MXBean(Obj ectName ob jName, Cla ss<T> inte rfaceClass ) | |
823 | th rows IOExc eption { | |
824 | re turn newPl atformMXBe anProxy(se rver, | |
825 | ob jName.toSt ring(), | |
826 | in terfaceCla ss); | |
827 | ||
828 | } | |
829 | ||
830 | // Ret urn thread IDs of de adlocked t hreads or null if an y. | |
831 | // It finds dead locks invo lving only monitors if it's a Tiger VM. | |
832 | // Oth erwise, it finds dea dlocks inv olving bot h monitors and | |
833 | // the concurren t locks. | |
834 | public long[] fi ndDeadlock edThreads( ) throws I OException { | |
835 | Th readMXBean tm = getT hreadMXBea n(); | |
836 | if (supports LockUsage && tm.isSy nchronizer UsageSuppo rted()) { | |
837 | return t m.findDead lockedThre ads(); | |
838 | } else { | |
839 | return t m.findMoni torDeadloc kedThreads (); | |
840 | } | |
841 | } | |
842 | ||
843 | public synchroni zed void m arkAsDead( ) { | |
844 | di sconnect() ; | |
845 | } | |
846 | ||
847 | public boolean i sDead() { | |
848 | re turn isDea d; | |
849 | } | |
850 | ||
851 | boolea n isConnec ted() { | |
852 | re turn !isDe ad(); | |
853 | } | |
854 | ||
855 | boolea n hasPlatf ormMXBeans () { | |
856 | re turn this. hasPlatfor mMXBeans; | |
857 | } | |
858 | ||
859 | boolea n hasHotSp otDiagnost icMXBean() { | |
860 | re turn this. hasHotSpot Diagnostic MXBean; | |
861 | } | |
862 | ||
863 | boolea n isLockUs ageSupport ed() { | |
864 | re turn suppo rtsLockUsa ge; | |
865 | } | |
866 | ||
867 | public boolean i sRegistere d(ObjectNa me name) t hrows IOEx ception { | |
868 | re turn serve r.isRegist ered(name) ; | |
869 | } | |
870 | ||
871 | public void addP ropertyCha ngeListene r(Property ChangeList ener liste ner) { | |
872 | pr opertyChan geSupport. addPropert yChangeLis tener(list ener); | |
873 | } | |
874 | ||
875 | public void addW eakPropert yChangeLis tener(Prop ertyChange Listener l istener) { | |
876 | if (!(listen er instanc eof WeakPC L)) { | |
877 | listener = new Wea kPCL(liste ner); | |
878 | } | |
879 | pr opertyChan geSupport. addPropert yChangeLis tener(list ener); | |
880 | } | |
881 | ||
882 | public void remo veProperty ChangeList ener(Prope rtyChangeL istener li stener) { | |
883 | if (!(listen er instanc eof WeakPC L)) { | |
884 | // Searc h for the WeakPCL ho lding this listener (if any) | |
885 | for (Pro pertyChang eListener pcl : prop ertyChange Support.ge tPropertyC hangeListe ners()) { | |
886 | if ( pcl instan ceof WeakP CL && ((We akPCL)pcl) .get() == listener) { | |
887 | listener = pcl; | |
888 | break; | |
889 | } | |
890 | } | |
891 | } | |
892 | pr opertyChan geSupport. removeProp ertyChange Listener(l istener); | |
893 | } | |
894 | ||
895 | /** | |
896 | * The PropertyC hangeListe ner is han dled via a WeakRefer ence | |
897 | * so as not to pin down t he listene r. | |
898 | */ | |
899 | privat e class We akPCL exte nds WeakRe ference<Pr opertyChan geListener > | |
900 | impl ements Pro pertyChang eListener { | |
901 | We akPCL(Prop ertyChange Listener r eferent) { | |
902 | super(re ferent); | |
903 | } | |
904 | ||
905 | pu blic void propertyCh ange(Prope rtyChangeE vent pce) { | |
906 | Property ChangeList ener pcl = get(); | |
907 | ||
908 | if (pcl == null) { | |
909 | // T he referen t listener was GC'ed , we're no longer | |
910 | // i nterested in Propert yChanges, remove the listener. | |
911 | disp ose(); | |
912 | } else { | |
913 | pcl. propertyCh ange(pce); | |
914 | } | |
915 | } | |
916 | ||
917 | pr ivate void dispose() { | |
918 | removePr opertyChan geListener (this); | |
919 | } | |
920 | } | |
921 | ||
922 | // | |
923 | // Sna pshot MBea nServerCon nection: | |
924 | // | |
925 | // Thi s is an ob ject that wraps an e xisting MB eanServerC onnection and adds | |
926 | // cac hing to it , as follo ws: | |
927 | // | |
928 | // - T he first t ime an att ribute is called in a given MB ean, the r esult is | |
929 | // c ached. Eve ry subsequ ent time g etAttribut e is calle d for that attribute | |
930 | // t he cached result is returned. | |
931 | // | |
932 | // - B efore ever y call to VMPanel.up date() or when the R efresh but ton in the | |
933 | // A ttributes table is p ressed dow n the attr ibutes cac he is flus hed. Then | |
934 | // a ny subsequ ent call t o getAttri bute will retrieve a ll the val ues for | |
935 | // t he attribu tes that a re known t o the cach e. | |
936 | // | |
937 | // - T he attribu tes cache uses a lea rning appr oach and o nly the at tributes | |
938 | // t hat are in the cache will be r etrieved b etween two subsequen t updates. | |
939 | // | |
940 | ||
941 | public interface SnapshotM BeanServer Connection | |
942 | extends MBeanServe rConnectio n { | |
943 | /* * | |
944 | * Flush all cached va lues of at tributes. | |
945 | * / | |
946 | pu blic void flush(); | |
947 | } | |
948 | ||
949 | public static cl ass Snapsh ot { | |
950 | pr ivate Snap shot() { | |
951 | } | |
952 | pu blic stati c Snapshot MBeanServe rConnectio n | |
953 | newS napshot(MB eanServerC onnection mbsc) { | |
954 | final In vocationHa ndler ih = new Snaps hotInvocat ionHandler (mbsc); | |
955 | return ( SnapshotMB eanServerC onnection) Proxy.new ProxyInsta nce( | |
956 | Snapshot.c lass.getCl assLoader( ), | |
957 | new Class[ ] {Snapsho tMBeanServ erConnecti on.class}, | |
958 | ih); | |
959 | } | |
960 | } | |
961 | ||
962 | static class Sna pshotInvoc ationHandl er impleme nts Invoca tionHandle r { | |
963 | ||
964 | pr ivate fina l MBeanSer verConnect ion conn; | |
965 | pr ivate Map< ObjectName , NameValu eMap> cach edValues = newMap(); | |
966 | pr ivate Map< ObjectName , Set<Stri ng>> cache dNames = n ewMap(); | |
967 | ||
968 | @S uppressWar nings("ser ial") | |
969 | pr ivate stat ic final c lass NameV alueMap | |
970 | exte nds HashMa p<String, Object> {} | |
971 | ||
972 | Sn apshotInvo cationHand ler(MBeanS erverConne ction conn ) { | |
973 | this.con n = conn; | |
974 | } | |
975 | ||
976 | sy nchronized void flus h() { | |
977 | cachedVa lues = new Map(); | |
978 | } | |
979 | ||
980 | pu blic Objec t invoke(O bject prox y, Method method, Ob ject[] arg s) | |
981 | thro ws Throwab le { | |
982 | final St ring metho dName = me thod.getNa me(); | |
983 | if (meth odName.equ als("getAt tribute")) { | |
984 | retu rn getAttr ibute((Obj ectName) a rgs[0], (S tring) arg s[1]); | |
985 | } else i f (methodN ame.equals ("getAttri butes")) { | |
986 | retu rn getAttr ibutes((Ob jectName) args[0], ( String[]) args[1]); | |
987 | } else i f (methodN ame.equals ("flush")) { | |
988 | flus h(); | |
989 | retu rn null; | |
990 | } else { | |
991 | try { | |
992 | return met hod.invoke (conn, arg s); | |
993 | } ca tch (Invoc ationTarge tException e) { | |
994 | throw e.ge tCause(); | |
995 | } | |
996 | } | |
997 | } | |
998 | ||
999 | pr ivate Obje ct getAttr ibute(Obje ctName obj Name, Stri ng attrNam e) | |
1000 | thro ws MBeanEx ception, I nstanceNot FoundExcep tion, | |
1001 | Attr ibuteNotFo undExcepti on, Reflec tionExcept ion, IOExc eption { | |
1002 | final Na meValueMap values = getCachedA ttributes( | |
1003 | objName, C ollections .singleton (attrName) ); | |
1004 | Object v alue = val ues.get(at trName); | |
1005 | if (valu e != null || values. containsKe y(attrName )) { | |
1006 | retu rn value; | |
1007 | } | |
1008 | // Not i n cache, p resumably because it was omitt ed from th e | |
1009 | // getAt tributes r esult beca use of an exception. Followin g | |
1010 | // call will proba bly provok e the same exception . | |
1011 | return c onn.getAtt ribute(obj Name, attr Name); | |
1012 | } | |
1013 | ||
1014 | pr ivate Attr ibuteList getAttribu tes( | |
1015 | Obje ctName obj Name, Stri ng[] attrN ames) thro ws | |
1016 | Inst anceNotFou ndExceptio n, Reflect ionExcepti on, IOExce ption { | |
1017 | final Na meValueMap values = getCachedA ttributes( | |
1018 | objName, | |
1019 | new TreeSe t<String>( Arrays.asL ist(attrNa mes))); | |
1020 | final At tributeLis t list = n ew Attribu teList(); | |
1021 | for (Str ing attrNa me : attrN ames) { | |
1022 | fina l Object v alue = val ues.get(at trName); | |
1023 | if ( value != n ull || val ues.contai nsKey(attr Name)) { | |
1024 | list.add(n ew Attribu te(attrNam e, value)) ; | |
1025 | } | |
1026 | } | |
1027 | return l ist; | |
1028 | } | |
1029 | ||
1030 | pr ivate sync hronized N ameValueMa p getCache dAttribute s( | |
1031 | Obje ctName obj Name, Set< String> at trNames) t hrows | |
1032 | Inst anceNotFou ndExceptio n, Reflect ionExcepti on, IOExce ption { | |
1033 | NameValu eMap value s = cached Values.get (objName); | |
1034 | if (valu es != null && values .keySet(). containsAl l(attrName s)) { | |
1035 | retu rn values; | |
1036 | } | |
1037 | attrName s = new Tr eeSet<Stri ng>(attrNa mes); | |
1038 | Set<Stri ng> oldNam es = cache dNames.get (objName); | |
1039 | if (oldN ames != nu ll) { | |
1040 | attr Names.addA ll(oldName s); | |
1041 | } | |
1042 | values = new NameV alueMap(); | |
1043 | final At tributeLis t attrs = conn.getAt tributes( | |
1044 | objName, | |
1045 | attrNames. toArray(ne w String[a ttrNames.s ize()])); | |
1046 | for (Att ribute att r : attrs. asList()) { | |
1047 | valu es.put(att r.getName( ), attr.ge tValue()); | |
1048 | } | |
1049 | cachedVa lues.put(o bjName, va lues); | |
1050 | cachedNa mes.put(ob jName, att rNames); | |
1051 | return v alues; | |
1052 | } | |
1053 | ||
1054 | // See http: //www.arti ma.com/web logs/viewp ost.jsp?th read=79394 | |
1055 | pr ivate stat ic <K, V> Map<K, V> newMap() { | |
1056 | return n ew HashMap <K, V>(); | |
1057 | } | |
1058 | } | |
1059 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.