Creating Electronic Markets 
by Ming Fan, Jan Stallaert, Andrew B. Whinston


Listing One
// Market Maker implementation. 
// Implements methods defined in MarketMakerInterface
public class MarketMakerImpl extends UnicastRemoteObject implements
  MarketMakerInterface {
  ...
  // implement the method SendOrder() advertised in interface
  public synchronized int SendOrder(Bundle offer) throws RemoteException {
  ...
  }
  // implement pass() advertised in interface
  public synchronized void pass(TradeAppletInterface o) 
                                                 throws RemoteException {
  ...
    // register TradeApplet in a Vector
    tradeClients.addElement(o);
  ...
  }
  ...
  // Market Maker callback TradeApplet & send it a Vector 
  // by invoking TradeApplet's method receive()
  TradeAppletInterface
               trader=(TradeAppletInterface)tradeClients.elementAt(i);
  trader.receive(somevector);
  ...
}

Listing Two
// Market Maker object binds itself to be "MM" 
public class MarketMaker {
  ...
MarketMakerImpl theServer = new MarketMakerImpl("MM"); 
Naming.rebind("MM", theServer);
.}

Listing Three
// TradeApplet 
public class TradeApplet extends Applet implements TradeAppletInterface,
  java.io.Serializable {
  ... 
  // TradeApplet locate Market Maker object using its URL and registered name
  // Before this, TradeApplet needs to export itself to enable callback
  UnicastRemoteObject.exportObject(this);
  String servername = "rmi://serverURL/" + "MM";
  MarketMaker = (MarketMakerInterface)Naming.lookup(servername);
  
  // TradeApplet passes itself to Market Maker 
  //              by invoking pass() on MarketMaker
  MarketMaker.pass(this);
  ...
  // TradeApplet send the order by invoking the remote method
  feedback = MarketMaker.SendOrder(order);
  ...
  // implement receive( )
  public void receive(Vector m) {
  ...
  }
  ...
}

Listing Four
SendOrder (Bundle order)  
{
   generate order ID for the new order based on initial order ID;
   increment order ID;
   add order to the open order Vector;
}




2


