import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
import java.math.*;

public class TimesImpl extends UnicastRemoteObject implements Stream, Runnable{

   BigInteger multiplier;
   Stream stream;
   Monitor monitor;
   
   public TimesImpl (String number, Stream stream) throws RemoteException {  
      super();  
      multiplier = new BigInteger(number);
      this.stream = stream;
      monitor = new Monitor(this);
   }

   public Object next () throws RemoteException { return monitor.next(); }

   public void run () {
      while (true) {
	 try {
	    IntObject object = (IntObject)stream.next();
	    BigInteger n = (BigInteger)object.valueOf();
	    n = n.multiply(multiplier);
	    monitor.putIt(new IntObject(n));
	 } catch (Exception e) {
	    System.out.println("TimesImpl Caught:"+e.toString());
	 }
      }
   }
}

