connectionclient.java

来自「the source code of voyager examples---co」· Java 代码 · 共 53 行

JAVA
53
字号
// (c) Copyright 2003 Recursion Software, Inc.

package examples.connectionmgmt;

import com.recursionsw.ve.Namespace;
import com.recursionsw.ve.Voyager;
import com.recursionsw.ve.transport.Transport;

import examples.stockmarket.IStockmarket;

public class ConnectionClient implements Runnable {
    IStockmarket market;
    String announcement;

    public ConnectionClient(IStockmarket market, String str) {
        this.market = market;
        this.announcement = str;
    }

    public void run() {
        try {
            market.news(announcement);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            Voyager.startup();
            // obtain a proxy to the object on port 9000 with symbol "NASDAQ"
            Transport.addEventListener(new ConnectionListener());
            IStockmarket market =
                (IStockmarket) Namespace.lookup("9000/NASDAQ");
            // Create six connections.
            System.out.println("Calling server...");

            int threads = 6;
            Thread[] all = new Thread[threads];
            for (int idx = 0; idx < threads; idx++) {
                all[idx] = new Thread(new ConnectionClient(market, "Headline #" + (idx + 1)));
                all[idx].start();
            }
            for (int idx = 0; idx < threads; idx++) {
            	all[idx].join();
            }
            Voyager.shutdown();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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