PortfolioClient.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.ejb.session.example2;
- import weblogic.rmi.*;
- import java.util.*;
- import javax.naming.*;
- /**
- * ResearchClient periodically asks server for research.
- */
- public class PortfolioClient extends TimerTask implements Runnable {
- /**
- * Method run
- *
- *
- */
- public void run() {
- System.out.println("PortfolioClient running:" + new Date());
- try {
- InitialContext ctx = Environment.getInitialContext();
- Object objref = ctx.lookup("AnalyzePortfolio");
- AnalyzePortfolioHome home =
- (AnalyzePortfolioHome) javax.rmi.PortableRemoteObject.narrow(objref,
- AnalyzePortfolioHome.class);
- AnalyzePortfolioRemote analyzer = home.create();
- // Add some debts and some holdings.
- analyzer.addHolding("BEAS", new Integer(20000));
- analyzer.addHolding("WAG", new Integer(10000));
- analyzer.addHolding("MSFT", new Integer(150));
- analyzer.addDebt("Car Loan", new Integer(20000));
- analyzer.addDebt("Mortgage", new Integer(30000));
- // Ask for first analysis.
- System.out.println(analyzer.getAnalysis());
- // Add a big holding and ask for second analysis.
- analyzer.addHolding("PETS", new Integer(200000));
- System.out.println(analyzer.getAnalysis());
- analyzer.remove();
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- }
- /**
- * Declare a new client and schedule it on a timer.
- */
- public static void main(String[] args) {
- Timer t = new Timer();
- PortfolioClient client = new PortfolioClient();
- // Starting in 5 secs, run every 5 seconds.
- t.schedule(client, 5000, 5000);
- }
- }
- /*--- Formatted in Bible Style on Thu, Sep 6, '01 ---*/
- /*------ Formatted by Jindent 3.24 Gold 1.02 --- http://www.jindent.de ------*/