⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jeapplicationmbean.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<a name="164" href="#164">164</a> <a name="165" href="#165">165</a>                 <em class="comment">/*<em class="comment"> </em></em><a name="166" href="#166">166</a> <em class="comment">                 * Add the name and new value to the result list. Be sure</em><a name="167" href="#167">167</a> <em class="comment">                 * to ask the MBean for the new value, rather than simply</em><a name="168" href="#168">168</a> <em class="comment">                 * using attr.getValue(), because the new value may not</em><a name="169" href="#169">169</a> <em class="comment">                 * be same if it is modified according to the JE </em><a name="170" href="#170">170</a> <em class="comment">                 * implementation.</em><a name="171" href="#171">171</a> <em class="comment">                 */</em><a name="172" href="#172">172</a>                 String name = attr.getName();<a name="173" href="#173">173</a>                 Object newValue = jeHelper.getAttribute(targetEnv, name); <a name="174" href="#174">174</a>                 results.add(<strong>new</strong> Attribute(name, <strong>new</strong>Value));<a name="175" href="#175">175</a>             } <strong>catch</strong> (Exception e) {<a name="176" href="#176">176</a>                 e.printStackTrace();<a name="177" href="#177">177</a>             }<a name="178" href="#178">178</a>         }<a name="179" href="#179">179</a>         <strong>return</strong> results;<a name="180" href="#180">180</a>     }<a name="181" href="#181">181</a> <a name="182" href="#182">182</a>     <em>/**<em>*</em></em><a name="183" href="#183">183</a> <em>     * @see DynamicMBean#invoke</em><a name="184" href="#184">184</a> <em>     */</em><a name="185" href="#185">185</a>     <strong>public</strong> Object invoke(String actionName,<a name="186" href="#186">186</a>                          Object[] params,<a name="187" href="#187">187</a>                          String[] signature)<a name="188" href="#188">188</a>         throws MBeanException {<a name="189" href="#189">189</a> <a name="190" href="#190">190</a>         Object result = <strong>null</strong>;<a name="191" href="#191">191</a>         <a name="192" href="#192">192</a>         <strong>if</strong> (actionName == <strong>null</strong>) {<a name="193" href="#193">193</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"actionName cannot be null"</span>);<a name="194" href="#194">194</a>         }<a name="195" href="#195">195</a> <em class="comment">// Don't allow opening and closing of environment.  It was created</em><a name="196" href="#196">196</a> <em class="comment">// externally.  St.Ack</em><a name="197" href="#197">197</a> <em class="comment">//        </em><a name="198" href="#198">198</a> <em class="comment">//        if (actionName.equals(OP_OPEN)) {</em><a name="199" href="#199">199</a> <em class="comment">//            openEnvironment();</em><a name="200" href="#200">200</a> <em class="comment">//            return null;</em><a name="201" href="#201">201</a> <em class="comment">//        } else if (actionName.equals(OP_CLOSE)) {</em><a name="202" href="#202">202</a> <em class="comment">//            closeEnvironment();</em><a name="203" href="#203">203</a> <em class="comment">//            return null;</em><a name="204" href="#204">204</a> <em class="comment">//        } else {</em><a name="205" href="#205">205</a>             result = jeHelper.invoke(targetEnv, actionName, params, signature);<a name="206" href="#206">206</a> <em class="comment">//        }</em><a name="207" href="#207">207</a> <a name="208" href="#208">208</a>         <strong>return</strong> result;<a name="209" href="#209">209</a>     }<a name="210" href="#210">210</a> <a name="211" href="#211">211</a>     <em>/**<em>*</em></em><a name="212" href="#212">212</a> <em>     * @see DynamicMBean#getMBeanInfo</em><a name="213" href="#213">213</a> <em>     */</em><a name="214" href="#214">214</a>     <strong>public</strong> MBeanInfo getMBeanInfo() {<a name="215" href="#215">215</a> 	<strong>return</strong> mbeanInfo;<a name="216" href="#216">216</a>     }<a name="217" href="#217">217</a> <a name="218" href="#218">218</a>     <em>/**<em>*</em></em><a name="219" href="#219">219</a> <em>     * Create the available management interface for this environment.</em><a name="220" href="#220">220</a> <em>     * The attributes and operations available vary according to</em><a name="221" href="#221">221</a> <em>     * environment configuration.</em><a name="222" href="#222">222</a> <em>     *</em><a name="223" href="#223">223</a> <em>     */</em><a name="224" href="#224">224</a>     <strong>private</strong> <strong>synchronized</strong> <strong>void</strong> resetMBeanInfo() {<a name="225" href="#225">225</a>         <a name="226" href="#226">226</a>         <em class="comment">/*</em><a name="227" href="#227">227</a> <em class="comment">         * Get JE attributes, operation and notification information</em><a name="228" href="#228">228</a> <em class="comment">         * from JEMBeanHelper. An application may choose to add functionality</em><a name="229" href="#229">229</a> <em class="comment">         * of its own when constructing the MBeanInfo.</em><a name="230" href="#230">230</a> <em class="comment">         */</em><a name="231" href="#231">231</a>         <a name="232" href="#232">232</a>         <em class="comment">/*<em class="comment"> Attributes. */</em></em><a name="233" href="#233">233</a>         List attributeList =  jeHelper.getAttributeList(targetEnv);<a name="234" href="#234">234</a>         MBeanAttributeInfo [] attributeInfo =<a name="235" href="#235">235</a>             <strong>new</strong> MBeanAttributeInfo[attributeList.size()];<a name="236" href="#236">236</a>         attributeList.toArray(attributeInfo);<a name="237" href="#237">237</a> <a name="238" href="#238">238</a>         <em class="comment">/*<em class="comment"> Constructors. */</em></em><a name="239" href="#239">239</a>         Constructor [] constructors = <strong>this</strong>.getClass().getConstructors();<a name="240" href="#240">240</a>         MBeanConstructorInfo [] constructorInfo =<a name="241" href="#241">241</a>             <strong>new</strong> MBeanConstructorInfo[constructors.length];<a name="242" href="#242">242</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; constructors.length; i++) {<a name="243" href="#243">243</a>             constructorInfo[i] =<a name="244" href="#244">244</a>                 <strong>new</strong> MBeanConstructorInfo(<strong>this</strong>.getClass().getName(),<a name="245" href="#245">245</a>                                          constructors[i]);<a name="246" href="#246">246</a>         }<a name="247" href="#247">247</a> <a name="248" href="#248">248</a>         <em class="comment">/*<em class="comment"> Operations. */</em></em><a name="249" href="#249">249</a> <a name="250" href="#250">250</a>         <em class="comment">/*<em class="comment"> </em></em><a name="251" href="#251">251</a> <em class="comment">         * Get the list of operations available from the jeHelper. Then add</em><a name="252" href="#252">252</a> <em class="comment">         * an open and close operation.</em><a name="253" href="#253">253</a> <em class="comment">         */</em><a name="254" href="#254">254</a>         List operationList = jeHelper.getOperationList(targetEnv);<a name="255" href="#255">255</a>         <em class="comment">/*<em class="comment"> Don't allow opening or closing remotely.</em></em><a name="256" href="#256">256</a> <em class="comment">        if (targetEnv == null) {</em><a name="257" href="#257">257</a> <em class="comment">            operationList.add(</em><a name="258" href="#258">258</a> <em class="comment">             new MBeanOperationInfo(OP_OPEN,</em><a name="259" href="#259">259</a> <em class="comment">                                    "Configure and open the JE environment.",</em><a name="260" href="#260">260</a> <em class="comment">                                    new MBeanParameterInfo[0], // no params</em><a name="261" href="#261">261</a> <em class="comment">                                    "java.lang.Boolean",</em><a name="262" href="#262">262</a> <em class="comment">                                    MBeanOperationInfo.ACTION_INFO));</em><a name="263" href="#263">263</a> <em class="comment">        } else {</em><a name="264" href="#264">264</a> <em class="comment">            operationList.add(</em><a name="265" href="#265">265</a> <em class="comment">             new MBeanOperationInfo(OP_CLOSE,</em><a name="266" href="#266">266</a> <em class="comment">                                    "Close the JE environment.",</em><a name="267" href="#267">267</a> <em class="comment">                                    new MBeanParameterInfo[0], // no params</em><a name="268" href="#268">268</a> <em class="comment">                                    "void",</em><a name="269" href="#269">269</a> <em class="comment">                                    MBeanOperationInfo.ACTION_INFO));</em><a name="270" href="#270">270</a> <em class="comment">        }</em><a name="271" href="#271">271</a> <em class="comment">        */</em><a name="272" href="#272">272</a>         <a name="273" href="#273">273</a>         MBeanOperationInfo [] operationInfo =<a name="274" href="#274">274</a>             <strong>new</strong> MBeanOperationInfo[operationList.size()];<a name="275" href="#275">275</a>         operationList.toArray(operationInfo);<a name="276" href="#276">276</a> <a name="277" href="#277">277</a>         <em class="comment">/*<em class="comment"> Notifications. */</em></em><a name="278" href="#278">278</a>         MBeanNotificationInfo [] notificationInfo =<a name="279" href="#279">279</a>             jeHelper.getNotificationInfo(targetEnv);<a name="280" href="#280">280</a> <a name="281" href="#281">281</a>         <em class="comment">/*<em class="comment"> Generate the MBean description. */</em></em><a name="282" href="#282">282</a>         mbeanInfo = <strong>new</strong> MBeanInfo(<strong>this</strong>.getClass().getName(),<a name="283" href="#283">283</a>                                   DESCRIPTION,<a name="284" href="#284">284</a>                                   attributeInfo,<a name="285" href="#285">285</a>                                   constructorInfo,<a name="286" href="#286">286</a>                                   operationInfo,<a name="287" href="#287">287</a>                                   notificationInfo);<a name="288" href="#288">288</a>     }<a name="289" href="#289">289</a> <a name="290" href="#290">290</a>     <em>/**<em>*</em></em><a name="291" href="#291">291</a> <em>     * Open a JE environment using the configuration specified through</em><a name="292" href="#292">292</a> <em>     * MBean attributes and recorded within the JEMBeanHelper. </em><a name="293" href="#293">293</a> <em>     */</em><a name="294" href="#294">294</a>     <strong>private</strong>  <strong>void</strong> openEnvironment() <a name="295" href="#295">295</a>         throws MBeanException {<a name="296" href="#296">296</a> <a name="297" href="#297">297</a>         <strong>try</strong> {<a name="298" href="#298">298</a>             <strong>if</strong> (targetEnv == <strong>null</strong>) {<a name="299" href="#299">299</a>                 <em class="comment">/*<em class="comment"> </em></em><a name="300" href="#300">300</a> <em class="comment">                 * The environment configuration has been set through</em><a name="301" href="#301">301</a> <em class="comment">                 * mbean attributes managed by the JEMBeanHelper.</em><a name="302" href="#302">302</a> <em class="comment">                 */</em><a name="303" href="#303">303</a>                 targetEnv =<a name="304" href="#304">304</a>                     <strong>new</strong> Environment(jeHelper.getEnvironmentHome(),<a name="305" href="#305">305</a>                                     jeHelper.getEnvironmentOpenConfig());<a name="306" href="#306">306</a>                 resetMBeanInfo();<a name="307" href="#307">307</a>             }<a name="308" href="#308">308</a>         } <strong>catch</strong> (DatabaseException e) {<a name="309" href="#309">309</a>             <strong>throw</strong> <strong>new</strong> MBeanException(e);<a name="310" href="#310">310</a>         }<a name="311" href="#311">311</a>     }<a name="312" href="#312">312</a> <a name="313" href="#313">313</a>     <em>/**<em>*</em></em><a name="314" href="#314">314</a> <em>     * Release the environment handle contained within the MBean to properly</em><a name="315" href="#315">315</a> <em>     * release resources.</em><a name="316" href="#316">316</a> <em>     */</em><a name="317" href="#317">317</a>     <strong>private</strong> <strong>void</strong> closeEnvironment()<a name="318" href="#318">318</a>         throws MBeanException {<a name="319" href="#319">319</a> <a name="320" href="#320">320</a>         <strong>try</strong> {<a name="321" href="#321">321</a>             <strong>if</strong> (targetEnv != <strong>null</strong>) {<a name="322" href="#322">322</a>                 targetEnv.close();<a name="323" href="#323">323</a>                 targetEnv = <strong>null</strong>;<a name="324" href="#324">324</a>                 resetMBeanInfo();<a name="325" href="#325">325</a>             }<a name="326" href="#326">326</a>         } <strong>catch</strong> (DatabaseException e) {<a name="327" href="#327">327</a>             <strong>throw</strong> <strong>new</strong> MBeanException(e);<a name="328" href="#328">328</a>         }<a name="329" href="#329">329</a>     }<a name="330" href="#330">330</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -