Produced by Araxis Merge on 9/25/2018 2:13:12 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\management | Agent.java | Mon Jan 22 14:46:54 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\management | Agent.java | Wed Sep 12 17:42:44 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1108 |
Changed | 1 | 2 |
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 3, 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 | package su n.manageme nt; | |
26 | ||
27 | import jav a.io.Buffe redInputSt ream; | |
28 | import jav a.io.File; | |
29 | import jav a.io.FileI nputStream ; | |
30 | import jav a.io.FileN otFoundExc eption; | |
31 | import jav a.io.IOExc eption; | |
32 | import jav a.io.Input Stream; | |
33 | import jav a.lang.man agement.Ma nagementFa ctory; | |
34 | import jav a.lang.ref lect.Invoc ationTarge tException ; | |
35 | import jav a.lang.ref lect.Metho d; | |
36 | import jav a.net.Inet Address; | |
37 | import jav a.net.Sock et; | |
38 | import jav a.net.Unkn ownHostExc eption; | |
39 | import jav a.text.Mes sageFormat ; | |
40 | import jav a.util.Mis singResour ceExceptio n; | |
41 | import jav a.util.Pro perties; | |
42 | import jav a.util.Res ourceBundl e; | |
43 | ||
44 | import jav ax.managem ent.remote .JMXConnec torServer; | |
45 | import jav ax.managem ent.remote .JMXServic eURL; | |
46 | ||
47 | import sta tic sun.ma nagement.A gentConfig urationErr or.*; | |
48 | import sun .managemen t.jmxremot e.Connecto rBootstrap ; | |
49 | import sun .managemen t.jdp.JdpC ontroller; | |
50 | import sun .managemen t.jdp.JdpE xception; | |
51 | import sun .misc.VMSu pport; | |
52 | ||
53 | /** | |
54 | * This Ag ent is sta rted by th e VM when -Dcom.sun. management .snmp or | |
55 | * -Dcom.s un.managem ent.jmxrem ote is set . This cla ss will be loaded by the | |
56 | * system class load er. Also j mx framewo rk could b e started by jcmd | |
57 | */ | |
58 | public cla ss Agent { | |
59 | // man agement pr operties | |
60 | ||
61 | privat e static P roperties mgmtProps; | |
62 | privat e static R esourceBun dle messag eRB; | |
63 | privat e static f inal Strin g CONFIG_F ILE = | |
64 | "com.sun .managemen t.config.f ile"; | |
65 | privat e static f inal Strin g SNMP_POR T = | |
66 | "com.sun .managemen t.snmp.por t"; | |
67 | privat e static f inal Strin g JMXREMOT E = | |
68 | "com.sun .managemen t.jmxremot e"; | |
69 | privat e static f inal Strin g JMXREMOT E_PORT = | |
70 | "com.sun .managemen t.jmxremot e.port"; | |
71 | privat e static f inal Strin g RMI_PORT = | |
72 | "com.sun .managemen t.jmxremot e.rmi.port "; | |
73 | privat e static f inal Strin g ENABLE_T HREAD_CONT ENTION_MON ITORING = | |
74 | "com.sun .managemen t.enableTh readConten tionMonito ring"; | |
75 | privat e static f inal Strin g LOCAL_CO NNECTOR_AD DRESS_PROP = | |
76 | "com.sun .managemen t.jmxremot e.localCon nectorAddr ess"; | |
77 | privat e static f inal Strin g SNMP_ADA PTOR_BOOTS TRAP_CLASS _NAME = | |
78 | "sun.man agement.sn mp.Adaptor Bootstrap" ; | |
79 | ||
80 | privat e static f inal Strin g JDP_DEFA ULT_ADDRES S = "224.0 .23.178"; | |
81 | private st atic final int JDP_D EFAULT_POR T
|
|
82 | ||
83 | // The only acti ve agent a llowed | |
84 | privat e static J MXConnecto rServer jm xServer = null; | |
85 | ||
86 | // Par se string com.sun.ma nagement.p rop=xxx,co m.sun.mana gement.pro p=yyyy | |
87 | // and return pr operty set if args i s null or empty | |
88 | // ret urn empty property s et | |
89 | privat e static P roperties parseStrin g(String a rgs) { | |
90 | Pr operties a rgProps = new Proper ties(); | |
91 | if (args != null) { | |
92 | for (Str ing option : args.sp lit(",")) { | |
93 | Stri ng s[] = o ption.spli t("=", 2); | |
94 | Stri ng name = s[0].trim( ); | |
95 | Stri ng value = (s.length > 1) ? s[ 1].trim() : ""; | |
96 | ||
97 | if ( !name.star tsWith("co m.sun.mana gement.")) { | |
98 | error(INVA LID_OPTION , name); | |
99 | } | |
100 | ||
101 | argP rops.setPr operty(nam e, value); | |
102 | } | |
103 | } | |
104 | ||
105 | re turn argPr ops; | |
106 | } | |
107 | ||
108 | // inv oked by -j avaagent o r -Dcom.su n.manageme nt.agent.c lass | |
109 | public static vo id premain (String ar gs) throws Exception { | |
110 | ag entmain(ar gs); | |
111 | } | |
112 | ||
113 | // inv oked by at tach mecha nism | |
114 | public static vo id agentma in(String args) thro ws Excepti on { | |
115 | if (args == null || ar gs.length( ) == 0) { | |
116 | args = J MXREMOTE; // default to local management | |
117 | } | |
118 | ||
119 | Pr operties a rg_props = parseStri ng(args); | |
120 | ||
121 | // Read prop erties fro m the conf ig file | |
122 | Pr operties c onfig_prop s = new Pr operties() ; | |
123 | St ring fname = arg_pro ps.getProp erty(CONFI G_FILE); | |
124 | re adConfigur ation(fnam e, config_ props); | |
125 | ||
126 | // Arguments override config fil e | |
127 | co nfig_props .putAll(ar g_props); | |
128 | st artAgent(c onfig_prop s); | |
129 | } | |
130 | ||
131 | // jcm d Manageme ntAgent.st art_local entry poin t | |
132 | // Als o called d ue to comm and-line v ia startAg ent() | |
133 | privat e static s ynchronize d void sta rtLocalMan agementAge nt() { | |
134 | Pr operties a gentProps = VMSuppor t.getAgent Properties (); | |
135 | ||
136 | // start loc al connect or if not started | |
137 | if (agentPro ps.get(LOC AL_CONNECT OR_ADDRESS _PROP) == null) { | |
138 | JMXConne ctorServer cs = Conn ectorBoots trap.start LocalConne ctorServer (); | |
139 | String a ddress = c s.getAddre ss().toStr ing(); | |
140 | // Add t he local c onnector a ddress to the agent properties | |
141 | agentPro ps.put(LOC AL_CONNECT OR_ADDRESS _PROP, add ress); | |
142 | ||
143 | try { | |
144 | // e xport the address to the instr umentation buffer | |
145 | Conn ectorAddre ssLink.exp ort(addres s); | |
146 | } catch (Exception x) { | |
147 | // C onnector s erver star ted but un able to ex port addre ss | |
148 | // t o instrume ntation bu ffer - non -fatal err or. | |
149 | warn ing(EXPORT _ADDRESS_F AILED, x.g etMessage( )); | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | // jcm d Manageme ntAgent.st art entry point | |
155 | // Thi s method s tarts the remote JMX agent and starts ne ither | |
156 | // the local JMX agent nor the SNMP agent | |
157 | // @se e #startLo calManagem entAgent a nd also @s ee #startA gent. | |
158 | privat e static s ynchronize d void sta rtRemoteMa nagementAg ent(String args) thr ows Except ion { | |
159 | if (jmxServe r != null) { | |
160 | throw ne w RuntimeE xception(g etText(INV ALID_STATE , "Agent a lready sta rted")); | |
161 | } | |
162 | ||
163 | Pr operties a rgProps = parseStrin g(args); | |
164 | Pr operties c onfigProps = new Pro perties(); | |
165 | ||
166 | // Load the management propertie s from the config fi le | |
167 | // if config file is n ot specifi ed readCon figuration implicitl y | |
168 | // reads <ja va.home>/l ib/managem ent/manage ment.prope rties | |
169 | ||
170 | St ring fname = System. getPropert y(CONFIG_F ILE); | |
171 | re adConfigur ation(fnam e, configP rops); | |
172 | ||
173 | // managemen t properti es can be overridden by system propertie s | |
174 | // which tak e preceden ce | |
175 | Pr operties s ysProps = System.get Properties (); | |
176 | sy nchronized (sysProps ) { | |
177 | configPr ops.putAll (sysProps) ; | |
178 | } | |
179 | ||
180 | // if user s pecifies c onfig file into comm and line f or either | |
181 | // jcmd util ities or a ttach comm and it ove rrides pro perties se t in | |
182 | // command l ine at the time of V M start | |
183 | St ring fname User = arg Props.getP roperty(CO NFIG_FILE) ; | |
184 | if (fnameUse r != null) { | |
185 | readConf iguration( fnameUser, configPro ps); | |
186 | } | |
187 | ||
188 | // arguments specified in comman d line of jcmd utili ties | |
189 | // override both syste m properti es and one set by co nfig file | |
190 | // specified in jcmd c ommand lin e | |
191 | co nfigProps. putAll(arg Props); | |
192 | ||
193 | // jcmd does n't allow to change ThreadCont entionMoni toring, bu t user | |
194 | // can speci fy this pr operty ins ide config file, so enable opt ional | |
195 | // monitorin g function ality if t his proper ty is set | |
196 | fi nal String enableThr eadContent ionMonitor ing = | |
197 | conf igProps.ge tProperty( ENABLE_THR EAD_CONTEN TION_MONIT ORING); | |
198 | ||
199 | if (enableTh readConten tionMonito ring != nu ll) { | |
200 | Manageme ntFactory. getThreadM XBean(). | |
201 | setThreadC ontentionM onitoringE nabled(tru e); | |
202 | } | |
203 | ||
204 | St ring jmxre motePort = configPro ps.getProp erty(JMXRE MOTE_PORT) ; | |
205 | if (jmxremot ePort != n ull) { | |
206 | jmxServe r = Connec torBootstr ap. | |
207 | startRemot eConnector Server(jmx remotePort , configPr ops); | |
208 | ||
209 | startDis coveryServ ice(config Props); | |
210 | } | |
211 | } | |
212 | ||
213 | privat e static s ynchronize d void sto pRemoteMan agementAge nt() throw s Exceptio n { | |
214 | ||
215 | Jd pControlle r.stopDisc overyServi ce(); | |
216 | ||
217 | if (jmxServe r != null) { | |
218 | Connecto rBootstrap .unexportR egistry(); | |
219 | ||
220 | // Attem pt to stop already s topped age nt | |
221 | // Don't cause any errors. | |
222 | jmxServe r.stop(); | |
223 | jmxServe r = null; | |
224 | } | |
225 | } | |
226 | ||
227 | privat e static v oid startA gent(Prope rties prop s) throws Exception { | |
228 | St ring snmpP ort = prop s.getPrope rty(SNMP_P ORT); | |
229 | St ring jmxre mote = pro ps.getProp erty(JMXRE MOTE); | |
230 | St ring jmxre motePort = props.get Property(J MXREMOTE_P ORT); | |
231 | ||
232 | // Enable op tional mon itoring fu nctionalit y if reque sted | |
233 | fi nal String enableThr eadContent ionMonitor ing = | |
234 | prop s.getPrope rty(ENABLE _THREAD_CO NTENTION_M ONITORING) ; | |
235 | if (enableTh readConten tionMonito ring != nu ll) { | |
236 | Manageme ntFactory. getThreadM XBean(). | |
237 | setThreadC ontentionM onitoringE nabled(tru e); | |
238 | } | |
239 | ||
240 | tr y { | |
241 | if (snmp Port != nu ll) { | |
242 | load SnmpAgent( snmpPort, props); | |
243 | } | |
244 | ||
245 | /* | |
246 | * If th e jmxremot e.port pro perty is s et then we start the | |
247 | * RMICo nnectorSer ver for re mote M&M. | |
248 | * | |
249 | * If th e jmxremot e or jmxre mote.port properties are set t hen | |
250 | * we st art a RMIC onnectorSe rver for l ocal M&M. The addres s | |
251 | * of th is "local" server is exported as a count er to the jstat | |
252 | * instr umentation buffer. | |
253 | */ | |
254 | if (jmxr emote != n ull || jmx remotePort != null) { | |
255 | if ( jmxremoteP ort != nul l) { | |
256 | jmxServer = Connecto rBootstrap . | |
257 | st artRemoteC onnectorSe rver(jmxre motePort, props); | |
258 | startDisco veryServic e(props); | |
259 | } | |
260 | star tLocalMana gementAgen t(); | |
261 | } | |
262 | ||
263 | } catch (Age ntConfigur ationError e) { | |
264 | error(e. getError() , e.getPar ams()); | |
265 | } catch (Exc eption e) { | |
266 | error(e) ; | |
267 | } | |
268 | } | |
269 | ||
270 | privat e static v oid startD iscoverySe rvice(Prop erties pro ps) | |
271 | throws I OException { | |
272 | // Start dis covery ser vice if re quested | |
273 | St ring disco veryPort = props.get Property(" com.sun.ma nagement.j dp.port"); | |
274 | St ring disco veryAddres s = props. getPropert y("com.sun .managemen t.jdp.addr ess"); | |
275 | St ring disco veryShould Start = pr ops.getPro perty("com .sun.manag ement.jmxr emote.auto discovery" ); | |
276 | ||
277 | // Decide wh ether we s hould star t autodico very servi ce. | |
278 | // To start autodiscov ery follow ing condit ions shoul d be met: | |
279 | // autodisco very==true OR (autod icovery==n ull AND jd p.port != NULL) | |
280 | ||
281 | bo olean shou ldStart = false; | |
282 | if (discover yShouldSta rt == null ){ | |
283 | shouldSt art = (dis coveryPort != null); | |
284 | } | |
285 | el se{ | |
286 | try{ | |
287 | shoul dStart = B oolean.par seBoolean( discoveryS houldStart ); | |
288 | } catch (NumberFor matExcepti on e) { | |
289 | thro w new Agen tConfigura tionError( "Couldn't parse auto discovery argument") ; | |
290 | } | |
291 | } | |
292 | ||
293 | if (shouldSt art) { | |
294 | // port and addres s are requ ired argum ents and h ave no def ault value s | |
295 | InetAddr ess addres s; | |
296 | try { | |
297 | addr ess = (dis coveryAddr ess == nul l) ? | |
298 | InetAd dress.getB yName(JDP_ DEFAULT_AD DRESS) : I netAddress .getByName (discovery Address); | |
299 | } catch (UnknownHo stExceptio n e) { | |
300 | thro w new Agen tConfigura tionError( "Unable to broadcast to reques ted addres s", e); | |
301 | } | |
302 | ||
303 | int port = JDP_DEF AULT_PORT; | |
304 | if (disc overyPort != null) { | |
305 | try { | |
306 | po rt = Integ er.parseIn t(discover yPort); | |
307 | } cat ch (Number FormatExce ption e) { | |
308 | thr ow new Age ntConfigur ationError ("Couldn't parse JDP port argu ment"); | |
309 | } | |
310 | } | |
311 | ||
312 | // Rebui lding serv ice URL to broadcast it | |
313 | String j mxremotePo rt = props .getProper ty(JMXREMO TE_PORT); | |
314 | String r miPort = p rops.getPr operty(RMI _PORT); | |
315 | ||
316 | JMXServi ceURL url = jmxServe r.getAddre ss(); | |
317 | String h ostname = url.getHos t(); | |
318 | ||
319 | String j mxUrlStr = (rmiPort != null) | |
320 | ? String.f ormat( | |
321 | "service:j mx:rmi://% s:%s/jndi/ rmi://%s:% s/jmxrmi", | |
322 | hostname, rmiPort, h ostname, j mxremotePo rt) | |
323 | : String.f ormat( | |
324 | "service:j mx:rmi:/// jndi/rmi:/ /%s:%s/jmx rmi", host name, jmxr emotePort) ; | |
325 | ||
326 | String i nstanceNam e = props. getPropert y("com.sun .managemen t.jdp.name "); | |
327 | ||
328 | try{ | |
329 | JdpCo ntroller.s tartDiscov eryService (address, port, inst anceName, jmxUrlStr) ; | |
330 | } | |
331 | catch(Jd pException e){ | |
332 | thro w new Agen tConfigura tionError( "Couldn't start JDP service", e); | |
333 | } | |
334 | } | |
335 | } | |
336 | ||
337 | public static Pr operties l oadManagem entPropert ies() { | |
338 | Pr operties p rops = new Propertie s(); | |
339 | ||
340 | // Load the management propertie s from the config fi le | |
341 | ||
342 | St ring fname = System. getPropert y(CONFIG_F ILE); | |
343 | re adConfigur ation(fnam e, props); | |
344 | ||
345 | // managemen t properti es can be overridden by system propertie s | |
346 | // which tak e preceden ce | |
347 | Pr operties s ysProps = System.get Properties (); | |
348 | sy nchronized (sysProps ) { | |
349 | props.pu tAll(sysPr ops); | |
350 | } | |
351 | ||
352 | re turn props ; | |
353 | } | |
354 | ||
355 | public static sy nchronized Propertie s getManag ementPrope rties() { | |
356 | if (mgmtProp s == null) { | |
357 | String c onfigFile = System.g etProperty (CONFIG_FI LE); | |
358 | String s nmpPort = System.get Property(S NMP_PORT); | |
359 | String j mxremote = System.ge tProperty( JMXREMOTE) ; | |
360 | String j mxremotePo rt = Syste m.getPrope rty(JMXREM OTE_PORT); | |
361 | ||
362 | if (conf igFile == null && sn mpPort == null | |
363 | && jmxremo te == null && jmxrem otePort == null) { | |
364 | // r eturn if o ut-of-the- management option is not speci fied | |
365 | retu rn null; | |
366 | } | |
367 | mgmtProp s = loadMa nagementPr operties() ; | |
368 | } | |
369 | re turn mgmtP rops; | |
370 | } | |
371 | ||
372 | privat e static v oid loadSn mpAgent(St ring snmpP ort, Prope rties prop s) { | |
373 | tr y { | |
374 | // invok e the foll owing thro ugh reflec tion: | |
375 | // A daptorBoot strap.init ialize(snm pPort, pro ps); | |
376 | final Cl ass<?> ada ptorClass = | |
377 | Class.forN ame(SNMP_A DAPTOR_BOO TSTRAP_CLA SS_NAME, t rue, null) ; | |
378 | final Me thod initi alizeMetho d = | |
379 | adaptorCla ss.getMeth od("initia lize", | |
380 | String.cla ss, Proper ties.class ); | |
381 | initiali zeMethod.i nvoke(null , snmpPort , props); | |
382 | } catch (Cla ssNotFound Exception | NoSuchMe thodExcept ion | Ille galAccessE xception x ) { | |
383 | // snmp runtime do esn't exis t - initia lization f ails | |
384 | throw ne w Unsuppor tedOperati onExceptio n("Unsuppo rted manag ement prop erty: " + SNMP_PORT, x); | |
385 | } catch (Inv ocationTar getExcepti on x) { | |
386 | final Th rowable ca use = x.ge tCause(); | |
387 | if (caus e instance of Runtime Exception) { | |
388 | thro w (Runtime Exception) cause; | |
389 | } else i f (cause i nstanceof Error) { | |
390 | thro w (Error) cause; | |
391 | } | |
392 | // shoul d not happ en... | |
393 | throw ne w Unsuppor tedOperati onExceptio n("Unsuppo rted manag ement prop erty: " + SNMP_PORT, cause); | |
394 | } | |
395 | } | |
396 | ||
397 | // rea d config f ile and in itialize t he propert ies | |
398 | privat e static v oid readCo nfiguratio n(String f name, Prop erties p) { | |
399 | if (fname == null) { | |
400 | String h ome = Syst em.getProp erty("java .home"); | |
401 | if (home == null) { | |
402 | thro w new Erro r("Can't f ind java.h ome ??"); | |
403 | } | |
404 | StringBu ffer defau ltFileName = new Str ingBuffer( home); | |
405 | defaultF ileName.ap pend(File. separator) .append("l ib"); | |
406 | defaultF ileName.ap pend(File. separator) .append("m anagement" ); | |
407 | defaultF ileName.ap pend(File. separator) .append("m anagement. properties "); | |
408 | // Set f ile name | |
409 | fname = defaultFil eName.toSt ring(); | |
410 | } | |
411 | fi nal File c onfigFile = new File (fname); | |
412 | if (!configF ile.exists ()) { | |
413 | error(CO NFIG_FILE_ NOT_FOUND, fname); | |
414 | } | |
415 | ||
416 | In putStream in = null; | |
417 | tr y { | |
418 | in = new FileInput Stream(con figFile); | |
419 | Buffered InputStrea m bin = ne w Buffered InputStrea m(in); | |
420 | p.load(b in); | |
421 | } catch (Fil eNotFoundE xception e ) { | |
422 | error(CO NFIG_FILE_ OPEN_FAILE D, e.getMe ssage()); | |
423 | } catch (IOE xception e ) { | |
424 | error(CO NFIG_FILE_ OPEN_FAILE D, e.getMe ssage()); | |
425 | } catch (Sec urityExcep tion e) { | |
426 | error(CO NFIG_FILE_ ACCESS_DEN IED, fname ); | |
427 | } finally { | |
428 | if (in ! = null) { | |
429 | try { | |
430 | in.close() ; | |
431 | } ca tch (IOExc eption e) { | |
432 | error(CONF IG_FILE_CL OSE_FAILED , fname); | |
433 | } | |
434 | } | |
435 | } | |
436 | } | |
437 | ||
438 | public static vo id startAg ent() thro ws Excepti on { | |
439 | St ring prop = System.g etProperty ("com.sun. management .agent.cla ss"); | |
440 | ||
441 | // -Dcom.sun .managemen t.agent.cl ass not se t so read management | |
442 | // propertie s and star t agent | |
443 | if (prop == null) { | |
444 | // initi alize mana gement pro perties | |
445 | Properti es props = getManage mentProper ties(); | |
446 | if (prop s != null) { | |
447 | star tAgent(pro ps); | |
448 | } | |
449 | return; | |
450 | } | |
451 | ||
452 | // -Dcom.sun .managemen t.agent.cl ass=<agent classname >:<agent a rgs> | |
453 | St ring[] val ues = prop .split(":" ); | |
454 | if (values.l ength < 1 || values. length > 2 ) { | |
455 | error(AG ENT_CLASS_ INVALID, " \"" + prop + "\""); | |
456 | } | |
457 | St ring cname = values[ 0]; | |
458 | St ring args = (values. length == 2 ? values [1] : null ); | |
459 | ||
460 | if (cname == null || c name.lengt h() == 0) { | |
461 | error(AG ENT_CLASS_ INVALID, " \"" + prop + "\""); | |
462 | } | |
463 | ||
464 | if (cname != null) { | |
465 | try { | |
466 | // I nstantiate the named class. | |
467 | // i nvoke the premain(St ring args) method | |
468 | Clas s<?> clz = ClassLoad er.getSyst emClassLoa der().load Class(cnam e); | |
469 | Meth od premain = clz.get Method("pr emain", | |
470 | new Cl ass<?>[]{S tring.clas s}); | |
471 | prem ain.invoke (null, /* static */ | |
472 | new Ob ject[]{arg s}); | |
473 | } catch (ClassNotF oundExcept ion ex) { | |
474 | erro r(AGENT_CL ASS_NOT_FO UND, "\"" + cname + "\""); | |
475 | } catch (NoSuchMet hodExcepti on ex) { | |
476 | erro r(AGENT_CL ASS_PREMAI N_NOT_FOUN D, "\"" + cname + "\ ""); | |
477 | } catch (SecurityE xception e x) { | |
478 | erro r(AGENT_CL ASS_ACCESS _DENIED); | |
479 | } catch (Exception ex) { | |
480 | Stri ng msg = ( ex.getCaus e() == nul l | |
481 | ? ex.g etMessage( ) | |
482 | : ex.g etCause(). getMessage ()); | |
483 | erro r(AGENT_CL ASS_FAILED , msg); | |
484 | } | |
485 | } | |
486 | } | |
487 | ||
488 | public static vo id error(S tring key) { | |
489 | St ring keyTe xt = getTe xt(key); | |
490 | Sy stem.err.p rint(getTe xt("agent. err.error" ) + ": " + keyText); | |
491 | th row new Ru ntimeExcep tion(keyTe xt); | |
492 | } | |
493 | ||
494 | public static vo id error(S tring key, String[] params) { | |
495 | if (params = = null || params.len gth == 0) { | |
496 | error(ke y); | |
497 | } else { | |
498 | StringBu ffer messa ge = new S tringBuffe r(params[0 ]); | |
499 | for (int i = 1; i < params.l ength; i++ ) { | |
500 | mess age.append (" " + par ams[i]); | |
501 | } | |
502 | error(ke y, message .toString( )); | |
503 | } | |
504 | } | |
505 | ||
506 | public static vo id error(S tring key, String me ssage) { | |
507 | St ring keyTe xt = getTe xt(key); | |
508 | Sy stem.err.p rint(getTe xt("agent. err.error" ) + ": " + keyText); | |
509 | Sy stem.err.p rintln(": " + messag e); | |
510 | th row new Ru ntimeExcep tion(keyTe xt); | |
511 | } | |
512 | ||
513 | public static vo id error(E xception e ) { | |
514 | e. printStack Trace(); | |
515 | Sy stem.err.p rintln(get Text(AGENT _EXCEPTION ) + ": " + e.toStrin g()); | |
516 | th row new Ru ntimeExcep tion(e); | |
517 | } | |
518 | ||
519 | public static vo id warning (String ke y, String message) { | |
520 | Sy stem.err.p rint(getTe xt("agent. err.warnin g") + ": " + getText (key)); | |
521 | Sy stem.err.p rintln(": " + messag e); | |
522 | } | |
523 | ||
524 | privat e static v oid initRe source() { | |
525 | tr y { | |
526 | messageR B = | |
527 | ResourceBu ndle.getBu ndle("sun. management .resources .agent"); | |
528 | } catch (Mis singResour ceExceptio n e) { | |
529 | throw ne w Error("F atal: Reso urce for m anagement agent is m issing"); | |
530 | } | |
531 | } | |
532 | ||
533 | public static St ring getTe xt(String key) { | |
534 | if (messageR B == null) { | |
535 | initReso urce(); | |
536 | } | |
537 | tr y { | |
538 | return m essageRB.g etString(k ey); | |
539 | } catch (Mis singResour ceExceptio n e) { | |
540 | return " Missing ma nagement a gent resou rce bundle : key = \" " + key + "\""; | |
541 | } | |
542 | } | |
543 | ||
544 | public static St ring getTe xt(String key, Strin g... args) { | |
545 | if (messageR B == null) { | |
546 | initReso urce(); | |
547 | } | |
548 | St ring forma t = messag eRB.getStr ing(key); | |
549 | if (format = = null) { | |
550 | format = "missing resource k ey: key = \"" + key + "\", " | |
551 | + "argumen ts = \"{0} \", \"{1}\ ", \"{2}\" "; | |
552 | } | |
553 | re turn Messa geFormat.f ormat(form at, (Objec t[]) args) ; | |
554 | } | |
555 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.