Methods Summary |
---|
private static java.util.Collection | getAccountDescriptions(NameRepository nameRepository)
ArrayList returnValue = new ArrayList();
Iterator i = nameRepository.getAllNames();
boolean checking = false;
while (i.hasNext()) {
AccountDescription accountDescription = new AccountDescription();
accountDescription.name = (String) i.next();
int cents = (int) (Math.random() * 100000);
accountDescription.balance = new Money(cents);
returnValue.add(accountDescription);
if (checking) {
accountDescription.contextName = "checking";
} else {
accountDescription.contextName = "savings";
}
checking = !checking;
}
return returnValue;
|
private static void | getContext()
try {
baseContext = BaseContextImpl.getStubFromServer("127.0.0.1");
} catch (Exception e) {
System.out.println("Couldn't find base context");
e.printStackTrace();
}
|
private static void | launchServer(com.ora.rmibook.chapter15.bank.applications.ImplLauncher$AccountDescription serverDescription)
try {
Account_Impl newAccount = new Account_Impl(serverDescription.balance);
Path path = Path.buildPath(new String[] {serverDescription.contextName}
);
if (null == baseContext) {
getContext();
}
baseContext.bind(path, serverDescription.name, new AttributeSet(), newAccount);
System.out.println("Account " + serverDescription.name + " successfully launched.");
} catch (NamingException e) {
System.out.println(e.getDescription());
e.printStackTrace();
} catch (Exception ee) {
ee.printStackTrace();
}
|
public static void | main(java.lang.String[] args)
int numberOfServers = (Integer.valueOf(args[0])).intValue();
NameRepository nameRepository = new NameRepository(numberOfServers);
Collection accountDescriptions = getAccountDescriptions(nameRepository);
Iterator i = accountDescriptions.iterator();
while (i.hasNext()) {
AccountDescription nextAccountDescription = (AccountDescription) i.next();
launchServer(nextAccountDescription);
}
|