added initial cs656/lab3/src directory
git-svn-id: svn://anubis/gvsu@210 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
6557a75000
commit
ed66ce5b9a
48
cs656/lab3/src/PresenceService.java
Normal file
48
cs656/lab3/src/PresenceService.java
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* <p>Title: Lab3</p>
|
||||
* <p>Description: Simple Chat Interface for OpenChord </p>
|
||||
* <p>Copyright: Copyright (c) 2008</p>
|
||||
* <p>Company: Grand Vally State University</p>
|
||||
* @author Jonathan Engelsma
|
||||
* @version 1.0
|
||||
*/
|
||||
import de.uniba.wiai.lspi.chord.service.ServiceException;
|
||||
|
||||
/**
|
||||
* 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 ServiceException;
|
||||
|
||||
/**
|
||||
* 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 ServiceException;
|
||||
|
||||
/**
|
||||
* 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 ServiceException;
|
||||
|
||||
|
||||
/**
|
||||
* Leave the current Chord network. Client's must call this before they
|
||||
* terminate in order to make sure the keys they maintain are passed to their
|
||||
* successor in the Chord ring.
|
||||
*/
|
||||
void leave() throws ServiceException;
|
||||
}
|
101
cs656/lab3/src/RegistrationInfo.java
Normal file
101
cs656/lab3/src/RegistrationInfo.java
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* <p>Title: Lab2</p>
|
||||
* <p>Description: Registration record for the Chord Chat System </p>
|
||||
* <p>Copyright: Copyright (c) 2008</p>
|
||||
* <p>Company: Grand Vally State University</p>
|
||||
* @author Jonathan Engelsma
|
||||
* @version 1.0
|
||||
*/
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class represents the information that the chat client registers
|
||||
* with the presence server.
|
||||
*/
|
||||
public class RegistrationInfo implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 2144157610883535152L;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chord requires stored data items to override the default hashCode() method. Leave
|
||||
* this here or you will have problems! See OpenChord manual for details.
|
||||
*/
|
||||
public int hashCode () {
|
||||
return this.toString().intern().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Chord requires stored data items to override the default equals() method. Leave
|
||||
* this here or you will have problems! See OpenChord manual for details.
|
||||
*/
|
||||
public boolean equals ( Object o){
|
||||
if (o instanceof RegistrationInfo )
|
||||
{
|
||||
return (( RegistrationInfo)o).toString().equals(this.toString() );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* hashCode() and equals() use this. Don't touch it!
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return this.userName + "@" + this.host + ":" + this.port;
|
||||
}
|
||||
}
|
38
cs656/lab3/src/StringKey.java
Normal file
38
cs656/lab3/src/StringKey.java
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* <p>Title: Lab2</p>
|
||||
* <p>Description: Chord Key for strings </p>
|
||||
* <p>Copyright: Copyright (c) 2008</p>
|
||||
* <p>Company: Grand Vally State University</p>
|
||||
* @author Jonathan Engelsma
|
||||
* @version 1.0
|
||||
*/
|
||||
import de.uniba.wiai.lspi.chord.service.Key;
|
||||
|
||||
/**
|
||||
* Implements a simple Chord Key for Strings. See sample code or OpenChord manual for more details.
|
||||
*/
|
||||
public class StringKey implements Key {
|
||||
|
||||
String theString ;
|
||||
|
||||
public StringKey ( String theString )
|
||||
{
|
||||
this.theString = theString ;
|
||||
}
|
||||
|
||||
public byte [] getBytes (){
|
||||
return this.theString.getBytes();
|
||||
}
|
||||
|
||||
public int hashCode (){
|
||||
return this.theString.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals ( Object o){
|
||||
if (o instanceof StringKey )
|
||||
{
|
||||
return (( StringKey)o).theString.equals(this.theString );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user