Modifier and Type | Field and Description |
---|---|
private ThreadedSimpleTask<Pair<Message,User>> |
giveMessage
Deliver message to user in separate thread
|
private java.util.HashMap<java.lang.String,SortedArray<java.lang.String>> |
groups
Groups map
|
static PostOffice |
POST_OFFICE
Post office singleton
|
private java.util.HashMap<java.lang.String,User> |
users
Users map
|
Modifier | Constructor and Description |
---|---|
private |
PostOffice()
Create a new instance of PostOffice
|
Modifier and Type | Method and Description |
---|---|
void |
addToGroup(User user,
java.lang.String group)
Add a user to a group.
|
java.util.Set<java.lang.String> |
getGroupNames()
Set of actual groups
|
java.util.List<java.lang.String> |
getGroupsFor(java.lang.String user)
Give the list where the user is in
|
java.util.List<java.lang.String> |
getMembers(java.lang.String group)
Give the list of the members of a group
|
java.util.Set<java.lang.String> |
getUserNames()
List of registered users
|
boolean |
isInGroup(User user,
java.lang.String group)
Indicates if a user is in a group
|
boolean |
isRegisteredUser(java.lang.String user)
Indicates if a user is registered
|
boolean |
postMessage(User sender,
int messageId,
java.lang.String destination,
java.lang.Object message)
Post a message for a specific user
|
void |
postMessageForAll(User sender,
int messageId,
java.lang.Object message,
boolean excludeMe)
Post a message for all registered users
|
void |
postMessageForGroup(User sender,
int messageId,
java.lang.String group,
java.lang.Object message)
Post a message for all members of a group
|
void |
registerUser(User user)
Register a user
|
void |
removeFromGroup(User user,
java.lang.String group)
Remove a user from a group
|
void |
unregisterUser(User user)
Unregister a user
|
public static final PostOffice POST_OFFICE
private final ThreadedSimpleTask<Pair<Message,User>> giveMessage
private final java.util.HashMap<java.lang.String,SortedArray<java.lang.String>> groups
private final java.util.HashMap<java.lang.String,User> users
public void addToGroup(User user, java.lang.String group)
user
- User to addgroup
- Group where add.public java.util.Set<java.lang.String> getGroupNames()
public java.util.List<java.lang.String> getGroupsFor(java.lang.String user)
user
- User namepublic java.util.List<java.lang.String> getMembers(java.lang.String group)
group
- Group namepublic java.util.Set<java.lang.String> getUserNames()
public boolean isInGroup(User user, java.lang.String group)
user
- User testedgroup
- Group nametrue
if the user is in the grouppublic boolean isRegisteredUser(java.lang.String user)
user
- User name testedtrue
if the user is registeredpublic boolean postMessage(User sender, int messageId, java.lang.String destination, java.lang.Object message)
sender
- Message sendermessageId
- Message IDdestination
- User destinationmessage
- Message to sendtrue
if message posted.false
if message not posted, because the destination user dosen't exitspublic void postMessageForAll(User sender, int messageId, java.lang.Object message, boolean excludeMe)
sender
- Sender of messagemessageId
- Message IDmessage
- Message it selfexcludeMe
- Indicates if the sender is not in the distributionpublic void postMessageForGroup(User sender, int messageId, java.lang.String group, java.lang.Object message)
sender
- SendermessageId
- Message IDgroup
- Group to sendmessage
- Message itselfpublic void registerUser(User user)
user
- User to registerpublic void removeFromGroup(User user, java.lang.String group)
user
- User to removegroup
- Group where removepublic void unregisterUser(User user)
user
- User to unregister