📄 example7.java.html
字号:
</FONT><FONT color=#008000>//<em> </em><em>This</em><em> </em><em>will</em><em> </em><em>cause</em><em> </em><em>a</em><em> </em><em>short</em><em>-</em><em>dump</em><em> </em><em>in</em><em> </em><em>R</em><em>/</em><em>3</em><em> </em><em>that</em><em> </em><em>indicates</em><em> </em><em>that</em><em> </em><em>we</em><em> </em><em>cannot</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>handle</em><em> </em><em>the</em><em> </em><em>request.</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>else</b></FONT><FONT color=#000000> { </FONT><FONT color=#008000>//<em> </em><em>Otherwise</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>throw</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>new</b></FONT><FONT color=#000000> </FONT><FONT color=#000080><b>JCO.AbapException</b></FONT><FONT color=#000000>(</FONT><FONT color=#FF00FF>"NOT_SUPPORTED"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"This service is not implemented by the external server"</FONT><FONT color=#000000>); } } } </FONT><FONT color=#008000>/** <em> </em><em>*</em><em> </em><em> </em><em>Called</em><em> </em><em>if</em><em> </em><em>an</em><em> </em><em>exception</em><em> </em><em>was</em><em> </em><em>thrown</em><em> </em><em>anywhere</em><em> </em><em>in</em><em> </em><em>our</em><em> </em><em>server</em> <em> </em><em>*</em><em>/</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>public</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>void</b></FONT><FONT color=#000000> serverExceptionOccurred(</FONT><FONT color=#000080><b>JCO.Server</b></FONT><FONT color=#000000> srv, Exception ex) { System.out.println(</FONT><FONT color=#FF00FF>"Exception in Server "</FONT><FONT color=#000000> + srv</FONT><FONT color=#000080><b>.getProgID</b></FONT><FONT color=#000000>() + </FONT><FONT color=#FF00FF>":\n"</FONT><FONT color=#000000> + ex); ex.printStackTrace(); } </FONT><FONT color=#008000>/** <em> </em><em>*</em><em> </em><em> </em><em>Called</em><em> </em><em>if</em><em> </em><em>an</em><em> </em><em>error</em><em> </em><em>was</em><em> </em><em>thrown</em><em> </em><em>anywhere</em><em> </em><em>in</em><em> </em><em>our</em><em> </em><em>server</em> <em> </em><em>*</em><em>/</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>public</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>void</b></FONT><FONT color=#000000> serverErrorOccurred(</FONT><FONT color=#000080><b>JCO.Server</b></FONT><FONT color=#000000> srv, Error err) { System.out.println(</FONT><FONT color=#FF00FF>"Error in Server "</FONT><FONT color=#000000> + srv</FONT><FONT color=#000080><b>.getProgID</b></FONT><FONT color=#000000>() + </FONT><FONT color=#FF00FF>":\n"</FONT><FONT color=#000000> + err); err.printStackTrace(); } </FONT><FONT color=#008000>//<em> </em><em>System</em><em> </em><em>IDs</em><em> </em><em>of</em><em> </em><em>the</em><em> </em><em>system</em><em> </em><em>that</em><em> </em><em>we</em><em> </em><em>gonna</em><em> </em><em>using</em><em> </em><em>be</em><em> </em><em>for</em><em> </em><em>dictionary</em><em> </em><em>calls</em></FONT><FONT color=#000000> String POOL_A = </FONT><FONT color=#FF00FF>"SYSTEM_A"</FONT><FONT color=#000000>; String POOL_B = </FONT><FONT color=#FF00FF>"SYSTEM_B"</FONT><FONT color=#000000>; </FONT><FONT color=#008000>//<em> </em><em>The</em><em> </em><em>server</em><em> </em><em>objects</em><em> </em><em>that</em><em> </em><em>actually</em><em> </em><em>handles</em><em> </em><em>the</em><em> </em><em>request</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>int</b></FONT><FONT color=#000000> MAX_SERVERS = 2; Server servers[] = </FONT><FONT color=#0000FF><b>new</b></FONT><FONT color=#000000> Server[MAX_SERVERS]; </FONT><FONT color=#008000>/** <em> </em><em>*</em><em> </em><em> </em><em>Constructor.</em><em> </em><em>Creates</em><em> </em><em>a</em><em> </em><em>client</em><em> </em><em>pool</em><em>,</em><em> </em><em>the</em><em> </em><em>repository</em><em> </em><em>and</em><em> </em><em>a</em><em> </em><em>server.</em> <em> </em><em>*</em><em>/</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>public</b></FONT><FONT color=#000000> Example7() { </FONT><FONT color=#000080><b>IRepository</b></FONT><FONT color=#000000> repository; </FONT><FONT color=#008000>//<em> </em><em>Add</em><em> </em><em>a</em><em> </em><em>connection</em><em> </em><em>pool</em><em> </em><em>to</em><em> </em><em>a</em><em> </em><em>remote</em><em> </em><em>R</em><em>/</em><em>3</em><em> </em><em>system</em><em> </em><em>A.</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>We</em><em> </em><em>will</em><em> </em><em>use</em><em> </em><em>this</em><em> </em><em>connected</em><em> </em><em>to</em><em> </em><em>dynamically</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>request</em><em> </em><em>dictionary</em><em> </em><em>information</em><em> </em><em>for</em><em> </em><em>incoming</em><em> </em><em>function</em><em> </em><em>calls.</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>!</em><em>!</em><em>!</em><em> </em><em>Please</em><em>,</em><em> </em><em>fill</em><em> </em><em>in</em><em> </em><em>the</em><em> </em><em>necessary</em><em> </em><em>login</em><em> </em><em>and</em><em> </em><em>system</em><em> </em><em>parameters</em><em> </em><em>!</em><em>!</em><em>!</em></FONT><FONT color=#000000> </FONT><FONT color=#000080><b>JCO.addClientPool</b></FONT><FONT color=#000000>(POOL_A,3,</FONT><FONT color=#FF00FF>"000"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"user"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"password"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"EN"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"system_a"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"01"</FONT><FONT color=#000000>); </FONT><FONT color=#008000>//<em> </em><em>Create</em><em> </em><em>repository</em><em> </em><em>for</em><em> </em><em>System</em><em> </em><em>A</em></FONT><FONT color=#000000> repository = </FONT><FONT color=#000080><b>JCO.createRepository</b></FONT><FONT color=#000000>(</FONT><FONT color=#FF00FF>"SYSTEM_A"</FONT><FONT color=#000000>, POOL_A ); </FONT><FONT color=#008000>//<em> </em><em>Create</em><em> </em><em>a</em><em> </em><em>new</em><em> </em><em>server</em><em> </em><em>and</em><em> </em><em>register</em><em> </em><em>it</em><em> </em><em>with</em><em> </em><em>system</em><em> </em><em>A</em></FONT><FONT color=#000000> servers[0] = </FONT><FONT color=#0000FF><b>new</b></FONT><FONT color=#000000> Server(</FONT><FONT color=#FF00FF>"SystemA"</FONT><FONT color=#000000>, </FONT><FONT color=#FF00FF>"sapgw01"</FONT><FONT color=#000000>, </FONT><FONT color=#FF00FF>"SERVER_A"</FONT><FONT color=#000000>, repository); </FONT><FONT color=#008000>//<em> </em><em>Add</em><em> </em><em>a</em><em> </em><em>connection</em><em> </em><em>pool</em><em> </em><em>to</em><em> </em><em>a</em><em> </em><em>remote</em><em> </em><em>R</em><em>/</em><em>3</em><em> </em><em>system</em><em> </em><em>B.</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>We</em><em> </em><em>will</em><em> </em><em>use</em><em> </em><em>this</em><em> </em><em>connected</em><em> </em><em>to</em><em> </em><em>dynamically</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>request</em><em> </em><em>dictionary</em><em> </em><em>information</em><em> </em><em>for</em><em> </em><em>incoming</em><em> </em><em>function</em><em> </em><em>calls.</em></FONT><FONT color=#000000> </FONT><FONT color=#008000>//<em> </em><em>!</em><em>!</em><em>!</em><em> </em><em>Please</em><em>,</em><em> </em><em>fill</em><em> </em><em>in</em><em> </em><em>the</em><em> </em><em>necessary</em><em> </em><em>login</em><em> </em><em>and</em><em> </em><em>system</em><em> </em><em>parameters</em><em> </em><em>!</em><em>!</em><em>!</em></FONT><FONT color=#000000> </FONT><FONT color=#000080><b>JCO.addClientPool</b></FONT><FONT color=#000000>(POOL_B,3,</FONT><FONT color=#FF00FF>"000"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"user"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"password"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"EN"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"system_b"</FONT><FONT color=#000000>,</FONT><FONT color=#FF00FF>"02"</FONT><FONT color=#000000>); </FONT><FONT color=#008000>//<em> </em><em>Create</em><em> </em><em>repository</em><em> </em><em>for</em><em> </em><em>system</em><em> </em><em>B</em></FONT><FONT color=#000000> repository = </FONT><FONT color=#000080><b>JCO.createRepository</b></FONT><FONT color=#000000>(</FONT><FONT color=#FF00FF>"SYSTEM_B"</FONT><FONT color=#000000>, POOL_B ); </FONT><FONT color=#008000>//<em> </em><em>Create</em><em> </em><em>a</em><em> </em><em>new</em><em> </em><em>server</em><em> </em><em>and</em><em> </em><em>register</em><em> </em><em>it</em><em> </em><em>with</em><em> </em><em>system</em><em> </em><em>B</em></FONT><FONT color=#000000> servers[1] = </FONT><FONT color=#0000FF><b>new</b></FONT><FONT color=#000000> Server(</FONT><FONT color=#FF00FF>"SystemB"</FONT><FONT color=#000000>, </FONT><FONT color=#FF00FF>"sapgw02"</FONT><FONT color=#000000>, </FONT><FONT color=#FF00FF>"SERVER_B"</FONT><FONT color=#000000>, repository); </FONT><FONT color=#008000>//<em> </em><em>Register</em><em> </em><em>ourselves</em><em> </em><em>such</em><em> </em><em>that</em><em> </em><em>we</em><em> </em><em>get</em><em> </em><em>exceptions</em><em> </em><em>from</em><em> </em><em>the</em><em> </em><em>servers</em></FONT><FONT color=#000000> </FONT><FONT color=#000080><b>JCO.addServerExceptionListener</b></FONT><FONT color=#000000>(</FONT><FONT color=#0000FF><b>this</b></FONT><FONT color=#000000>); </FONT><FONT color=#008000>//<em> </em><em>Register</em><em> </em><em>ourselves</em><em> </em><em>such</em><em> </em><em>that</em><em> </em><em>we</em><em> </em><em>get</em><em> </em><em>errors</em><em> </em><em>from</em><em> </em><em>the</em><em> </em><em>servers</em></FONT><FONT color=#000000> </FONT><FONT color=#000080><b>JCO.addServerErrorListener</b></FONT><FONT color=#000000>(</FONT><FONT color=#0000FF><b>this</b></FONT><FONT color=#000000>); } </FONT><FONT color=#008000>/** <em> </em><em>*</em><em> </em><em> </em><em>Start</em><em> </em><em>the</em><em> </em><em>server</em> <em> </em><em>*</em><em>/</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>public</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>void</b></FONT><FONT color=#000000> startServers() { </FONT><FONT color=#0000FF><b>try</b></FONT><FONT color=#000000> { </FONT><FONT color=#0000FF><b>for</b></FONT><FONT color=#000000> (</FONT><FONT color=#0000FF><b>int</b></FONT><FONT color=#000000> i = 0; i < MAX_SERVERS; i++) servers[i]</FONT><FONT color=#000080><b>.start</b></FONT><FONT color=#000000>(); } </FONT><FONT color=#0000FF><b>catch</b></FONT><FONT color=#000000> (Exception ex) { System.out.println(</FONT><FONT color=#FF00FF>"Could not start servers !\n"</FONT><FONT color=#000000> + ex); }</FONT><FONT color=#008000>//<em>try</em></FONT><FONT color=#000000> } </FONT><FONT color=#008000>/** <em> </em><em>*</em><em> </em><em> </em><em>Simple</em><em> </em><em>main</em><em> </em><em>program</em><em> </em><em>driver</em> <em> </em><em>*</em><em>/</em></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>public</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>static</b></FONT><FONT color=#000000> </FONT><FONT color=#0000FF><b>void</b></FONT><FONT color=#000000> main(String[] argv) { Example7 obj = </FONT><FONT color=#0000FF><b>new</b></FONT><FONT color=#000000> Example7(); obj.startServers(); }}</PRE></FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -