Version 1.5APIs subject to change!

multiverse.server.objects
Class Entity

java.lang.Object
  extended by multiverse.server.objects.NamedPropertyClass
      extended by multiverse.server.objects.Entity
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Bag, ClassAbilityObject, CombatInfo, Instance, MarsGroup, MarsGroupMember, MarsQuest, MVObject, ObjectManagerPlugin.MasterObject, ObjectStub, PlayerQuestStates, Road, SpawnData, VoiceStub, WorldManagerPlugin.WorldManagerInstance

public class Entity
extends NamedPropertyClass
implements java.io.Serializable

Entity is the root class of persistable objects in the Multiverse heirarchy. All entities have a unique object ID (OID). Uniqueness is guaranteed through the OIDManager which typically grabs blocks of unallocated IDs from the database.

Examples of Entities include players, monsters, weapons, armor, quests, and templates. Non-persisted configuration data is typically not an entity.

See Also:
Serialized Form

Field Summary
protected static Logger log
          Logger for this object, used to log info/debug messages.
static java.util.concurrent.locks.Lock staticLock
          Dont use this, will probably be moved.
protected  java.lang.Integer subObjectNamespacesInt
          This is the set of sub-object namespaces, compressed into an Integer by using one bit for each Namespace.
protected static java.util.Set<java.lang.Object> transientPropertyKeys
          A set of key values that are always stored in the transient map; all others are always stored in the persistent map
protected  ObjectType type
           
 
Fields inherited from class multiverse.server.objects.NamedPropertyClass
lock, name
 
Constructor Summary
Entity()
          Creates an entity and assigns it a new OID.
Entity(java.lang.Long oid)
          Creates an entity using the passed in OID.
Entity(java.lang.String name)
          Creates an entity with the given name, and assigns it a new OID.
 
Method Summary
static boolean equals(Entity obj1, Entity obj2)
          Returns if two objects are the same - tested by comparing the object id and namespace.
 boolean equals(java.lang.Object other)
          Returns if two objects are the same - tested by comparing the object id.
static Entity[] getAllEntitiesByNamespace(Namespace namespace)
          Deprecated. As of 1.5, use equivalent function on EntityManager.
static Entity getEntityByNamespace(java.lang.Long oid, Namespace namespace)
          Deprecated. As of 1.5, use equivalent function on EntityManager.
static int getEntityCount()
          Deprecated. As of 1.5, use equivalent function on EntityManager.
 java.util.concurrent.locks.Lock getLock()
          Returns the lock for this entity.
 Namespace getNamespace()
          Returns the namespace containing the entity
 java.lang.Long getOid()
          Returns OID for this Entity
 boolean getPersistenceFlag()
          Returns true if the object has been marked persistent.
 java.io.Serializable getProperty(java.lang.String key)
          If the key is in the transientPropertyKeys set, get the value associated with the key from the transientMap; otherwise get it from the persistent map
 java.util.List<Namespace> getSubObjectNamespaces()
          Get a list of the sub-object Namespace objects associated with the Entity.
 java.lang.Integer getSubObjectNamespacesInt()
          Get the subObjectNamespacesInt; exists only to provide a JavaBean interface, so that the database code will persist the Integer.
 java.util.Map<java.lang.String,java.io.Serializable> getTransientDataRef()
           
 ObjectType getType()
          Entity object type.
 int hashCode()
          Returns the OID as hashcode since it is unique.
 boolean isDeleted()
           
static void registerEntityByNamespace(Entity entity, Namespace namespace)
          Deprecated. As of 1.5, use equivalent function on EntityManager.
static java.lang.Object registerTransientPropertyKey(java.lang.Object key)
          Adds an object to the transientPropertyKeys map
static boolean removeEntityByNamespace(Entity entity, Namespace namespace)
          Deprecated. As of 1.5, use equivalent function on EntityManager.
static boolean removeEntityByNamespace(java.lang.Long oid, Namespace namespace)
          Deprecated. As of 1.5, use equivalent function on EntityManager.
 void setDeleted()
           
 void setNamespace(Namespace namespace)
          Sets the entity's namespace
 void setOid(java.lang.Long oid)
          Sets the OID for this entity.
 void setPersistenceFlag(boolean flag)
          mark this object as being persistent or not.
 java.io.Serializable setProperty(java.lang.String key, java.io.Serializable value)
          If the key is in the transientPropertyKeys set, store the key/value pair in the transientMap; otherwise store it in the persistent map
 void setSubObjectNamespaces(java.util.Set<Namespace> namespaces)
          Set the sub-object Namespace objects associated with the Entity.
 void setSubObjectNamespacesInt(java.lang.Integer value)
          Set the subObjectNamespacesInt; exists only to provide a JavaBean interface, so that the database code will persist the Integer.
 void setType(ObjectType type)
          Set the Entity object type.
 byte[] toBytes()
          Serializes this entity and returns the byte array.
 java.lang.String toString()
          Returns the string describing this entity, useful for logging.
static void unregisterTransientPropertyKey(java.lang.Object key)
          Removes an object to the transientPropertyKeys set
 
Methods inherited from class multiverse.server.objects.NamedPropertyClass
getBooleanProperty, getIntProperty, getName, getPropertyMap, getPropertyMapRef, getStringProperty, lock, modifyIntProperty, setName, setPropertyMap, setupTransient, unlock
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

transientPropertyKeys

protected static java.util.Set<java.lang.Object> transientPropertyKeys
A set of key values that are always stored in the transient map; all others are always stored in the persistent map


subObjectNamespacesInt

protected java.lang.Integer subObjectNamespacesInt
This is the set of sub-object namespaces, compressed into an Integer by using one bit for each Namespace.


log

protected static final Logger log
Logger for this object, used to log info/debug messages.


type

protected ObjectType type

staticLock

public static java.util.concurrent.locks.Lock staticLock
Dont use this, will probably be moved. Lock for all entities map.

Constructor Detail

Entity

public Entity()
Creates an entity and assigns it a new OID.


Entity

public Entity(java.lang.String name)
Creates an entity with the given name, and assigns it a new OID.

Parameters:
name - name for the entity.

Entity

public Entity(java.lang.Long oid)
Creates an entity using the passed in OID. This is typically used when loading a saved entity from the database since you want to set the OID to match what was saved.

Parameters:
oid - OID for the constructed entity
Method Detail

toString

public java.lang.String toString()
Returns the string describing this entity, useful for logging.

Overrides:
toString in class java.lang.Object
Returns:
string describing entity

hashCode

public int hashCode()
Returns the OID as hashcode since it is unique.

Overrides:
hashCode in class java.lang.Object

getOid

public java.lang.Long getOid()
Returns OID for this Entity

Returns:
oid for this Entity

setOid

public void setOid(java.lang.Long oid)
Sets the OID for this entity. This generally should not be used since it means the old OID is thrown away and probably wasted. Try to use the constructor which takes in an OID instead.

Parameters:
oid - the OID to set for this entity.

getType

public ObjectType getType()
Entity object type.

Returns:
ObjectTypes.unknown if no object type has been set.

setType

public void setType(ObjectType type)
Set the Entity object type.


getTransientDataRef

public java.util.Map<java.lang.String,java.io.Serializable> getTransientDataRef()

equals

public static boolean equals(Entity obj1,
                             Entity obj2)
Returns if two objects are the same - tested by comparing the object id and namespace. null objects are never equal to any other object including other null objects.


equals

public boolean equals(java.lang.Object other)
Returns if two objects are the same - tested by comparing the object id. null objects are never equal to any other object including other null objects.

Overrides:
equals in class java.lang.Object

setPersistenceFlag

public void setPersistenceFlag(boolean flag)
mark this object as being persistent or not. other systems will check this field and save the object to the database when appropriate.


getPersistenceFlag

public boolean getPersistenceFlag()
Returns true if the object has been marked persistent. saved objects maintain this state


getNamespace

public Namespace getNamespace()
Returns the namespace containing the entity


setNamespace

public void setNamespace(Namespace namespace)
Sets the entity's namespace


getSubObjectNamespaces

public java.util.List<Namespace> getSubObjectNamespaces()
Get a list of the sub-object Namespace objects associated with the Entity.

Returns:
List of Namespace objects

setSubObjectNamespaces

public void setSubObjectNamespaces(java.util.Set<Namespace> namespaces)
Set the sub-object Namespace objects associated with the Entity.

Parameters:
namespaces - A list of Namespace objects

getLock

public java.util.concurrent.locks.Lock getLock()
Returns the lock for this entity. Be careful when using the lock, since it can easily lead to a deadlock.

Returns:
A Lock object.

toBytes

public byte[] toBytes()
Serializes this entity and returns the byte array.

Returns:
byte array for serialized entity

setProperty

public java.io.Serializable setProperty(java.lang.String key,
                                        java.io.Serializable value)
If the key is in the transientPropertyKeys set, store the key/value pair in the transientMap; otherwise store it in the persistent map

Overrides:
setProperty in class NamedPropertyClass
Returns:
old value for given key or null if none ever set.

getProperty

public java.io.Serializable getProperty(java.lang.String key)
If the key is in the transientPropertyKeys set, get the value associated with the key from the transientMap; otherwise get it from the persistent map

Overrides:
getProperty in class NamedPropertyClass
Parameters:
key - serializable key object.
Returns:
value of the property, null if property does not exist.
See Also:
NamedPropertyClass.setProperty(String, Serializable)

isDeleted

public boolean isDeleted()

setDeleted

public void setDeleted()

registerTransientPropertyKey

public static java.lang.Object registerTransientPropertyKey(java.lang.Object key)
Adds an object to the transientPropertyKeys map


unregisterTransientPropertyKey

public static void unregisterTransientPropertyKey(java.lang.Object key)
Removes an object to the transientPropertyKeys set


getEntityByNamespace

public static Entity getEntityByNamespace(java.lang.Long oid,
                                          Namespace namespace)
Deprecated. As of 1.5, use equivalent function on EntityManager.

Get the Entity object for the given OID and namespace

Returns:
The Entity corresponding to the OID and namespace, or null

registerEntityByNamespace

public static void registerEntityByNamespace(Entity entity,
                                             Namespace namespace)
Deprecated. As of 1.5, use equivalent function on EntityManager.

Register the entity by its OID and the Namespace passed in. This method silently replaces any existing entity of the same oid and namespace, because that's what the old code did.


removeEntityByNamespace

public static boolean removeEntityByNamespace(Entity entity,
                                              Namespace namespace)
Deprecated. As of 1.5, use equivalent function on EntityManager.

Unregister the entity, using its OID and the Namespace


removeEntityByNamespace

public static boolean removeEntityByNamespace(java.lang.Long oid,
                                              Namespace namespace)
Deprecated. As of 1.5, use equivalent function on EntityManager.

Look up the Entity by OID and Namespace, and unregister it


getAllEntitiesByNamespace

public static Entity[] getAllEntitiesByNamespace(Namespace namespace)
Deprecated. As of 1.5, use equivalent function on EntityManager.

Return an array containing all the Entity objects registered in the Namespace.


getEntityCount

public static int getEntityCount()
Deprecated. As of 1.5, use equivalent function on EntityManager.


getSubObjectNamespacesInt

public java.lang.Integer getSubObjectNamespacesInt()
Get the subObjectNamespacesInt; exists only to provide a JavaBean interface, so that the database code will persist the Integer.


setSubObjectNamespacesInt

public void setSubObjectNamespacesInt(java.lang.Integer value)
Set the subObjectNamespacesInt; exists only to provide a JavaBean interface, so that the database code will persist the Integer.



Copyright © 2008 The Multiverse Network, Inc.