Produced by Araxis Merge on 9/25/2018 2:13:11 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\javax\management\remote\rmi | RMIConnectorServer.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\management\remote\rmi | RMIConnectorServer.java | Wed Sep 12 17:21:11 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 1704 |
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 2, 2017, 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 ja vax.manage ment.remot e.rmi; | |
27 | ||
28 | ||
29 | import com .sun.jmx.r emote.secu rity.MBean ServerFile AccessCont roller; | |
30 | import com .sun.jmx.r emote.inte rnal.IIOPH elper; | |
31 | import com .sun.jmx.r emote.util .ClassLogg er; | |
32 | import com .sun.jmx.r emote.util .EnvHelp; | |
33 | ||
34 | import jav a.io.ByteA rrayOutput Stream; | |
35 | import jav a.io.IOExc eption; | |
36 | import sun .misc.Obje ctInputFil ter; | |
37 | import jav a.io.Objec tOutputStr eam; | |
38 | import jav a.net.Malf ormedURLEx ception; | |
39 | import jav a.rmi.serv er.RMIClie ntSocketFa ctory; | |
40 | import jav a.rmi.serv er.RMIServ erSocketFa ctory; | |
41 | import jav a.util.Col lections; | |
42 | import jav a.util.Has hMap; | |
43 | import jav a.util.Has hSet; | |
44 | import jav a.util.Has htable; | |
45 | import jav a.util.Map ; | |
46 | import jav a.util.Set ; | |
47 | ||
48 | import jav ax.managem ent.Instan ceNotFound Exception; | |
49 | import jav ax.managem ent.MBeanS erver; | |
50 | ||
51 | import jav ax.managem ent.remote .JMXConnec tionNotifi cation; | |
52 | import jav ax.managem ent.remote .JMXConnec tor; | |
53 | import jav ax.managem ent.remote .JMXConnec torServer; | |
54 | import jav ax.managem ent.remote .JMXServic eURL; | |
55 | import jav ax.managem ent.remote .MBeanServ erForwarde r; | |
56 | ||
57 | import jav ax.naming. InitialCon text; | |
58 | import jav ax.naming. NamingExce ption; | |
59 | ||
60 | /** | |
61 | * <p>A JM X API conn ector serv er that cr eates RMI- based conn ections | |
62 | * from re mote clien ts. Usual ly, such c onnector s ervers are made | |
63 | * using { @link java x.manageme nt.remote. JMXConnect orServerFa ctory | |
64 | * JMXConn ectorServe rFactory}. However, specializ ed applica tions can | |
65 | * use thi s class di rectly, fo r example with an {@ link RMISe rverImpl} | |
66 | * object. </p> | |
67 | * | |
68 | * @since 1.5 | |
69 | */ | |
70 | public cla ss RMIConn ectorServe r extends JMXConnect orServer { | |
71 | /** | |
72 | * <p> Name of th e attribut e that spe cifies whe ther the { @link | |
73 | * RMI Server} st ub that re presents a n RMI conn ector serv er should | |
74 | * ove rride an e xisting st ub at the same addre ss. The v alue | |
75 | * ass ociated wi th this at tribute, i f any, sho uld be a s tring that | |
76 | * is equal, ign oring case , to <code >"true"</c ode> or | |
77 | * <co de>"false" </code>. The defaul t value is false.</p > | |
78 | */ | |
79 | public static fi nal String JNDI_REBI ND_ATTRIBU TE = | |
80 | "j mx.remote. jndi.rebin d"; | |
81 | ||
82 | /** | |
83 | * <p> Name of th e attribut e that spe cifies the {@link | |
84 | * RMI ClientSock etFactory} for the R MI objects created i n | |
85 | * con junction w ith this c onnector. The value associated with this | |
86 | * att ribute mus t be of ty pe <code>R MIClientSo cketFactor y</code> a nd can | |
87 | * onl y be speci fied in th e <code>Ma p</code> a rgument su pplied whe n | |
88 | * cre ating a co nnector se rver.</p> | |
89 | */ | |
90 | public static fi nal String RMI_CLIEN T_SOCKET_F ACTORY_ATT RIBUTE = | |
91 | "j mx.remote. rmi.client .socket.fa ctory"; | |
92 | ||
93 | /** | |
94 | * <p> Name of th e attribut e that spe cifies the {@link | |
95 | * RMI ServerSock etFactory} for the R MI objects created i n | |
96 | * con junction w ith this c onnector. The value associated with this | |
97 | * att ribute mus t be of ty pe <code>R MIServerSo cketFactor y</code> a nd can | |
98 | * onl y be speci fied in th e <code>Ma p</code> a rgument su pplied whe n | |
99 | * cre ating a co nnector se rver.</p> | |
100 | */ | |
101 | public static fi nal String RMI_SERVE R_SOCKET_F ACTORY_ATT RIBUTE = | |
102 | "j mx.remote. rmi.server .socket.fa ctory"; | |
103 | ||
104 | /** | |
105 | * <p> Makes an < code>RMICo nnectorSer ver</code> . | |
106 | * Thi s is equiv alent to c alling {@l ink #RMICo nnectorSer ver( | |
107 | * JMX ServiceURL ,Map,RMISe rverImpl,M BeanServer ) | |
108 | * RMI ConnectorS erver(dire ctoryURL,e nvironment ,null,null )}</p> | |
109 | * | |
110 | * @pa ram url th e URL defi ning how t o create t he connect or server. | |
111 | * Can not be nul l. | |
112 | * | |
113 | * @pa ram enviro nment attr ibutes gov erning the creation and | |
114 | * sto ring of th e RMI obje ct. Can b e null, wh ich is equ ivalent to | |
115 | * an empty Map. | |
116 | * | |
117 | * @ex ception Il legalArgum entExcepti on if <cod e>url</cod e> is null . | |
118 | * | |
119 | * @ex ception Ma lformedURL Exception if <code>u rl</code> does not | |
120 | * con form to th e syntax f or an RMI connector, or if its protocol | |
121 | * is not recogn ized by th is impleme ntation. O nly "rmi" and "iiop" | |
122 | * are valid whe n this con structor i s used. | |
123 | * | |
124 | * @ex ception IO Exception if the con nector ser ver cannot be create d | |
125 | * for some reas on or if i t is inevi table that its {@lin k #start() | |
126 | * sta rt} method will fail . | |
127 | */ | |
128 | public RMIConnec torServer( JMXService URL url, M ap<String, ?> environ ment) | |
129 | throws I OException { | |
130 | th is(url, en vironment, (MBeanSer ver) null) ; | |
131 | } | |
132 | ||
133 | /** | |
134 | * <p> Makes an < code>RMICo nnectorSer ver</code> for the g iven MBean | |
135 | * ser ver. | |
136 | * Thi s is equiv alent to c alling {@l ink #RMICo nnectorSer ver( | |
137 | * JMX ServiceURL ,Map,RMISe rverImpl,M BeanServer ) | |
138 | * RMI ConnectorS erver(dire ctoryURL,e nvironment ,null,mbea nServer)}< /p> | |
139 | * | |
140 | * @pa ram url th e URL defi ning how t o create t he connect or server. | |
141 | * Can not be nul l. | |
142 | * | |
143 | * @pa ram enviro nment attr ibutes gov erning the creation and | |
144 | * sto ring of th e RMI obje ct. Can b e null, wh ich is equ ivalent to | |
145 | * an empty Map. | |
146 | * | |
147 | * @pa ram mbeanS erver the MBean serv er to whic h the new connector | |
148 | * ser ver is att ached, or null if it will be a ttached by being | |
149 | * reg istered as an MBean in the MBe an server. | |
150 | * | |
151 | * @ex ception Il legalArgum entExcepti on if <cod e>url</cod e> is null . | |
152 | * | |
153 | * @ex ception Ma lformedURL Exception if <code>u rl</code> does not | |
154 | * con form to th e syntax f or an RMI connector, or if its protocol | |
155 | * is not recogn ized by th is impleme ntation. O nly "rmi" and "iiop" | |
156 | * are valid whe n this con structor i s used. | |
157 | * | |
158 | * @ex ception IO Exception if the con nector ser ver cannot be create d | |
159 | * for some reas on or if i t is inevi table that its {@lin k #start() | |
160 | * sta rt} method will fail . | |
161 | */ | |
162 | public RMIConnec torServer( JMXService URL url, M ap<String, ?> environ ment, | |
163 | MBeanServe r mbeanSer ver) | |
164 | throws I OException { | |
165 | th is(url, en vironment, (RMIServe rImpl) nul l, mbeanSe rver); | |
166 | } | |
167 | ||
168 | /** | |
169 | * <p> Makes an < code>RMICo nnectorSer ver</code> for the g iven MBean | |
170 | * ser ver.</p> | |
171 | * | |
172 | * @pa ram url th e URL defi ning how t o create t he connect or server. | |
173 | * Can not be nul l. | |
174 | * | |
175 | * @pa ram enviro nment attr ibutes gov erning the creation and | |
176 | * sto ring of th e RMI obje ct. Can b e null, wh ich is equ ivalent to | |
177 | * an empty Map. | |
178 | * | |
179 | * @pa ram rmiSer verImpl An implement ation of t he RMIServ er interfa ce, | |
180 | * co nsistent w ith the pr otocol typ e specifie d in <var> url</var>. | |
181 | * If this para meter is n on null, t he protoco l type spe cified by | |
182 | * <v ar>url</va r> is not constraine d, and is assumed to be valid. | |
183 | * Ot herwise, o nly "rmi" and "iiop" will be r ecognized. | |
184 | * | |
185 | * @pa ram mbeanS erver the MBean serv er to whic h the new connector | |
186 | * ser ver is att ached, or null if it will be a ttached by being | |
187 | * reg istered as an MBean in the MBe an server. | |
188 | * | |
189 | * @ex ception Il legalArgum entExcepti on if <cod e>url</cod e> is null . | |
190 | * | |
191 | * @ex ception Ma lformedURL Exception if <code>u rl</code> does not | |
192 | * con form to th e syntax f or an RMI connector, or if its protocol | |
193 | * is not recogn ized by th is impleme ntation. O nly "rmi" and "iiop" | |
194 | * are recognize d when <va r>rmiServe rImpl</var > is null. | |
195 | * | |
196 | * @ex ception IO Exception if the con nector ser ver cannot be create d | |
197 | * for some reas on or if i t is inevi table that its {@lin k #start() | |
198 | * sta rt} method will fail . | |
199 | * | |
200 | * @se e #start | |
201 | */ | |
202 | public RMIConnec torServer( JMXService URL url, M ap<String, ?> environ ment, | |
203 | RMIServerI mpl rmiSer verImpl, | |
204 | MBeanServe r mbeanSer ver) | |
205 | throws I OException { | |
206 | su per(mbeanS erver); | |
207 | ||
208 | if (url == n ull) throw new | |
209 | IllegalA rgumentExc eption("Nu ll JMXServ iceURL"); | |
210 | if (rmiServe rImpl == n ull) { | |
211 | final St ring prt = url.getPr otocol(); | |
212 | if (prt == null || !(prt.equ als("rmi") || prt.eq uals("iiop "))) { | |
213 | fina l String m sg = "Inva lid protoc ol type: " + prt; | |
214 | thro w new Malf ormedURLEx ception(ms g); | |
215 | } | |
216 | final St ring urlPa th = url.g etURLPath( ); | |
217 | if (!url Path.equal s("") | |
218 | && ! urlPath.eq uals("/") | |
219 | && ! urlPath.st artsWith(" /jndi/")) { | |
220 | fina l String m sg = "URL path must be empty o r start wi th " + | |
221 | "/jndi/"; | |
222 | thro w new Malf ormedURLEx ception(ms g); | |
223 | } | |
224 | } | |
225 | ||
226 | if (environm ent == nul l) | |
227 | this.att ributes = Collection s.emptyMap (); | |
228 | el se { | |
229 | EnvHelp. checkAttri butes(envi ronment); | |
230 | this.att ributes = Collection s.unmodifi ableMap(en vironment) ; | |
231 | } | |
232 | ||
233 | th is.address = url; | |
234 | th is.rmiServ erImpl = r miServerIm pl; | |
235 | } | |
236 | ||
237 | /** | |
238 | * <p> Returns a client stu b for this connector server. A client | |
239 | * stu b is a ser ializable object who se {@link | |
240 | * JMX Connector# connect(Ma p) connect } method c an be used to make | |
241 | * one new conne ction to t his connec tor server .</p> | |
242 | * | |
243 | * @pa ram env cl ient conne ction para meters of the same s ort that | |
244 | * cou ld be prov ided to {@ link JMXCo nnector#co nnect(Map) | |
245 | * JMX Connector. connect(Ma p)}. Can be null, w hich is eq uivalent | |
246 | * to an empty m ap. | |
247 | * | |
248 | * @re turn a cli ent stub t hat can be used to m ake a new connection | |
249 | * to this conne ctor serve r. | |
250 | * | |
251 | * @ex ception Un supportedO perationEx ception if this conn ector | |
252 | * ser ver does n ot support the gener ation of c lient stub s. | |
253 | * | |
254 | * @ex ception Il legalState Exception if the JMX ConnectorS erver is | |
255 | * not started ( see {@link #isActive ()}). | |
256 | * | |
257 | * @ex ception IO Exception if a commu nications problem me ans that a | |
258 | * stu b cannot b e created. | |
259 | **/ | |
260 | public JMXConnec tor toJMXC onnector(M ap<String, ?> env) th rows IOExc eption { | |
261 | // The seria lized for of rmiServ erImpl is automatica lly | |
262 | // a RMI ser ver stub. | |
263 | if (!isActiv e()) throw new | |
264 | IllegalS tateExcept ion("Conne ctor is no t active") ; | |
265 | ||
266 | // Merge map s | |
267 | Ma p<String, Object> us emap = new HashMap<S tring, Obj ect>( | |
268 | (thi s.attribut es==null)? Collection s.<String, Object>em ptyMap(): | |
269 | this.attri butes); | |
270 | ||
271 | if (env != n ull) { | |
272 | EnvHelp. checkAttri butes(env) ; | |
273 | usemap.p utAll(env) ; | |
274 | } | |
275 | ||
276 | us emap = Env Help.filte rAttribute s(usemap); | |
277 | ||
278 | fi nal RMISer ver stub=( RMIServer) rmiServerI mpl.toStub (); | |
279 | ||
280 | re turn new R MIConnecto r(stub, us emap); | |
281 | } | |
282 | ||
283 | /** | |
284 | * <p> Activates the connec tor server , that is starts lis tening for | |
285 | * cli ent connec tions. Ca lling this method wh en the con nector | |
286 | * ser ver is alr eady activ e has no e ffect. Ca lling this method | |
287 | * whe n the conn ector serv er has bee n stopped will gener ate an | |
288 | * <co de>IOExcep tion</code >.</p> | |
289 | * | |
290 | * <p> The behavi or of this method wh en called for the fi rst time | |
291 | * dep ends on th e paramete rs that we re supplie d at const ruction, | |
292 | * as described below.</p> | |
293 | * | |
294 | * <p> First, an object of a subclass of {@link RMIServer Impl} is | |
295 | * req uired, to export the connector server th rough RMI: </p> | |
296 | * | |
297 | * <ul > | |
298 | * | |
299 | * <li >If an <co de>RMIServ erImpl</co de> was su pplied to the | |
300 | * con structor, it is used . | |
301 | * | |
302 | * <li >Otherwise , if the p rotocol pa rt of the | |
303 | * <co de>JMXServ iceURL</co de> suppli ed to the constructo r was | |
304 | * <co de>iiop</c ode>, an o bject of t ype {@link RMIIIOPSe rverImpl} | |
305 | * is created. | |
306 | * | |
307 | * <li >Otherwise , if the < code>JMXSe rviceURL</ code> | |
308 | * was null, or its protoc ol part wa s <code>rm i</code>, an object | |
309 | * of type {@lin k RMIJRMPS erverImpl} is create d. | |
310 | * | |
311 | * <li >Otherwise , the impl ementation can creat e an | |
312 | * imp lementatio n-specific {@link RM IServerImp l} or it c an throw | |
313 | * {@l ink Malfor medURLExce ption}. | |
314 | * | |
315 | * </u l> | |
316 | * | |
317 | * <p> If the giv en address includes a JNDI dir ectory URL as | |
318 | * spe cified in the packag e document ation for {@link | |
319 | * jav ax.managem ent.remote .rmi}, the n this | |
320 | * <co de>RMIConn ectorServe r</code> w ill bootst rap by bin ding the | |
321 | * <co de>RMIServ erImpl</co de> to the given add ress.</p> | |
322 | * | |
323 | * <p> If the URL path part of the <c ode>JMXSer viceURL</c ode> was | |
324 | * emp ty or a si ngle slash (<code>/< /code>), t hen the RM I object | |
325 | * wil l not be b ound to a directory. Instead, a referen ce to it | |
326 | * wil l be encod ed in the URL path o f the RMIC onnectorSe rver | |
327 | * add ress (retu rned by {@ link #getA ddress()}) . The enc odings for | |
328 | * <co de>rmi</co de> and <c ode>iiop</ code> are described in the | |
329 | * pac kage docum entation f or {@link | |
330 | * jav ax.managem ent.remote .rmi}.</p> | |
331 | * | |
332 | * <p> The behavi or when th e URL path is neithe r empty no r a JNDI | |
333 | * dir ectory URL , or when the protoc ol is neit her <code> rmi</code> | |
334 | * nor <code>iio p</code>, is impleme ntation de fined, and may | |
335 | * inc lude throw ing {@link Malformed URLExcepti on} when t he | |
336 | * con nector ser ver is cre ated or wh en it is s tarted.</p > | |
337 | * | |
338 | * @ex ception Il legalState Exception if the con nector ser ver has | |
339 | * not been atta ched to an MBean ser ver. | |
340 | * @ex ception IO Exception if the con nector ser ver cannot be | |
341 | * sta rted, or i n the case of the {@ code iiop} protocol, that | |
342 | * RMI /IIOP is n ot support ed. | |
343 | */ | |
344 | public synchroni zed void s tart() thr ows IOExce ption { | |
345 | fi nal boolea n tracing = logger.t raceOn(); | |
346 | ||
347 | if (state == STARTED) { | |
348 | if (trac ing) logge r.trace("s tart", "al ready star ted"); | |
349 | return; | |
350 | } else if (s tate == ST OPPED) { | |
351 | if (trac ing) logge r.trace("s tart", "al ready stop ped"); | |
352 | throw ne w IOExcept ion("The s erver has been stopp ed."); | |
353 | } | |
354 | ||
355 | if (getMBean Server() = = null) | |
356 | throw ne w IllegalS tateExcept ion("This connector server is not " + | |
357 | "attac hed to an MBean serv er"); | |
358 | ||
359 | // Check the internal access fil e property to see | |
360 | // if an MBe anServerFo rwarder is to be pro vided | |
361 | // | |
362 | if (attribut es != null ) { | |
363 | // Check if access file prop erty is sp ecified | |
364 | // | |
365 | String a ccessFile = | |
366 | (Str ing) attri butes.get( "jmx.remot e.x.access .file"); | |
367 | if (acce ssFile != null) { | |
368 | // A ccess file property specified, create an instance | |
369 | // o f the MBea nServerFil eAccessCon troller cl ass | |
370 | // | |
371 | MBea nServerFor warder mbs f; | |
372 | try { | |
373 | mbsf = new MBeanServ erFileAcce ssControll er(accessF ile); | |
374 | } ca tch (IOExc eption e) { | |
375 | throw EnvH elp.initCa use( | |
376 | new Il legalArgum entExcepti on(e.getMe ssage()), e); | |
377 | } | |
378 | // S et the MBe anServerFo rwarder | |
379 | // | |
380 | setM BeanServer Forwarder( mbsf); | |
381 | } | |
382 | } | |
383 | ||
384 | tr y { | |
385 | if (trac ing) logge r.trace("s tart", "se tting defa ult class loader"); | |
386 | defaultC lassLoader = EnvHelp .resolveSe rverClassL oader( | |
387 | attributes , getMBean Server()); | |
388 | } catch (Ins tanceNotFo undExcepti on infc) { | |
389 | IllegalA rgumentExc eption x = new | |
390 | Ille galArgumen tException ("ClassLoa der not fo und: "+inf c); | |
391 | throw En vHelp.init Cause(x,in fc); | |
392 | } | |
393 | ||
394 | if (tracing) logger.tr ace("start ", "settin g RMIServe r object") ; | |
395 | fi nal RMISer verImpl rm iServer; | |
396 | ||
397 | if (rmiServe rImpl != n ull) | |
398 | rmiServe r = rmiSer verImpl; | |
399 | el se | |
400 | rmiServe r = newSer ver(); | |
401 | ||
402 | rm iServer.se tMBeanServ er(getMBea nServer()) ; | |
403 | rm iServer.se tDefaultCl assLoader( defaultCla ssLoader); | |
404 | rm iServer.se tRMIConnec torServer( this); | |
405 | rm iServer.ex port(); | |
406 | ||
407 | tr y { | |
408 | if (trac ing) logge r.trace("s tart", "ge tting RMIS erver obje ct to expo rt"); | |
409 | final RM IServer ob jref = obj ectToBind( rmiServer, attribute s); | |
410 | ||
411 | if (addr ess != nul l && addre ss.getURLP ath().star tsWith("/j ndi/")) { | |
412 | fina l String j ndiUrl = a ddress.get URLPath(). substring( 6); | |
413 | ||
414 | if ( tracing) | |
415 | logger.tra ce("start" , "Using e xternal di rectory: " + jndiUrl ); | |
416 | ||
417 | Stri ng stringB oolean = ( String) at tributes.g et(JNDI_RE BIND_ATTRI BUTE); | |
418 | fina l boolean rebind = E nvHelp.com puteBoolea nFromStrin g( stringB oolean ); | |
419 | ||
420 | if ( tracing) | |
421 | logger.tra ce("start" , JNDI_REB IND_ATTRIB UTE + "=" + rebind); | |
422 | ||
423 | try { | |
424 | if (tracin g) logger. trace("sta rt", "bind ing to " + jndiUrl); | |
425 | ||
426 | final Hash table<?, ? > usemap = EnvHelp.m apToHashta ble(attrib utes); | |
427 | ||
428 | bind(jndiU rl, usemap , objref, rebind); | |
429 | ||
430 | boundJndiU rl = jndiU rl; | |
431 | } ca tch (Namin gException e) { | |
432 | // fit e i n the nest ed excepti on if we a re on 1.4 | |
433 | throw newI OException ("Cannot b ind to URL ["+jndiUr l+"]: " | |
434 | + e, e); | |
435 | } | |
436 | } else { | |
437 | // i f jndiURL is null, w e must enc ode the st ub into th e URL. | |
438 | if ( tracing) l ogger.trac e("start", "Encoding URL"); | |
439 | ||
440 | enco deStubInAd dress(objr ef, attrib utes); | |
441 | ||
442 | if ( tracing) l ogger.trac e("start", "Encoded URL: " + t his.addres s); | |
443 | } | |
444 | } catch (Exc eption e) { | |
445 | try { | |
446 | rmiS erver.clos e(); | |
447 | } catch (Exception x) { | |
448 | // O K: we are already th rowing ano ther excep tion | |
449 | } | |
450 | if (e in stanceof R untimeExce ption) | |
451 | thro w (Runtime Exception) e; | |
452 | else if (e instanc eof IOExce ption) | |
453 | thro w (IOExcep tion) e; | |
454 | else | |
455 | thro w newIOExc eption("Go t unexpect ed excepti on while " + | |
456 | "st arting the connector server: " | |
457 | + e , e); | |
458 | } | |
459 | ||
460 | rm iServerImp l = rmiSer ver; | |
461 | ||
462 | sy nchronized (openedSer vers) { | |
463 | openedSe rvers.add( this); | |
464 | } | |
465 | ||
466 | st ate = STAR TED; | |
467 | ||
468 | if (tracing) { | |
469 | logger.t race("star t", "Conne ctor Serve r Address = " + addr ess); | |
470 | logger.t race("star t", "start ed."); | |
471 | } | |
472 | } | |
473 | ||
474 | /** | |
475 | * <p> Deactivate s the conn ector serv er, that i s, stops l istening f or | |
476 | * cli ent connec tions. Ca lling this method wi ll also cl ose all | |
477 | * cli ent connec tions that were made by this s erver. Af ter this | |
478 | * met hod return s, whether normally or with an exception , the | |
479 | * con nector ser ver will n ot create any new cl ient | |
480 | * con nections.< /p> | |
481 | * | |
482 | * <p> Once a con nector ser ver has be en stopped , it canno t be start ed | |
483 | * aga in.</p> | |
484 | * | |
485 | * <p> Calling th is method when the c onnector s erver has already | |
486 | * bee n stopped has no eff ect. Call ing this m ethod when the | |
487 | * con nector ser ver has no t yet been started w ill disabl e the | |
488 | * con nector ser ver object permanent ly.</p> | |
489 | * | |
490 | * <p> If closing a client connection produces an excepti on, that | |
491 | * exc eption is not thrown from this method. A {@link | |
492 | * JMX Connection Notificati on} is emi tted from this MBean with the | |
493 | * con nection ID of the co nnection t hat could not be clo sed.</p> | |
494 | * | |
495 | * <p> Closing a connector server is a potentia lly slow o peration. | |
496 | * For example, if a clien t machine with an op en connect ion has | |
497 | * cra shed, the close oper ation migh t have to wait for a network | |
498 | * pro tocol time out. Call ers that d o not want to block in a close | |
499 | * ope ration sho uld do it in a separ ate thread .</p> | |
500 | * | |
501 | * <p> This metho d calls th e method { @link RMIS erverImpl# close() | |
502 | * clo se} on the connector server's <code>RMIS erverImpl< /code> | |
503 | * obj ect.</p> | |
504 | * | |
505 | * <p> If the <co de>RMIServ erImpl</co de> was bo und to a J NDI | |
506 | * dir ectory by the {@link #start() start} met hod, it is unbound | |
507 | * fro m the dire ctory by t his method .</p> | |
508 | * | |
509 | * @ex ception IO Exception if the ser ver cannot be closed cleanly, | |
510 | * or if the <co de>RMIServ erImpl</co de> cannot be unboun d from the | |
511 | * dir ectory. W hen this e xception i s thrown, the server has | |
512 | * alr eady attem pted to cl ose all cl ient conne ctions, if | |
513 | * app ropriate; to call {@ link RMISe rverImpl#c lose()}; a nd to | |
514 | * unb ind the <c ode>RMISer verImpl</c ode> from its direct ory, if | |
515 | * app ropriate. All clien t connecti ons are cl osed excep t possibly | |
516 | * tho se that ge nerated ex ceptions w hen the se rver attem pted to | |
517 | * clo se them. | |
518 | */ | |
519 | public void stop () throws IOExceptio n { | |
520 | fi nal boolea n tracing = logger.t raceOn(); | |
521 | ||
522 | sy nchronized (this) { | |
523 | if (stat e == STOPP ED) { | |
524 | if ( tracing) l ogger.trac e("stop"," already st opped."); | |
525 | retu rn; | |
526 | } else i f (state = = CREATED) { | |
527 | if ( tracing) l ogger.trac e("stop"," not starte d yet."); | |
528 | } | |
529 | ||
530 | if (trac ing) logge r.trace("s top", "sto pping."); | |
531 | state = STOPPED; | |
532 | } | |
533 | ||
534 | sy nchronized (openedSer vers) { | |
535 | openedSe rvers.remo ve(this); | |
536 | } | |
537 | ||
538 | IO Exception exception = null; | |
539 | ||
540 | // rmiServer Impl can b e null if stop() cal led withou t start() | |
541 | if (rmiServe rImpl != n ull) { | |
542 | try { | |
543 | if ( tracing) l ogger.trac e("stop", "closing R MI server. "); | |
544 | rmiS erverImpl. close(); | |
545 | } catch (IOExcepti on e) { | |
546 | if ( tracing) l ogger.trac e("stop", "failed to close RMI server: " + e); | |
547 | if ( logger.deb ugOn()) lo gger.debug ("stop",e) ; | |
548 | exce ption = e; | |
549 | } | |
550 | } | |
551 | ||
552 | if (boundJnd iUrl != nu ll) { | |
553 | try { | |
554 | if ( tracing) | |
555 | logger.tra ce("stop", | |
556 | "unb ind from e xternal di rectory: " + boundJn diUrl); | |
557 | ||
558 | fina l Hashtabl e<?, ?> us emap = Env Help.mapTo Hashtable( attributes ); | |
559 | ||
560 | Init ialContext ctx = | |
561 | new Initia lContext(u semap); | |
562 | ||
563 | ctx. unbind(bou ndJndiUrl) ; | |
564 | ||
565 | ctx. close(); | |
566 | } catch (NamingExc eption e) { | |
567 | if ( tracing) l ogger.trac e("stop", "failed to unbind RM I server: "+e); | |
568 | if ( logger.deb ugOn()) lo gger.debug ("stop",e) ; | |
569 | // f it e in as the neste d exceptio n if we ar e on 1.4 | |
570 | if ( exception == null) | |
571 | exception = newIOExc eption("Ca nnot bind to URL: " + e, e); | |
572 | } | |
573 | } | |
574 | ||
575 | if (exceptio n != null) throw exc eption; | |
576 | ||
577 | if (tracing) logger.tr ace("stop" , "stopped "); | |
578 | } | |
579 | ||
580 | public synchroni zed boolea n isActive () { | |
581 | re turn (stat e == START ED); | |
582 | } | |
583 | ||
584 | public JMXServic eURL getAd dress() { | |
585 | if (!isActiv e()) | |
586 | return n ull; | |
587 | re turn addre ss; | |
588 | } | |
589 | ||
590 | public Map<Strin g,?> getAt tributes() { | |
591 | Ma p<String, ?> map = E nvHelp.fil terAttribu tes(attrib utes); | |
592 | re turn Colle ctions.unm odifiableM ap(map); | |
593 | } | |
594 | ||
595 | @Overr ide | |
596 | public synchroni zed | |
597 | vo id setMBea nServerFor warder(MBe anServerFo rwarder mb sf) { | |
598 | su per.setMBe anServerFo rwarder(mb sf); | |
599 | if (rmiServe rImpl != n ull) | |
600 | rmiServe rImpl.setM BeanServer (getMBeanS erver()); | |
601 | } | |
602 | ||
603 | /* We repeat the definitio ns of conn ection{Ope ned,Closed ,Failed} | |
604 | her e so that they are a ccessible to other c lasses in this packa ge | |
605 | eve n though t hey have p rotected a ccess. */ | |
606 | ||
607 | @Overr ide | |
608 | protec ted void c onnectionO pened(Stri ng connect ionId, Str ing messag e, | |
609 | Obje ct userDat a) { | |
610 | su per.connec tionOpened (connectio nId, messa ge, userDa ta); | |
611 | } | |
612 | ||
613 | @Overr ide | |
614 | protec ted void c onnectionC losed(Stri ng connect ionId, Str ing messag e, | |
615 | Obje ct userDat a) { | |
616 | su per.connec tionClosed (connectio nId, messa ge, userDa ta); | |
617 | } | |
618 | ||
619 | @Overr ide | |
620 | protec ted void c onnectionF ailed(Stri ng connect ionId, Str ing messag e, | |
621 | Obje ct userDat a) { | |
622 | su per.connec tionFailed (connectio nId, messa ge, userDa ta); | |
623 | } | |
624 | ||
625 | /** | |
626 | * Bin d a stub t o a regist ry. | |
627 | * @pa ram jndiUr l URL of t he stub in the regis try, extra cted | |
628 | * from t he <code>J MXServiceU RL</code>. | |
629 | * @pa ram attrib utes A Has htable con taining en vironment parameters , | |
630 | * built from the M ap specifi ed at this object cr eation. | |
631 | * @pa ram rmiSer ver The ob ject to bi nd in the registry | |
632 | * @pa ram rebind true if t he object must be re bound. | |
633 | **/ | |
634 | void b ind(String jndiUrl, Hashtable< ?, ?> attr ibutes, | |
635 | RMISer ver rmiSer ver, boole an rebind) | |
636 | th rows Namin gException , Malforme dURLExcept ion { | |
637 | // if jndiUR L is not n ull, we nu st bind th e stub to a | |
638 | // directory . | |
639 | In itialConte xt ctx = | |
640 | new Init ialContext (attribute s); | |
641 | ||
642 | if (rebind) | |
643 | ctx.rebi nd(jndiUrl , rmiServe r); | |
644 | el se | |
645 | ctx.bind (jndiUrl, rmiServer) ; | |
646 | ct x.close(); | |
647 | } | |
648 | ||
649 | /** | |
650 | * Cre ates a new RMIServer Impl. | |
651 | **/ | |
652 | RMISer verImpl ne wServer() throws IOE xception { | |
653 | fi nal boolea n iiop = i sIiopURL(a ddress,tru e); | |
654 | fi nal int po rt; | |
655 | if (address == null) | |
656 | PORT ; | |
657 | el se | |
658 | port = a ddress.get Port(); | |
659 | if (iiop) | |
660 | return n ewIIOPServ er(attribu tes); | |
661 | el se | |
662 | return n ewJRMPServ er(attribu tes, port) ; | |
663 | } | |
664 | ||
665 | /** | |
666 | * Enc ode a stub into the JMXService URL. | |
667 | * @pa ram rmiSer ver The st ub object to encode in the URL | |
668 | * @pa ram attrib utes A Map containin g environm ent parame ters, | |
669 | * built from the M ap specifi ed at this object cr eation. | |
670 | **/ | |
671 | privat e void enc odeStubInA ddress( | |
672 | RMIServe r rmiServe r, Map<Str ing, ?> at tributes) | |
673 | throws I OException { | |
674 | ||
675 | fi nal String protocol, host; | |
676 | fi nal int po rt; | |
677 | ||
678 | if (address == null) { | |
679 | if (IIOP Helper.isS tub(rmiSer ver)) | |
680 | prot ocol = "ii op"; | |
681 | else | |
682 | prot ocol = "rm i"; | |
683 | host = n ull; // wi ll default to local host name | |
684 | PORT ; | |
685 | } else { | |
686 | protocol = address .getProtoc ol(); | |
687 | host = ( address.ge tHost().eq uals("")) ? null : a ddress.get Host(); | |
688 | port = a ddress.get Port(); | |
689 | } | |
690 | ||
691 | fi nal String urlPath = encodeStu b(rmiServe r, attribu tes); | |
692 | ||
693 | ad dress = ne w JMXServi ceURL(prot ocol, host , port, ur lPath); | |
694 | } | |
695 | ||
696 | static boolean i sIiopURL(J MXServiceU RL directo ryURL, boo lean stric t) | |
697 | th rows Malfo rmedURLExc eption { | |
698 | St ring proto col = dire ctoryURL.g etProtocol (); | |
699 | if (protocol .equals("r mi")) | |
700 | return f alse; | |
701 | el se if (pro tocol.equa ls("iiop") ) | |
702 | return t rue; | |
703 | el se if (str ict) { | |
704 | ||
705 | throw ne w Malforme dURLExcept ion("URL m ust have p rotocol " + | |
706 | "\"rmi \" or \"ii op\": \"" + | |
707 | protoc ol + "\"") ; | |
708 | } | |
709 | re turn false ; | |
710 | } | |
711 | ||
712 | /** | |
713 | * Ret urns the I OR of the given rmiS erver. | |
714 | **/ | |
715 | static String en codeStub( | |
716 | RMIServe r rmiServe r, Map<Str ing, ?> en v) throws IOExceptio n { | |
717 | if (IIOPHelp er.isStub( rmiServer) ) | |
718 | return " /ior/" + e ncodeIIOPS tub(rmiSer ver, env); | |
719 | el se | |
720 | return " /stub/" + encodeJRMP Stub(rmiSe rver, env) ; | |
721 | } | |
722 | ||
723 | static String en codeJRMPSt ub( | |
724 | RMIServe r rmiServe r, Map<Str ing, ?> en v) | |
725 | throws I OException { | |
726 | By teArrayOut putStream bout = new ByteArray OutputStre am(); | |
727 | Ob jectOutput Stream oou t = new Ob jectOutput Stream(bou t); | |
728 | oo ut.writeOb ject(rmiSe rver); | |
729 | oo ut.close() ; | |
730 | by te[] bytes = bout.to ByteArray( ); | |
731 | re turn byteA rrayToBase 64(bytes); | |
732 | } | |
733 | ||
734 | static String en codeIIOPSt ub( | |
735 | RMIServe r rmiServe r, Map<Str ing, ?> en v) | |
736 | throws I OException { | |
737 | tr y { | |
738 | Object o rb = IIOPH elper.getO rb(rmiServ er); | |
739 | return I IOPHelper. objectToSt ring(orb, rmiServer) ; | |
740 | } catch (Run timeExcept ion x) { | |
741 | throw ne wIOExcepti on(x.getMe ssage(), x ); | |
742 | } | |
743 | } | |
744 | ||
745 | /** | |
746 | * Obj ect that w e will bin d to the r egistry. | |
747 | * Thi s object i s a stub c onnected t o our RMIS erverImpl. | |
748 | **/ | |
749 | privat e static R MIServer o bjectToBin d( | |
750 | RMIServe rImpl rmiS erver, Map <String, ? > env) | |
751 | th rows IOExc eption { | |
752 | re turn RMICo nnector. | |
753 | connectS tub((RMISe rver)rmiSe rver.toStu b(),env); | |
754 | } | |
755 | ||
756 | privat e static R MIServerIm pl newJRMP Server(Map <String, ? > env, int port) | |
757 | throws I OException { | |
758 | RM IClientSoc ketFactory csf = (RM IClientSoc ketFactory ) | |
759 | env.get( RMI_CLIENT _SOCKET_FA CTORY_ATTR IBUTE); | |
760 | RM IServerSoc ketFactory ssf = (RM IServerSoc ketFactory ) | |
761 | env.get( RMI_SERVER _SOCKET_FA CTORY_ATTR IBUTE); | |
762 | re turn new R MIJRMPServ erImpl(por t, csf, ss f, env); | |
763 | } | |
764 | ||
765 | privat e static R MIServerIm pl newIIOP Server(Map <String, ? > env) | |
766 | throws I OException { | |
767 | re turn new R MIIIOPServ erImpl(env ); | |
768 | } | |
769 | ||
770 | privat e static S tring byte ArrayToBas e64(byte[] a) { | |
771 | in t aLen = a .length; | |
772 | in t numFullG roups = aL en/3; | |
773 | in t numBytes InPartialG roup = aLe n - 3*numF ullGroups; | |
774 | in t resultLe n = 4*((aL en + 2)/3) ; | |
775 | fi nal String Builder re sult = new StringBui lder(resul tLen); | |
776 | ||
777 | // Translate all full groups fro m byte arr ay element s to Base6 4 | |
778 | in t inCursor = 0; | |
779 | fo r (int i=0 ; i<numFul lGroups; i ++) { | |
780 | int byte 0 = a[inCu rsor++] & 0xff; | |
781 | int byte 1 = a[inCu rsor++] & 0xff; | |
782 | int byte 2 = a[inCu rsor++] & 0xff; | |
783 | result.a ppend(intT oAlpha[byt e0 >> 2]); | |
784 | result.a ppend(intT oAlpha[(by te0 << 4)& 0x3f | (by te1 >> 4)] ); | |
785 | result.a ppend(intT oAlpha[(by te1 << 2)& 0x3f | (by te2 >> 6)] ); | |
786 | result.a ppend(intT oAlpha[byt e2 & 0x3f] ); | |
787 | } | |
788 | ||
789 | // Translate partial g roup if pr esent | |
790 | if (numBytes InPartialG roup != 0) { | |
791 | int byte 0 = a[inCu rsor++] & 0xff; | |
792 | result.a ppend(intT oAlpha[byt e0 >> 2]); | |
793 | if (numB ytesInPart ialGroup = = 1) { | |
794 | resu lt.append( intToAlpha [(byte0 << 4) & 0x3f ]); | |
795 | resu lt.append( "=="); | |
796 | } else { | |
797 | // a ssert numB ytesInPart ialGroup = = 2; | |
798 | int byte1 = a[ inCursor++ ] & 0xff; | |
799 | resu lt.append( intToAlpha [(byte0 << 4)&0x3f | (byte1 >> 4)]); | |
800 | resu lt.append( intToAlpha [(byte1 << 2)&0x3f]) ; | |
801 | resu lt.append( '='); | |
802 | } | |
803 | } | |
804 | // assert in Cursor == a.length; | |
805 | // assert re sult.lengt h() == res ultLen; | |
806 | re turn resul t.toString (); | |
807 | } | |
808 | ||
809 | /** | |
810 | * Thi s array is a lookup table that translate s 6-bit po sitive int eger | |
811 | * ind ex values into their "Base64 A lphabet" e quivalents as specif ied | |
812 | * in Table 1 of RFC 2045. | |
813 | */ | |
814 | privat e static f inal char intToAlpha [] = { | |
815 | 'A ', 'B', 'C ', 'D', 'E ', 'F', 'G ', 'H', 'I ', 'J', 'K ', 'L', 'M ', | |
816 | 'N ', 'O', 'P ', 'Q', 'R ', 'S', 'T ', 'U', 'V ', 'W', 'X ', 'Y', 'Z ', | |
817 | 'a ', 'b', 'c ', 'd', 'e ', 'f', 'g ', 'h', 'i ', 'j', 'k ', 'l', 'm ', | |
818 | 'n ', 'o', 'p ', 'q', 'r ', 's', 't ', 'u', 'v ', 'w', 'x ', 'y', 'z ', | |
819 | '0 ', '1', '2 ', '3', '4 ', '5', '6 ', '7', '8 ', '9', '+ ', '/' | |
820 | }; | |
821 | ||
822 | /** | |
823 | * Con struct a n ew IOExcep tion with a nested e xception. | |
824 | * The nested ex ception is set only if JDK {@l iteral >= 1.4} | |
825 | */ | |
826 | privat e static I OException newIOExce ption(Stri ng message , | |
827 | Thro wable caus e) { | |
828 | fi nal IOExce ption x = new IOExce ption(mess age); | |
829 | re turn EnvHe lp.initCau se(x,cause ); | |
830 | } | |
831 | ||
832 | ||
833 | // Pri vate varia bles | |
834 | // --- ---------- ---- | |
835 | ||
836 | privat e static C lassLogger logger = | |
837 | ne w ClassLog ger("javax .managemen t.remote.r mi", "RMIC onnectorSe rver"); | |
838 | ||
839 | privat e JMXServi ceURL addr ess; | |
840 | privat e RMIServe rImpl rmiS erverImpl; | |
841 | privat e final Ma p<String, ?> attribu tes; | |
842 | privat e ClassLoa der defaul tClassLoad er = null; | |
843 | ||
844 | privat e String b oundJndiUr l; | |
845 | ||
846 | // sta te | |
847 | privat e static f inal int C REATED = 0 ; | |
848 | privat e static f inal int S TARTED = 1 ; | |
849 | privat e static f inal int S TOPPED = 2 ; | |
850 | ||
851 | privat e int stat e = CREATE D; | |
852 | privat e final st atic Set<R MIConnecto rServer> o penedServe rs = | |
853 | new Hash Set<RMICon nectorServ er>(); | |
854 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.