/*
 * Client.java
 *
 *  Created on 15. Juli 2001, 16:53
 */

package org.apache.log4j.rmi.test;

import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;

/**
 *
 * @author adm
 * @version 1.0
 */
public class Client extends Object {
    
    private static IServer server;

    /** Creates new Client */
    public Client() {
    }

    /**
    * @param args the command line arguments
    */
    public static void main (String args[]) {
        RemoteLog.config("org/apache/log4j/rmi/test/client.lcf");
        System.setSecurityManager(new RMISecurityManager());
        Client.lookup();
        Client client = new Client();
        client.communicate("hello");
        client.communicate("bye bye");
    }
    
    private static void lookup(){
        try{
            server = (IServer)Naming.lookup("//localhost/server");
            RemoteLog.main.info("Server found");
        } catch (NotBoundException nbe){
            RemoteLog.main.error("Server not bound in registery",nbe);
        } catch (RemoteException re){
            RemoteLog.main.error("RemoteException looking up Server",re);
        } catch (MalformedURLException mue){
            RemoteLog.main.error("URL for looking up Server malformed",mue);
        }
    }
    
    private void communicate(String message){
        try{
            server.receive(message);
            RemoteLog.communicate.info("sent message["+message+"]");
        } catch (RemoteException re){
            RemoteLog.communicate.error("couldn't send message["+message+"]");
        }
    }
}

