All pastes #29633 Raw Edit

nauti

public java v1 · immutable
#29633 ·published 2005-11-20 16:25 UTC
rendered paste body
package at.ac.tuwien.dslab.rmi.client;import at.ac.tuwien.dslab.rmi.client.interfaces.*; import at.ac.tuwien.dslab.rmi.common.interfaces.*;import at.ac.tuwien.dslab.rmi.common.*;import at.ac.tuwien.dslab.rmi.client.*; import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.Serializable;import java.util.Properties;import java.util.Hashtable;import java.util.Properties;import java.net.MalformedURLException;import java.rmi.NotBoundException;import java.rmi.RemoteException;import java.rmi.Naming;import java.rmi.server.UnicastRemoteObject;public class SkyNetClientImpl implements ISkyNetClient, ISkyNetListener, Serializable {	protected static ISkyNetManager manager = null;	protected static IBuddy myPersonality = null;	protected static ISkyNetListener listener = null;	protected static boolean exitSkyNet = false;	private CommandQueue commands = null;		public static void main(String[] args) 	{		if(args.length == 1) {						try {				Properties props = DSLabUtils.loadPropertiesFromFile(args[0]);										new SkyNetClientImpl(props);			} catch(Exception e) {				System.out.println("Unknown Exception in SkyNetClient: "+e.getMessage());			} 		}	}		public SkyNetClientImpl(Properties props) throws RemoteException 	{		commands = new CommandQueue();		requestRmiObjects( getRmiUrl(props) );	}		private void requestRmiObjects(String url) throws RemoteException 	{		try {			UnicastRemoteObject.exportObject(this);			manager = (ISkyNetManager) Naming.lookup(url);			myPersonality = new BuddyImpl();			listener = (ISkyNetListener) Naming.lookup(url);			manager.addSkyNetListener(listener);			System.out.println("SkyNet says: I welcome you... give me some commands please!");				run();			manager.removeSkyNetListener(listener);		} catch(NotBoundException nbe) {			System.out.println(nbe.getMessage());		} catch(MalformedURLException mfue) {			System.out.println(mfue.getMessage());		}	}	private String getRmiUrl(Properties p) 	{						return "rmi://"+p.getProperty("RMI_HOSTNAME")+":"+p.getProperty("RMI_PORT")+"/"+p.getProperty("RMI_OBJECT");	}		public void run() 	{		try {			BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));			String inputLine = null;			while(exitSkyNet == false && (inputLine = stdIn.readLine()) != null) {					executeCommand(inputLine);			}			stdIn.close();			UnicastRemoteObject.unexportObject(this, true);		} catch(SkyNetException sne) {			System.out.println("SkyNet says: "+sne.getMessage());			run();		} catch(IOException e) {			System.out.println("Unknown Exception in SkyNetClientImpl: "+e.getMessage());		}	}		public void executeCommand(String command) throws SkyNetException, SkyNetCommandException 	{		findCommandAndExecute(command.split(" "));	}		private void findCommandAndExecute(String[] arg) throws SkyNetException	{		if(commands.getQueue().containsKey(arg[0])) {			commands.getQueue().get(arg[0]).exec(arg);		} else {			throw new SkyNetCommandException("command not recognized");		}	}	    public void buddyLoggedIn(String sourceID, IBuddy buddy, ISkyNetListener listener) throws RemoteException    {    	System.out.println("neuer buddy online");    }        public void buddyLoggedOut(String sourceID, IBuddy buddy) throws RemoteException    {    	System.out.println("buddy geht offline");    }        public void messageReceived(String senderNickname, String receiverNickname, String msg) throws RemoteException    {    	System.out.println("nachricht empfangen");	}		public void fileReceived(java.lang.String senderNickname, String receiverNickname, String filename, byte[] data) throws RemoteException	{		System.out.println("datei empfangen");	}}