/* Implementation of the rmistack interface. It is this file from which we will use rmic on to generate code that automatically handles incomming requests. */ import java.rmi.*; import java.rmi.server.*; import java.util.*; // for arraylist data structure // Every remote call to a method on a RemoteObject will spin off a new // thread, which may need to be synchronized. The distributed concurrency // is thus mirrored by local thread-concurrency on the server. public class stackimpl extends UnicastRemoteObject implements rmistack { private ArrayList St; // even the constructor must decalre exception public stackimpl() throws RemoteException { St = new ArrayList(); } public int size() throws RemoteException { return St.size(); } public void push(String s) throws RemoteException { St.add(s); } public String pop() throws RemoteException { int n = St.size(); String response = null; if (n>0) { response = St.get(n-1); // return last element of arraylist St.remove(n-1); } return response; } public String peek() throws RemoteException { int n = St.size(); String response = null; if (n>0) { response = St.get(n-1); // return last element of arraylist } return response; } // main will register a stackimpl object with the local rmiregistry public static void main(String[] args) throws Exception { stackimpl stack0 = new stackimpl(); stackimpl stack1 = new stackimpl(); Naming.rebind("stack0",stack0); // register with local rmiregistry Naming.rebind("stack1",stack1); // register with local rmiregistry } }//stackimpl // Run this program after starting the rmiregistry on the local machine.