FileDocCategorySizeDatePackage
CreditAgent.javaAPI DocExample1243Tue Jan 20 20:58:50 GMT 1998dcj.examples.security

CreditAgent

public class CreditAgent extends SimpleAgent
Source code from "Java Distributed Computing", by Jim Farley. Class: CreditAgent Example: 5-2 Description: An extension of SimpleAgent that provides credit information for named accounts.

Fields Summary
Constructors Summary
public CreditAgent(String host, int port)

    super(host, port);
  
Methods Summary
protected java.lang.StringgetCreditData(java.lang.String acctName)

    // Real method would use account name to
    // initiate a database query...
    return "No info available.";
  
protected voidprocessMsg(java.lang.String msg)

    String name = null;
    String cmd = null;
    String retMsg = new String();

    // Parse the command and account name from the input stream.
    StreamTokenizer stok = new StreamTokenizer(new StringReader(msg));
    try {
      stok.nextToken();
      cmd = stok.sval;
      name = stok.sval;
    }
    catch (IOException e) {}

    if (cmd.compareTo("GET") == 0) {
      String cData = getCreditData(name);
      retMsg = name + " " + cData;
    }
    else {
      retMsg = "UNKNOWN_CMD";
    }

    // Add return message with results to the message queue.
    addMsg(retMsg);