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

public class HelloImpl
        extends UnicastRemoteObject
        implements Hello {
        private String name;

        public HelloImpl(String s) throws RemoteException {
		System.out.println(
		   "\tHelloImpl: HelloImpl(String s)");
                name = s;
        }

        public String sayHelloAndWait() throws RemoteException {
		Date d;
		System.out.println("sayHelloAndWait: ---> ");
		System.out.println("\tSleeping .... ");
		for ( int index = 1; index < 100000; index ++ )
			d = new Date();
		System.out.println("\tGood morning");
		System.out.println("sayHelloAndWait: <-- ");
                return  "Hello World my friend.";
        }

        public synchronized String synchronizedSayHelloAndWait() throws RemoteException {
		Date d;
		System.out.println("synchronizedSayHelloAndWait: ---> ");
		System.out.println("\tSleeping .... ");
		for ( int index = 1; index < 100000; index ++ )
			d = new Date();
		System.out.println("\tGood morning");
		System.out.println("synchronizedSayHelloAndWait: <-- ");
                return  "Hello World my friend.";
        }

        public static void main(String args[])
        {
                // System.setSecurityManager(new RMISecurityManager());

                try {
                    HelloImpl obj = new HelloImpl("HelloServer");
                    Naming.rebind("//yps/HelloServer", obj);
                    System.out.println("HelloServer bound in registry");
                } catch (Exception e) {
                    System.out.println("HelloImpl err: " + e.getMessage());
                    e.printStackTrace();
                }
        }
}

