added gvsu/cs656/lab4
git-svn-id: svn://anubis/gvsu@229 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
ec5eb17457
commit
507a723e8e
@ -0,0 +1,59 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename: PresenceService.java
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
// $Id:$
|
||||||
|
//
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
package edu.gvsu.cis.cs656.lab4.server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jonathan Engelsma
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a client with the presence service.
|
||||||
|
* @param reg The information that is to be registered about a client.
|
||||||
|
*/
|
||||||
|
void register(RegistrationInfo reg) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup the registration information of another client.
|
||||||
|
* @param 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 Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the user's presence status.
|
||||||
|
* @param name The name of the user whose status is to be set.
|
||||||
|
* @param status true if user is available, false otherwise.
|
||||||
|
*/
|
||||||
|
void setStatus(String userName, boolean status) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 Exception;
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
//----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename: RegistrationInfo.java
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
// $Id:$
|
||||||
|
//
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
package edu.gvsu.cis.cs656.lab4.server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jonathan Engelsma
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the information that the chat client registers
|
||||||
|
* with the presence server.
|
||||||
|
*/
|
||||||
|
public class RegistrationInfo
|
||||||
|
{
|
||||||
|
private String userName;
|
||||||
|
private String host;
|
||||||
|
private boolean status;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
public RegistrationInfo()
|
||||||
|
{
|
||||||
|
this.userName = null;
|
||||||
|
this.host = null;
|
||||||
|
this.status = false;
|
||||||
|
this.port = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param userName the userName to set
|
||||||
|
*/
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the host the user is on.
|
||||||
|
* @return The name of the host client resides on.
|
||||||
|
*/
|
||||||
|
public String getHost()
|
||||||
|
{
|
||||||
|
return this.host;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param host the host to set
|
||||||
|
*/
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the port the client is listening for connections on.
|
||||||
|
* @return port value.
|
||||||
|
*/
|
||||||
|
public int getPort()
|
||||||
|
{
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param port the port to set
|
||||||
|
*/
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the client - true means availability, false means don't disturb.
|
||||||
|
* @return status value.
|
||||||
|
*/
|
||||||
|
public boolean getStatus()
|
||||||
|
{
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the user's busy/available status.
|
||||||
|
* @param status set to true if user is available, false otherwise.
|
||||||
|
*/
|
||||||
|
public void setStatus(boolean status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hashCode() and equals() use this. Don't touch it!
|
||||||
|
*/
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return this.userName + "@" + this.host + ":" + this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user