From 5c353891922e80ec7f681b5a32def12a317e7bcb Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 13 Sep 2008 19:56:21 +0000 Subject: [PATCH] added lab2 directory git-svn-id: svn://anubis/gvsu@138 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs656/lab2/src/PresenceService.java | 48 ++++++++++++++++ cs656/lab2/src/PresenceServiceImpl.java | 53 ++++++++++++++++++ cs656/lab2/src/RegistrationInfo.java | 73 +++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 cs656/lab2/src/PresenceService.java create mode 100644 cs656/lab2/src/PresenceServiceImpl.java create mode 100644 cs656/lab2/src/RegistrationInfo.java diff --git a/cs656/lab2/src/PresenceService.java b/cs656/lab2/src/PresenceService.java new file mode 100644 index 0000000..3515ece --- /dev/null +++ b/cs656/lab2/src/PresenceService.java @@ -0,0 +1,48 @@ +/** + *

Title: Lab2

+ *

Description: Simple Chat System

+ *

Copyright: Copyright (c) 2007

+ *

Company: Grand Vally State University

+ * @author Jonathan Engelsma + * @version 2.0 + */ +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * The abstract interface that is to implemented by a remote + * presence server. ChatClients will use this interface to + * register themselves with the presence server, and also to + * determine and locate other users who are available for chat + * sessions. + */ +public interface PresenceService extends Remote { + + /** + * Register a client with the presence service. + * @param reg The information that is to be registered about a client. + */ + void register(RegistrationInfo reg) throws RemoteException; + + /** + * Unregister a client from the presence service. Client must call this + * method when it terminates execution. + * @param userName The name of the user to be unregistered. + */ + void unregister(String userName) throws RemoteException; + + /** + * Lookup the registration information of another client. + * @name The name of the client that is to be located. + * @return The RegistrationInfo info for the client, or null if + * no such client was found. + */ + RegistrationInfo lookup(String name) throws RemoteException; + + /** + * Determine all users who are currently registered in the system. + * @return An array of RegistrationInfo objects - one for each client + * present in the system. + */ + RegistrationInfo[] listRegisteredUsers() throws RemoteException; +} diff --git a/cs656/lab2/src/PresenceServiceImpl.java b/cs656/lab2/src/PresenceServiceImpl.java new file mode 100644 index 0000000..851526d --- /dev/null +++ b/cs656/lab2/src/PresenceServiceImpl.java @@ -0,0 +1,53 @@ +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +public class PresenceServiceImpl implements PresenceService +{ + public PresenceServiceImpl() + { + super(); + } + + public void register(RegistrationInfo reg) + { + } + + public void unregister(String userName) + { + } + + public RegistrationInfo lookup(String name) + { + return null; + } + + public RegistrationInfo[] listRegisteredUsers() + { + return null; + } + + public static void main(String[] args) + { + if (System.getSecurityManager() == null) + { + System.setSecurityManager(new SecurityManager()); + } + try + { + PresenceServiceImpl impl = new PresenceServiceImpl(); + PresenceService stub = (PresenceService) + UnicastRemoteObject.exportObject(impl, 0); + Registry registry = LocateRegistry.getRegistry(); + registry.rebind("PresenceServiceImpl", stub); + System.out.println("PresenceServiceImpl bound"); + } + catch (Exception e) + { + System.err.println("PresenceServiceImpl exception:"); + e.printStackTrace(); + } + } +} + + diff --git a/cs656/lab2/src/RegistrationInfo.java b/cs656/lab2/src/RegistrationInfo.java new file mode 100644 index 0000000..01c67dc --- /dev/null +++ b/cs656/lab2/src/RegistrationInfo.java @@ -0,0 +1,73 @@ +/** + *

Title: Lab2

+ *

Description: Simple Chat System

+ *

Copyright: Copyright (c) 2007

+ *

Company: Grand Vally State University

+ * @author Jonathan Engelsma + * @version 2.0 + */ +import java.io.*; + +/** + * This class represents the information that the chat client registers + * with the presence server. + */ +public class RegistrationInfo implements Serializable +{ + private String userName; + private String host; + private boolean status; + private int port; + + /** + * RegistrationInfo constructor. + * @param uname Name of the user being registered. + * @param h Name of the host their client is running on. + * @param p The port # their client is listening for connections on. + * @param s The status, true if the client is available to host a game, false otherwise. + */ + public RegistrationInfo(String uname, String h, int p, boolean s) + { + this.userName = uname; + this.host = h; + this.port = p; + this.status = s; + } + + /** + * Determine the name of the user. + * @return The name of the user. + */ + public String getUserName() + { + return this.userName; + } + + /** + * Determine the host the user is on. + * @return The name of the host client resides on. + */ + public String getHost() + { + return this.host; + } + + /** + * Get the port the client is listening for connections on. + * @return port value. + */ + public int getPort() + { + return this.port; + } + + /** + * Get the status of the client - true means availability, false means don't disturb. + * @return status value. + */ + public boolean getStatus() + { + return this.status; + } + +} \ No newline at end of file