uka.transport
Class SimpleObjectSpace

java.lang.Object
  extended byuka.util.IDConstants
      extended byuka.transport.SimpleObjectSpace
All Implemented Interfaces:
ObjectSpace, Printable

public final class SimpleObjectSpace
extends IDConstants
implements ObjectSpace, Printable


Field Summary
private  EnlargingArray objects
           
(package private)  int rewriteFirstID
           
(package private)  int rewriteOffset
           
 
Fields inherited from class uka.util.IDConstants
FIRST_NEW_ID, FIRST_VALID_ID, INVALID_ID, UNUSED_ID
 
Constructor Summary
SimpleObjectSpace()
           
 
Method Summary
 void appendTo(ToString s)
          This method should append the contents of each instance variable of the current object to the given ToString object.
 void beginRewrite(int rewriteFirstID, int rewriteOffset)
           
 void clear()
          Clears the object space by removing all identifier assignments.
 void endRewrite()
           
 int findID(java.lang.Object obj)
          Same as getID(java.lang.Object), but does not assign the object to this object space, if the object was not yet a member.
 int getID(java.lang.Object obj)
          Returns the identifier for a given object.
 java.lang.Object getObject(int id)
          Finds the object for a given identifier.
 IntIterator getUsedIDs()
           
 void includeID(int id)
          Make the object that corresponds to the given identifier part of this object space.
 boolean isAccepted(int id)
          Decides whether an object reference should be blocked during transmission through a MarshalStream/UnmarshalStream pair.
 boolean isIncluded(int id)
          Decides whether the obect that corresponds to the given identifier is part of this object space.
 boolean isShared(int id)
           
 boolean isUsed(int id)
          Checks whether this object space has an object assigned to the given identifier.
 void remove(int id)
          Removes the given identifer from this object space.
 void resetObject(int id, java.lang.Object obj)
          Reassigns a new object to an existing identifier.
private  int rewriteIncomming(int id)
           
private  int rewriteOutgoing(int id)
           
 void setObject(int id, java.lang.Object obj)
          Assigns the given object to an application provided identifier and includes the given object to this object space.
 
Methods inherited from class uka.util.IDConstants
isNew, isValid, normalizeID, toggleNew
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objects

private final EnlargingArray objects

rewriteFirstID

int rewriteFirstID

rewriteOffset

int rewriteOffset
Constructor Detail

SimpleObjectSpace

public SimpleObjectSpace()
Method Detail

rewriteIncomming

private int rewriteIncomming(int id)

rewriteOutgoing

private int rewriteOutgoing(int id)

beginRewrite

public void beginRewrite(int rewriteFirstID,
                         int rewriteOffset)

endRewrite

public void endRewrite()

getUsedIDs

public IntIterator getUsedIDs()
Specified by:
getUsedIDs in interface ObjectSpace

includeID

public void includeID(int id)
Description copied from interface: ObjectSpace
Make the object that corresponds to the given identifier part of this object space. An object is part of an object space, if the ObjectSpace.isIncluded(int) method returns true for the corresponding identifier. An object can have an assigned identifier in some object space without being part of that object space.

Specified by:
includeID in interface ObjectSpace
Returns:
the identifier assigned to the object passed as parameter.

isIncluded

public boolean isIncluded(int id)
Description copied from interface: ObjectSpace
Decides whether the obect that corresponds to the given identifier is part of this object space.

Specified by:
isIncluded in interface ObjectSpace
Returns:
whether the object that corresponds to the given identifier is part of this object space.
See Also:
ObjectSpace.includeID(int)

setObject

public void setObject(int id,
                      java.lang.Object obj)
Description copied from interface: ObjectSpace
Assigns the given object to an application provided identifier and includes the given object to this object space.

Specified by:
setObject in interface ObjectSpace

resetObject

public void resetObject(int id,
                        java.lang.Object obj)
Description copied from interface: ObjectSpace
Reassigns a new object to an existing identifier. The effect is the same as removing the identifier first and then reassigning it with ObjectSpace.setObject(int, java.lang.Object). Since ObjectSpace.setObject(int, java.lang.Object) may be overridden in subclasses to handle the first assignment of an identifier especially, ObjectSpace.resetObject(int, java.lang.Object) can be used to avoid additional calls to ObjectSpace.setObject(int, java.lang.Object).

Specified by:
resetObject in interface ObjectSpace

getObject

public java.lang.Object getObject(int id)
Description copied from interface: ObjectSpace
Finds the object for a given identifier.

Specified by:
getObject in interface ObjectSpace
Returns:
the object passed to the ObjectSpace.getID(java.lang.Object) call that returned the given identifier.

getID

public int getID(java.lang.Object obj)
Description copied from interface: ObjectSpace
Returns the identifier for a given object. If the object was presented to the ObjectSpace the first time, the #isNew method returns true for the resulting identifier.

Specified by:
getID in interface ObjectSpace

findID

public int findID(java.lang.Object obj)
Description copied from interface: ObjectSpace
Same as ObjectSpace.getID(java.lang.Object), but does not assign the object to this object space, if the object was not yet a member.

Specified by:
findID in interface ObjectSpace

isUsed

public boolean isUsed(int id)
Description copied from interface: ObjectSpace
Checks whether this object space has an object assigned to the given identifier. This is most useful, for traversing a non-contiguous identifier space. ObjectSpace.isUsed(int) returns true for identifier returned from ObjectSpace.getID(java.lang.Object).

Specified by:
isUsed in interface ObjectSpace

isShared

public boolean isShared(int id)
Specified by:
isShared in interface ObjectSpace
Returns:
whether the object that corresponds to the given identifier is a shared object.

isAccepted

public boolean isAccepted(int id)
Description copied from interface: ObjectSpace
Decides whether an object reference should be blocked during transmission through a MarshalStream/UnmarshalStream pair. If a call to ObjectSpace.isAccepted(int) on the ObjectSpace of the sender-side stream returns false for an object identifier, a reference to the corresponding object is blocked (replaced with null).

Specified by:
isAccepted in interface ObjectSpace
Returns:
whether references to the corresponding object should be marshaled or blocked.

remove

public void remove(int id)
Description copied from interface: ObjectSpace
Removes the given identifer from this object space. This operation removes the complete binding of the corresponding object to its identifier from this object space. A future call to ObjectSpace.getID(java.lang.Object) with the object corresponding to the given identifier as argument will result in a new identifier.

Specified by:
remove in interface ObjectSpace

clear

public void clear()
Description copied from interface: ObjectSpace
Clears the object space by removing all identifier assignments.

Specified by:
clear in interface ObjectSpace

appendTo

public void appendTo(ToString s)
Description copied from interface: Printable
This method should append the contents of each instance variable of the current object to the given ToString object. The appended data should be labeled with the name of the corresponding instance variable.

Specified by:
appendTo in interface Printable
See Also:
ToString, ToString.append(String, Object), ToString.append(String, boolean), ToString.append(String, byte), ToString.append(String, int)