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

📄 ch12.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TT>143:                 endl;</TT><TT>144:         cout &lt;&lt; &quot;  account balance: &quot; &lt;&lt; account-&gt;balance() &lt;&lt; endl;</TT><TT>145: </TT><TT>146:         // Ask the Bank to issue an ATMCard for the newly created</TT><TT>147:         // Account.</TT><TT>148:         cout &lt;&lt; &quot;ATMClient: Getting ATMCard from Bank.&quot; &lt;&lt; endl;</TT><TT>149:         try {</TT><TT>150:             atmCard = bank-&gt;issueATMCard(pin, account);</TT><TT>151:         } catch (const InvalidAccountException&amp;) {</TT><TT>152: </TT><TT>153:             // For some reason, the Account was invalid (this</TT><TT>154:             // shouldn't happen).</TT><TT>155:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid Account&quot;</TT><TT>156:                     &lt;&lt; endl;</TT><TT>157:             return 1;</TT><TT>158:         }</TT><TT>159: </TT><TT>160:         // Perform some transactions on the Account through the</TT><TT>161:         // ATM.</TT><TT>162:         cout &lt;&lt; &quot;ATMClient: Performing transactions.&quot; &lt;&lt; endl;</TT><TT>163:         try {</TT><TT>164:             cout &lt;&lt; &quot;  Depositing $250.00...&quot; &lt;&lt; endl;</TT><TT>165:             cout &lt;&lt; &quot;  New balance is $&quot; &lt;&lt; atm-&gt;deposit(atmCard,</TT><TT>166:                     account, pin, 250.00) &lt;&lt; endl;</TT><TT>167: </TT><TT>168:             // This will throw an exception since we're trying to</TT><TT>169:             // withdraw too much.</TT><TT>170:             cout &lt;&lt; &quot;  Withdrawing $500.00...&quot; &lt;&lt; endl;</TT><TT>171:             cout &lt;&lt; &quot;  New balance is $&quot; &lt;&lt; atm-&gt;withdraw(atmCard,</TT><TT>172:                     account, pin, 500.00) &lt;&lt; endl;</TT><TT>173:         } catch (AuthorizationException&amp;) {</TT><TT>174:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid PIN or &quot;</TT><TT>175:                     &lt;&lt; &quot;No authorization (as expected)&quot; &lt;&lt; endl;</TT><TT>176:         } catch (InvalidAmountException&amp;) {</TT><TT>177:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid amount&quot;</TT><TT>178:                     &lt;&lt; endl;</TT><TT>179:         } catch (InsufficientFundsException&amp;) {</TT><TT>180:             cout &lt;&lt; &quot;ATMClient: Exception caught: Insufficient &quot; &lt;&lt;</TT><TT>181:                     &quot;funds&quot; &lt;&lt; endl;</TT><TT>182:         }</TT><TT>183: </TT><TT>184:         // Perform some more transactions on the Account through</TT><TT>185:         // the ATM.</TT><TT>186:         cout &lt;&lt; &quot;ATMClient: Performing more transactions.&quot; &lt;&lt; endl;</TT><TT>187:         try {</TT><TT>188:             cout &lt;&lt; &quot;  Depositing $500.00...&quot; &lt;&lt; endl;</TT><TT>189:             cout &lt;&lt; &quot;  New balance is $&quot; &lt;&lt;</TT><TT>190:                     atm-&gt;deposit(atmCard, account, pin, 500.00) &lt;&lt;</TT><TT>191:                     endl;</TT><TT>192: </TT><TT>193:             // This will throw an exception because we're using the</TT><TT>194:             // wrong PIN.</TT><TT>195:             cout &lt;&lt; &quot;  Withdrawing $250.00 with incorrect PIN...&quot;</TT><TT>196:                     &lt;&lt; endl;</TT><TT>197:             cout &lt;&lt; &quot;  New balance is $&quot; &lt;&lt; atm-&gt;withdraw(atmCard,</TT><TT>198:                     account, pin + 1, 250.00) &lt;&lt; endl;</TT><TT>199:         } catch (AuthorizationException&amp;) {</TT><TT>200:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid PIN or &quot;</TT><TT>201:                     &lt;&lt; &quot;No authorization (as expected)&quot; &lt;&lt; endl;</TT><TT>202:         } catch (InvalidAmountException&amp;) {</TT><TT>203:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid amount&quot;</TT><TT>204:                     &lt;&lt; endl;</TT><TT>205:         } catch (InsufficientFundsException&amp;) {</TT><TT>206:             cout &lt;&lt; &quot;ATMClient: Exception caught: Insufficient &quot; &lt;&lt;</TT><TT>207:                     &quot;funds&quot; &lt;&lt; endl;</TT><TT>208:         }</TT><TT>209: </TT><TT>210:         // Get rid of the Account.</TT><TT>211:         try {</TT><TT>212:             cout &lt;&lt; &quot;  Deleting Account.&quot; &lt;&lt; endl;</TT><TT>213:             bank-&gt;deleteAccount(account);</TT><TT>214: </TT><TT>215:             // Attempt to delete the Account again, just for kicks.</TT><TT>216:             // This should result in an exception being thrown.</TT><TT>217:             cout &lt;&lt; &quot;  Attempting to cause an exception by &quot; &lt;&lt;</TT><TT>218:                     &quot;deleting Account again.&quot; &lt;&lt; endl;</TT><TT>219:             bank-&gt;deleteAccount(account);</TT><TT>220:         } catch (const InvalidAccountException&amp;) {</TT><TT>221: </TT><TT>222:             // Sure enough, the exception was thrown.</TT><TT>223:             cout &lt;&lt; &quot;ATMClient: Exception caught: Invalid &quot; &lt;&lt;</TT><TT>224:                     &quot;Account (as expected)&quot; &lt;&lt; endl;</TT><TT>225:         }</TT><TT>226:     } catch (const CORBA::Exception&amp; ex) {</TT><TT>227: </TT><TT>228:         // Some operation on the Account failed...</TT><TT>229:         cout &lt;&lt; &quot;ATMClient: Error accessing Account:&quot; &lt;&lt; endl;</TT><TT>230:         cout &lt;&lt; ex &lt;&lt; endl;</TT><TT>231:         return 1;</TT><TT>232:     }</TT><TT>233: </TT><TT>234:     // Sleep for long enough to catch an Account update message or</TT><TT>235:     // two.</TT><TT>236:     Sleep(120000);</TT><TT>237: </TT><TT>238:     // When this point is reached, the application is finished.</TT><TT>239:     return 0;240: }</TT> </FONT></PRE><P>That's it for modifications--you're now ready to run the modified code.<H3><A NAME="Heading22"></A><FONT COLOR="#000077">Running the Application</FONT></H3><P>The various components of the <TT>Bank</TT> application should be run in exactlythe same manner as on Day 9, with one exception: Before running anything else, youneed to start the CORBA Naming Service and let it create a default Naming Context.To do this with Visigenic's implementation of the Naming Service, type the following:</P><PRE><FONT COLOR="#0066FF"><TT>NameExtF &lt;factory name&gt; &lt;logfile&gt;</TT></FONT></PRE><P>For the purposes of the <TT>Bank</TT> application, the following will do justfine:</P><PRE><FONT COLOR="#0066FF"><TT>NameExtF NameServer naming.log</TT></FONT></PRE><P>The output of the Naming Service application will be the Interoperable ObjectReference (IOR) assigned to the Naming Service. Your output will vary but will looksomething like this:</P><PRE><FONT COLOR="#0066FF"><TT>IOR:012020203700000049444c3a6f72672e6f6d672f436f734e616d696e672f457</TT><TT>874656e6465644e616d696e67436f6e74657874466163746f72793a312e30002002</TT><TT>0000000153495680000000010101201400000069767939362e626577656c6c6e657</TT><TT>42e636f6d005750f8ff010000005300000001504d43000000003700000049444c3a</TT><TT>6f72672e6f6d672f436f734e616d696e672f457874656e6465644e616d696e67436</TT><TT>f6e74657874466163746f72793a312e3000200b0000004e616d6553657276657200</TT><TT>2000000000000000006f000000010100200e0000003135332e33362e3234302e373</TT><TT>90002065300000001504d43000000003700000049444c3a6f72672e6f6d672f436f</TT><TT>734e616d696e672f457874656e6465644e616d696e67436f6e74657874466163746</TT><TT>f72793a312e3000200b0000004e616d6553657276657200</TT></FONT></PRE><P>You're now ready to run the application as you did on Day 9. Because you didn'tmodify any of the functionality, the output of all the application components willbe exactly the same.<H2><A NAME="Heading23"></A><FONT COLOR="#000077">Summary</FONT></H2><P>In this chapter you became aware of the many CORBAservices and CORBAfacilitiesspecified by the OMG. You also determined which of the CORBAservices are appropriatefor use with the <TT>Bank</TT> application from previous chapters. Finally, you modifiedthe <TT>Bank</TT> application to use some of the features offered in the CORBA NamingService.</P><P>Additional information on the CORBAservices (the information provided in thischapter is a condensed version) is available from the OMG's Web site at <TT>http://www.omg.org/</TT>.</P><P>On Day 13, you'll shift gears again, this time turning your attention to the Javaprogramming language/platform. As you are no doubt aware, the CORBA architecturespans many programming languages, of which Java is just one. However, Java is anespecially interesting language to use with CORBA, given such features as interfacesand garbage collection (features you'll learn more about, if you're not already familiarwith them). The next chapter, &quot;Developing for the Internet Using CORBA and Java,&quot;briefly introduces you to the Java programming language and discusses the use ofJava with CORBA. Finally, on Day 14, &quot;Web-Enabling the <TT>Bank</TT> Examplewith Java,&quot; you'll apply Java and CORBA development to the Web, deploying anapplet-based front end to the <TT>Bank</TT> application with which you're so familiarby now.<H2><A NAME="Heading24"></A><FONT COLOR="#000077">Q&amp;A</FONT></H2><DL>	<DD><B>Q I didn't see any mention of vertical CORBAfacilities for [insert my pet	industry here]. Is the OMG neglecting us?</B><BR>	<B><BR>	A</B> The OMG is actively working in an ever-increasing number of vertical domains.	If you are interested in developing standard facility interfaces for a particular	industry, you should contact the OMG for more information.<BR>	<B><BR>	Q What is that weird-looking IOR thing anyway?</B><BR>	<B><BR>	A</B> The Interoperable Object Reference is a string that uniquely identifies a CORBA	object. The IOR is defined in such a way that any vendor's ORB can accept an IOR	and resolve it, yielding the object's location. Generally, you won't need to deal	with these, though occasionally they can be a convenient mechanism for objects to	locate each other. Because they are plain strings, they are easily transmitted across	a network, stored in a file, and so on.<BR>	<B><BR>	Q When using the Naming Service, the application components had the ID, <TT>&quot;BankServer1&quot;</TT>,	hardcoded. Could I make the applications search the Naming Service for a registered	<TT>BankServer</TT> instead?<BR>	<BR>	A</B> Yes. The Naming Context supports a <TT>list()</TT> operation that returns a	<TT>BindingList</TT> and <TT>BindingIterator</TT>, which in turn can be used to iterate	over the contents of the Naming Context. In this way, objects are located by name	or by type, or the application simply uses the first object that is found. Although	the Naming Service can be used for this purpose, a better choice might be to use	the Trader Service, which is intended for precisely this use.</DL><H2><A NAME="Heading25"></A><FONT COLOR="#000077">Workshop</FONT></H2><P>The following section will help you test your comprehension of the material presentedin this chapter and put what you've learned into practice. You'll find the answersto the quiz and exercises in Appendix A.<H3><A NAME="Heading26"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. Who defines the specifications for CORBAservices and CORBAfacilities?<BR>	<B><BR>	2</B>. Who provides the implementations for CORBAservices and CORBAfacilities?<BR>	<B><BR>	3</B>. What CORBAservices and/or CORBAfacilities, if any, must a vendor provide with	an ORB product in order to be considered CORBA 2.0-compliant?<BR>	<B><BR>	4</B>. Why are vertical market facilities useful?</DL><H3><A NAME="Heading27"></A><FONT COLOR="#000077">Exercises</FONT></H3><DL>	<DD><B>1</B>. Provide an overview of how the Object Trader Service could be used	to replace the <TT>BankServer</TT> in the sample <TT>Bank</TT> application.<BR>	<B><BR>	2</B>. Describe how the Event Service could be used within the <TT>Bank</TT> application	(hint: consider the automatic account update feature added on Day 9). What would	be the benefit of using this approach?<BR>	<B><BR>	3</B>. (Extra Credit) If you have any products available to you that implement one	or more CORBAservices, try to integrate the functionality provided by a service of	your choice with the sample <TT>Bank</TT> application. (See the section of this chapter	labeled &quot;Choosing CORBAservices&quot; to determine which services might integrate	well with the sample application.) Because of the numerous possibilities available	to you, no answer is provided for this exercise.<FONT COLOR="#000077"></FONT></DL><CENTER><P><HR><A HREF="../ch11/ch11.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch13/ch13.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR><BR><BR><IMG SRC="../button/corp.gif" WIDTH="284" HEIGHT="45" ALIGN="BOTTOM" ALT="Macmillan Computer Publishing USA"BORDER="0"></P><P>&#169; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

⌨️ 快捷键说明

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