org.omus.core
Class Group

java.lang.Object
  |
  +--org.omus.core.Group

public class Group
extends java.lang.Object

Represents a group of users. For each group that will be created due to an entry in config.xml or dynamically by a client, an instance of Group will be created. The only way to obtain a reference to a Group instance is the groupCreated method in org.omus.ext.GroupExtension. The Java Group class is similar to the ActionScript Group object in the Client API.


Method Summary
 boolean addCommand(Command com)
          Adds the specified command to the queue of this group for later execution.
 void close()
          Closes the group so that no other users can join.
 java.util.Iterator getAllUsers()
          Returns an Iterator over all the User instances of this group.
 java.lang.String getConfigID()
          Returns the configID of the group.
 java.lang.String getName()
          Returns the name of the group.
 PropertySet getProperties()
          Returns the PropertySet object associated with this group.
 User getUser(java.lang.String username)
          Returns the User object identified by the specified user name.
 int getUserCount()
          Returns the number of users who are currently member of this group.
 int getUserLimit()
          Returns the maximum number of users permitted for this group.
 boolean isClosed()
          Returns true if the group is closed so that no other users can join.
 boolean isFull()
          Returns true if the maximum number of users has been reached.
 void open()
          Opens the group for other users to join.
 void sendToClients(Message msg)
          Sends the specified Message to all the clients in this group.
 void sendToClients(Message msg, User exclude)
          Sends the specified Message to all the clients in this group except for the specified user.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addCommand

public boolean addCommand(Command com)
Adds the specified command to the queue of this group for later execution. You will rarely need this method because all of the methods that are invoked in your GroupExtension get executed in the group queue anyway. All groups in the Oregano Server are single-threaded. Many methods of the Group, User, and PropertySet classes are protected against access from other threads because they are not synchronized. If there is a time consuming task that you delegated to a worker thread with one of the methods of the TaskManager, you cannot call these methods from within that task. So if you use the TaskManager to read from the database, for example, and want to use the values that you read to modify the properties of a user, you have to write a command that performs this task and put it into the group queue. Example code migth look like this:
     final String result = null;
     Command com1 = new Command () {
         public void execute () {
             result = aTimeConsumingCalculation();
             Command com2 = new Command () {
                 public void execute () {
                     PropertySet ps = group.getProperties();
                     StringField st = (StringField)ps.getValue("foo");
                     st.setString(result);
                 }
             };
             group.addCommand(com2);
         }
     };
     Services.getTaskManager.executeNow(com1);
 
With this approach you avoid to slow down the group queue with your time consuming calculation, but are still able to pass its result to one of the protected methods.

getConfigID

public java.lang.String getConfigID()
Returns the configID of the group. It identifies the corresponding <group>-node in config.xml that was used to configure this group. You can create an unlimited number of groups with the same configID but different names. See the Configuration chapter for more details.

getName

public java.lang.String getName()
Returns the name of the group.

isFull

public boolean isFull()
Returns true if the maximum number of users has been reached.

isClosed

public boolean isClosed()
Returns true if the group is closed so that no other users can join.

getUserLimit

public int getUserLimit()
Returns the maximum number of users permitted for this group.

getProperties

public PropertySet getProperties()
Returns the PropertySet object associated with this group.

getUserCount

public int getUserCount()
Returns the number of users who are currently member of this group.

getUser

public User getUser(java.lang.String username)
Returns the User object identified by the specified user name.

getAllUsers

public java.util.Iterator getAllUsers()
Returns an Iterator over all the User instances of this group.

open

public void open()
Opens the group for other users to join.

close

public void close()
Closes the group so that no other users can join.

sendToClients

public void sendToClients(Message msg)
Sends the specified Message to all the clients in this group. The message will be received in the onMessage event handler in the client side Messenger object.

sendToClients

public void sendToClients(Message msg,
                          User exclude)
Sends the specified Message to all the clients in this group except for the specified user. The message will be received in the onMessage event handler in the client side Messenger object.