Attribute Persistence

The AttributePersistence interface provides a way of persisting attributes that have been set for the Server, Rooms and Clients. Any Object can take care of AttributePersistence as long as it implements the AttributePersistence interface.

Server and Room persistence is automatic. Client persistence is automatic when a Client is logged in but clients must be logged in, created and removed manually. These methods must be must be called for example by a Room or Service. When a client has logged in successfully isLoggedIn() from the ClientServices for the Client will return true.

For an attribute to passed to the APO (Attribute Persistence Object) it must have been flagged as persistent when set. A persistent attribute has a flag of either 2 (persistent only) or 3 (shared and persistent). An exception is Server attributes all of which are considered to be persistent.

The APO to be used is declared in uconfig.xml under the SERVER tag as:
<ATTRIBUTE_PERSISTENCE>
    <CLASS>MyAttributePersistenceClass</CLASS>
    <ATTRIBUTES>
        <AN_ATTRIBUTE>anAttribute</AN_ATTRIBUTE>
    </ATTRIBUTES>
</ATTRIBUTE_PERSISTENCE>
CLASS is the fully qualified name of the APO. This Class must be in the Classpath so Unity 2 Multiuser Server can load it.
All tags within the ATTRIBUTES tag are passed to the APO's init method and are used to customize an APO at Runtime. The ATTRIBUTES tag is not to be confused with the Server, Room, and Client attribtues the APO is meant to persist.

For example, here's the tag used to indicate that Unity 2 Multiuser Server should use the supplied MySQL APO.

<ATTRIBUTE_PERSISTENCE>
    <CLASS>org.moock.unity.opt.sqlap.SQLAttributePersistence</CLASS>
        <ATTRIBUTES>
        <DRIVER>org.gjt.mm.mysql.Driver</DRIVER>
        <URL>jdbc:mysql://db_ip:3306/db_name</URL>
        <USERNAME>db_username</USERNAME>
        <PASSWORD>db_password</PASSWORD>
        <CLIENT_ID_KEY>username</CLIENT_ID_KEY>
    </ATTRIBUTES>
</ATTRIBUTE_PERSISTENCE>
See Javadoc for information on all methods in the AttributePersistence interface.