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

📄 impllauncher.java

📁 RMI英文教程,从各个方面教你怎么进行RMI开发
💻 JAVA
字号:
package com.ora.rmibook.chapter13.bank.applications;


import com.ora.rmibook.chapter13.bank.*;
import com.ora.rmibook.chapter13.bank.valueobjects.*;
import java.util.*;
import java.rmi.*;


public class ImplLauncher {
    public static void main(String[] args) {
        int numberOfServers = (Integer.valueOf(args[0])).intValue();
        NameRepository nameRepository = new NameRepository(numberOfServers);
        Collection nameBalancePairs = getNameBalancePairs(nameRepository);
        Iterator i = nameBalancePairs.iterator();

        while (i.hasNext()) {
            NameBalancePair nextNameBalancePair = (NameBalancePair) i.next();

            launchServer(nextNameBalancePair);
        }
    }

    private static void launchServer(NameBalancePair serverDescription) {
        try {
            Account3_Impl2 newAccount = new Account3_Impl2(serverDescription.balance);

            Naming.rebind(serverDescription.name, newAccount);
            System.out.println("Account " + serverDescription.name + " successfully launched.");
        } catch (Exception e) {
        }
    }

    private static Collection getNameBalancePairs(NameRepository nameRepository) {
        ArrayList returnValue = new ArrayList();
        Iterator i = nameRepository.getAllNames();

        while (i.hasNext()) {
            NameBalancePair nextNameBalancePair = new NameBalancePair();

            nextNameBalancePair.name = (String) i.next();
            int cents = (int) (Math.random() * 100000);

            nextNameBalancePair.balance = new Money(cents);
            returnValue.add(nextNameBalancePair);
        }
        return returnValue;
    }

    private static class NameBalancePair {
        String name;
        Money balance;
    }
}

⌨️ 快捷键说明

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