updated ChatClient.java, PresenceServiceImpl.java
git-svn-id: svn://anubis/gvsu@220 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
463a762315
commit
e301f20c16
@ -287,6 +287,15 @@ public class ChatClient
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
unregister();
|
unregister();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
myPServ.leave(); /* Leave the Chord network */
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,6 +352,13 @@ public class ChatClient
|
|||||||
|
|
||||||
// Load the Chord properties files
|
// Load the Chord properties files
|
||||||
PropertiesLoader.loadPropertyFile();
|
PropertiesLoader.loadPropertyFile();
|
||||||
|
|
||||||
|
ChordClient chordClient = new ChordClient(host, master);
|
||||||
|
|
||||||
|
PresenceService pServ = new PresenceServiceImpl(chordClient);
|
||||||
|
|
||||||
|
ChatClient chatClient = new ChatClient(pServ, user);
|
||||||
|
chatClient.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void usage()
|
private static void usage()
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
// CS656
|
// CS656
|
||||||
// Lab Excersize 3
|
// Lab Excersize 3
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the PresenceService interface using Chord.
|
* This class implements the PresenceService interface using Chord.
|
||||||
* It provides a presence service for the chat system.
|
* It provides a presence service for the chat system.
|
||||||
@ -20,22 +23,54 @@ public class PresenceServiceImpl implements PresenceService
|
|||||||
/* a user calls this method to register with the presence service */
|
/* a user calls this method to register with the presence service */
|
||||||
public void register(RegistrationInfo reg)
|
public void register(RegistrationInfo reg)
|
||||||
{
|
{
|
||||||
|
StringKey userName = new StringKey(reg.getUserName());
|
||||||
|
try {
|
||||||
|
myChordClient.chord().insert(userName, reg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a user calls this method to unregister with the presence service */
|
/* a user calls this method to unregister with the presence service */
|
||||||
public void unregister(String userName)
|
public void unregister(String userName)
|
||||||
{
|
{
|
||||||
|
StringKey userNameKey = new StringKey(userName);
|
||||||
|
try {
|
||||||
|
myChordClient.chord().remove(userNameKey, lookup(userName));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a user calls this method to get the registration information
|
/* a user calls this method to get the registration information
|
||||||
* for another user by name */
|
* for another user by name */
|
||||||
public RegistrationInfo lookup(String name)
|
public RegistrationInfo lookup(String name)
|
||||||
{
|
{
|
||||||
|
StringKey userNameKey = new StringKey(name);
|
||||||
|
try {
|
||||||
|
Set<Serializable> vals = myChordClient.chord().retrieve(userNameKey);
|
||||||
|
Iterator<Serializable> it = vals.iterator();
|
||||||
|
if (it.hasNext())
|
||||||
|
{
|
||||||
|
RegistrationInfo data = (RegistrationInfo) it.next();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called when a user wishes to leave the network */
|
/* called when a user wishes to leave the network */
|
||||||
public void leave()
|
public void leave()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
myChordClient.chord().leave();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user