Changed DSet.Element to DSet.Entry in preparation for the addition of
array element update support. (Arrays have elements, sets have entries.) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1133 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
+10
-10
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# $Id: gendobj,v 1.9 2002/03/08 01:05:39 mdb Exp $
|
||||
# $Id: gendobj,v 1.10 2002/03/18 23:21:25 mdb Exp $
|
||||
#
|
||||
# gendobj is used to generate DObject source file definitons basded on
|
||||
# abbreviated declarations. Because DObject fields all have standard
|
||||
@@ -183,39 +183,39 @@ sub print_dobj_setters
|
||||
print OUT <<EOF;
|
||||
|
||||
/**
|
||||
* Requests that the specified element be added to the
|
||||
* Requests that the specified entry be added to the
|
||||
* <code>$field</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void addTo$cfield (DSet.Element elem)
|
||||
public void addTo$cfield (DSet.Entry elem)
|
||||
{
|
||||
requestElementAdd($fcode, elem);
|
||||
requestEntryAdd($fcode, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the element matching the supplied key be removed from
|
||||
* Requests that the entry matching the supplied key be removed from
|
||||
* the <code>$field</code> set. The set will not change until the
|
||||
* event is actually propagated through the system.
|
||||
*/
|
||||
public void removeFrom$cfield (Object key)
|
||||
{
|
||||
requestElementRemove($fcode, key);
|
||||
requestEntryRemove($fcode, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be updated in the
|
||||
* Requests that the specified entry be updated in the
|
||||
* <code>$field</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void update$cfield (DSet.Element elem)
|
||||
public void update$cfield (DSet.Entry elem)
|
||||
{
|
||||
requestElementUpdate($fcode, elem);
|
||||
requestEntryUpdate($fcode, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>$field</code> field be set to the
|
||||
* specified value. Generally one only adds, updates and removes
|
||||
* elements of a distributed set, but certain situations call for a
|
||||
* entries of a distributed set, but certain situations call for a
|
||||
* complete replacement of the set value. The local value will be
|
||||
* updated immediately and an event will be propagated through the
|
||||
* system to notify all listeners that the attribute did
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: OccupantManager.java,v 1.10 2001/12/20 02:48:21 mdb Exp $
|
||||
// $Id: OccupantManager.java,v 1.11 2002/03/18 23:21:25 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class OccupantManager
|
||||
return null;
|
||||
}
|
||||
|
||||
Iterator iter = _place.occupantInfo.elements();
|
||||
Iterator iter = _place.occupantInfo.entries();
|
||||
while (iter.hasNext()) {
|
||||
OccupantInfo info = (OccupantInfo)iter.next();
|
||||
if (info.username.equals(username)) {
|
||||
@@ -121,7 +121,7 @@ public class OccupantManager
|
||||
_place.addListener(this);
|
||||
|
||||
// cache the occupant info for the occupants in this room
|
||||
Iterator iter = _place.occupantInfo.elements();
|
||||
Iterator iter = _place.occupantInfo.entries();
|
||||
while (iter.hasNext()) {
|
||||
OccupantInfo info = (OccupantInfo)iter.next();
|
||||
_ocache.put(info.getBodyOid(), info);
|
||||
@@ -137,7 +137,7 @@ public class OccupantManager
|
||||
/**
|
||||
* Deals with all of the processing when an occupant shows up.
|
||||
*/
|
||||
public void elementAdded (ElementAddedEvent event)
|
||||
public void entryAdded (EntryAddedEvent event)
|
||||
{
|
||||
// bail if this isn't for the OCCUPANT_INFO field
|
||||
if (!event.getName().equals(PlaceObject.OCCUPANT_INFO)) {
|
||||
@@ -145,7 +145,7 @@ public class OccupantManager
|
||||
}
|
||||
|
||||
// put the info in our cache for use when we get a left event
|
||||
OccupantInfo info = (OccupantInfo)event.getElement();
|
||||
OccupantInfo info = (OccupantInfo)event.getEntry();
|
||||
int bodyOid = info.getBodyOid();
|
||||
_ocache.put(bodyOid, info);
|
||||
|
||||
@@ -159,7 +159,7 @@ public class OccupantManager
|
||||
/**
|
||||
* Deals with all of the processing when an occupant is updated.
|
||||
*/
|
||||
public void elementUpdated (ElementUpdatedEvent event)
|
||||
public void entryUpdated (EntryUpdatedEvent event)
|
||||
{
|
||||
// bail if this isn't for the OCCUPANT_INFO field
|
||||
if (!event.getName().equals(PlaceObject.OCCUPANT_INFO)) {
|
||||
@@ -167,7 +167,7 @@ public class OccupantManager
|
||||
}
|
||||
|
||||
// update our cache
|
||||
OccupantInfo info = (OccupantInfo)event.getElement();
|
||||
OccupantInfo info = (OccupantInfo)event.getEntry();
|
||||
int bodyOid = info.getBodyOid();
|
||||
_ocache.put(bodyOid, info);
|
||||
|
||||
@@ -181,7 +181,7 @@ public class OccupantManager
|
||||
/**
|
||||
* Deals with all of the processing when an occupant leaves.
|
||||
*/
|
||||
public void elementRemoved (ElementRemovedEvent event)
|
||||
public void entryRemoved (EntryRemovedEvent event)
|
||||
{
|
||||
// bail if this isn't for the OCCUPANT_INFO field
|
||||
if (!event.getName().equals(PlaceObject.OCCUPANT_INFO)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: OccupantInfo.java,v 1.5 2001/12/15 04:20:00 mdb Exp $
|
||||
// $Id: OccupantInfo.java,v 1.6 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.data;
|
||||
|
||||
@@ -28,9 +28,9 @@ import com.threerings.presents.dobj.DSet;
|
||||
* is requested.
|
||||
*/
|
||||
public class OccupantInfo
|
||||
implements DSet.Element, Cloneable
|
||||
implements DSet.Entry, Cloneable
|
||||
{
|
||||
/** The body object id of this occupant (and our element key). */
|
||||
/** The body object id of this occupant (and our entry key). */
|
||||
public Integer bodyOid;
|
||||
|
||||
/** The username of this occupant. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlaceObject.java,v 1.4 2002/03/08 01:06:12 mdb Exp $
|
||||
// $Id: PlaceObject.java,v 1.5 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.data;
|
||||
|
||||
@@ -47,39 +47,39 @@ public class PlaceObject extends DObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be added to the
|
||||
* Requests that the specified entry be added to the
|
||||
* <code>occupantInfo</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void addToOccupantInfo (DSet.Element elem)
|
||||
public void addToOccupantInfo (DSet.Entry elem)
|
||||
{
|
||||
requestElementAdd(OCCUPANT_INFO, elem);
|
||||
requestEntryAdd(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the element matching the supplied key be removed from
|
||||
* Requests that the entry matching the supplied key be removed from
|
||||
* the <code>occupantInfo</code> set. The set will not change until the
|
||||
* event is actually propagated through the system.
|
||||
*/
|
||||
public void removeFromOccupantInfo (Object key)
|
||||
{
|
||||
requestElementRemove(OCCUPANT_INFO, key);
|
||||
requestEntryRemove(OCCUPANT_INFO, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be updated in the
|
||||
* Requests that the specified entry be updated in the
|
||||
* <code>occupantInfo</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void updateOccupantInfo (DSet.Element elem)
|
||||
public void updateOccupantInfo (DSet.Entry elem)
|
||||
{
|
||||
requestElementUpdate(OCCUPANT_INFO, elem);
|
||||
requestEntryUpdate(OCCUPANT_INFO, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>occupantInfo</code> field be set to the
|
||||
* specified value. Generally one only adds, updates and removes
|
||||
* elements of a distributed set, but certain situations call for a
|
||||
* entries of a distributed set, but certain situations call for a
|
||||
* complete replacement of the set value. The local value will be
|
||||
* updated immediately and an event will be propagated through the
|
||||
* system to notify all listeners that the attribute did
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlaceManager.java,v 1.27 2002/02/14 18:08:53 mdb Exp $
|
||||
// $Id: PlaceManager.java,v 1.28 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
@@ -136,7 +136,7 @@ public class PlaceManager
|
||||
_plobj = plobj;
|
||||
|
||||
// configure the occupant info set
|
||||
plobj.occupantInfo.setElementType(getOccupantInfoClass());
|
||||
plobj.occupantInfo.setEntryType(getOccupantInfoClass());
|
||||
|
||||
// we'll need to hear about place object events
|
||||
plobj.addListener(this);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: OccupantList.java,v 1.4 2001/12/20 01:10:52 shaper Exp $
|
||||
// $Id: OccupantList.java,v 1.5 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.client;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class OccupantList
|
||||
public void willEnterPlace (PlaceObject plobj)
|
||||
{
|
||||
// add all of the occupants of the place to our list
|
||||
Iterator users = plobj.occupantInfo.elements();
|
||||
Iterator users = plobj.occupantInfo.entries();
|
||||
while (users.hasNext()) {
|
||||
OccupantInfo info = (OccupantInfo)users.next();
|
||||
_model.addElement(info.username);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TableListView.java,v 1.3 2002/02/08 23:55:24 mdb Exp $
|
||||
// $Id: TableListView.java,v 1.4 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.lobby.table;
|
||||
|
||||
@@ -132,7 +132,7 @@ public class TableListView
|
||||
// iterate over the tables already active in this lobby and put
|
||||
// them in their respective lists
|
||||
TableLobbyObject tlobj = (TableLobbyObject)place;
|
||||
Iterator iter = tlobj.tableSet.elements();
|
||||
Iterator iter = tlobj.tableSet.entries();
|
||||
while (iter.hasNext()) {
|
||||
tableAdded((Table)iter.next());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TableLobbyObject.java,v 1.3 2002/03/08 01:06:12 mdb Exp $
|
||||
// $Id: TableLobbyObject.java,v 1.4 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.lobby.table;
|
||||
|
||||
@@ -42,39 +42,39 @@ public class TableLobbyObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be added to the
|
||||
* Requests that the specified entry be added to the
|
||||
* <code>tableSet</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void addToTableSet (DSet.Element elem)
|
||||
public void addToTableSet (DSet.Entry elem)
|
||||
{
|
||||
requestElementAdd(TABLE_SET, elem);
|
||||
requestEntryAdd(TABLE_SET, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the element matching the supplied key be removed from
|
||||
* Requests that the entry matching the supplied key be removed from
|
||||
* the <code>tableSet</code> set. The set will not change until the
|
||||
* event is actually propagated through the system.
|
||||
*/
|
||||
public void removeFromTableSet (Object key)
|
||||
{
|
||||
requestElementRemove(TABLE_SET, key);
|
||||
requestEntryRemove(TABLE_SET, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified element be updated in the
|
||||
* Requests that the specified entry be updated in the
|
||||
* <code>tableSet</code> set. The set will not change until the event is
|
||||
* actually propagated through the system.
|
||||
*/
|
||||
public void updateTableSet (DSet.Element elem)
|
||||
public void updateTableSet (DSet.Entry elem)
|
||||
{
|
||||
requestElementUpdate(TABLE_SET, elem);
|
||||
requestEntryUpdate(TABLE_SET, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>tableSet</code> field be set to the
|
||||
* specified value. Generally one only adds, updates and removes
|
||||
* elements of a distributed set, but certain situations call for a
|
||||
* entries of a distributed set, but certain situations call for a
|
||||
* complete replacement of the set value. The local value will be
|
||||
* updated immediately and an event will be propagated through the
|
||||
* system to notify all listeners that the attribute did
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// $Id: TableDirector.java,v 1.5 2001/10/23 23:52:01 mdb Exp $
|
||||
// $Id: TableDirector.java,v 1.6 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.dobj.ElementAddedEvent;
|
||||
import com.threerings.presents.dobj.ElementUpdatedEvent;
|
||||
import com.threerings.presents.dobj.ElementRemovedEvent;
|
||||
import com.threerings.presents.dobj.EntryAddedEvent;
|
||||
import com.threerings.presents.dobj.EntryUpdatedEvent;
|
||||
import com.threerings.presents.dobj.EntryRemovedEvent;
|
||||
import com.threerings.presents.dobj.SetListener;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
@@ -190,10 +190,10 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementAdded (ElementAddedEvent event)
|
||||
public void entryAdded (EntryAddedEvent event)
|
||||
{
|
||||
if (event.getName().equals(_tableField)) {
|
||||
Table table = (Table)event.getElement();
|
||||
Table table = (Table)event.getEntry();
|
||||
|
||||
// check to see if we just joined a table
|
||||
checkSeatedness(table);
|
||||
@@ -204,10 +204,10 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementUpdated (ElementUpdatedEvent event)
|
||||
public void entryUpdated (EntryUpdatedEvent event)
|
||||
{
|
||||
if (event.getName().equals(_tableField)) {
|
||||
Table table = (Table)event.getElement();
|
||||
Table table = (Table)event.getEntry();
|
||||
|
||||
// check to see if we just joined or left a table
|
||||
checkSeatedness(table);
|
||||
@@ -218,7 +218,7 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void elementRemoved (ElementRemovedEvent event)
|
||||
public void entryRemoved (EntryRemovedEvent event)
|
||||
{
|
||||
if (event.getName().equals(_tableField)) {
|
||||
Integer tableId = (Integer)event.getKey();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Table.java,v 1.7 2002/02/01 23:32:37 mdb Exp $
|
||||
// $Id: Table.java,v 1.8 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.data;
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.threerings.parlor.game.GameConfig;
|
||||
* the Parlor services.
|
||||
*/
|
||||
public class Table
|
||||
implements DSet.Element, ParlorCodes
|
||||
implements DSet.Entry, ParlorCodes
|
||||
{
|
||||
/** The unique identifier for this table. */
|
||||
public Integer tableId;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DObject.java,v 1.39 2002/02/09 07:50:37 mdb Exp $
|
||||
// $Id: DObject.java,v 1.40 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -579,43 +579,43 @@ public class DObject
|
||||
/**
|
||||
* Calls by derived instances when a set adder method was called.
|
||||
*/
|
||||
protected void requestElementAdd (String name, DSet.Element elem)
|
||||
protected void requestEntryAdd (String name, DSet.Entry entry)
|
||||
{
|
||||
try {
|
||||
DSet set = (DSet)getAttribute(name);
|
||||
// dispatch an element added event
|
||||
postEvent(new ElementAddedEvent(
|
||||
_oid, name, elem, !set.homogenous()));
|
||||
// dispatch an entry added event
|
||||
postEvent(new EntryAddedEvent(
|
||||
_oid, name, entry, !set.homogenous()));
|
||||
|
||||
} catch (ObjectAccessException oae) {
|
||||
Log.warning("Unable to request elementAdd [name=" + name +
|
||||
", elem=" + elem + ", error=" + oae + "].");
|
||||
Log.warning("Unable to request entryAdd [name=" + name +
|
||||
", entry=" + entry + ", error=" + oae + "].");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls by derived instances when a set remover method was called.
|
||||
*/
|
||||
protected void requestElementRemove (String name, Object key)
|
||||
protected void requestEntryRemove (String name, Object key)
|
||||
{
|
||||
// dispatch an element removed event
|
||||
postEvent(new ElementRemovedEvent(_oid, name, key));
|
||||
// dispatch an entry removed event
|
||||
postEvent(new EntryRemovedEvent(_oid, name, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls by derived instances when a set updater method was called.
|
||||
*/
|
||||
protected void requestElementUpdate (String name, DSet.Element elem)
|
||||
protected void requestEntryUpdate (String name, DSet.Entry entry)
|
||||
{
|
||||
try {
|
||||
DSet set = (DSet)getAttribute(name);
|
||||
// dispatch an element updated event
|
||||
postEvent(new ElementUpdatedEvent(
|
||||
_oid, name, elem, !set.homogenous()));
|
||||
// dispatch an entry updated event
|
||||
postEvent(new EntryUpdatedEvent(
|
||||
_oid, name, entry, !set.homogenous()));
|
||||
|
||||
} catch (ObjectAccessException oae) {
|
||||
Log.warning("Unable to request elementUpdate [name=" + name +
|
||||
", elem=" + elem + ", error=" + oae + "].");
|
||||
Log.warning("Unable to request entryUpdate [name=" + name +
|
||||
", entry=" + entry + ", error=" + oae + "].");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DSet.java,v 1.15 2002/02/08 05:14:22 mdb Exp $
|
||||
// $Id: DSet.java,v 1.16 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -15,81 +15,81 @@ import com.threerings.presents.io.Streamable;
|
||||
|
||||
/**
|
||||
* The distributed set class provides a means by which an unordered set of
|
||||
* objects can be maintained as a distributed object field. Elements can
|
||||
* be added to and removed from the set, requests for which will generate
|
||||
* objects can be maintained as a distributed object field. Entries can be
|
||||
* added to and removed from the set, requests for which will generate
|
||||
* events much like other distributed object fields.
|
||||
*
|
||||
* <p> A set can be either homogenous, whereby the type of object to be
|
||||
* contained in the set is configured before the set is used and does not
|
||||
* change; or heterogenous, whereby a set can contain any type of element
|
||||
* as long as it implements {@link Element}. Homogenous sets take
|
||||
* advantage of their homogeneity by not transfering the classname of each
|
||||
* element as it is sent over the wire.
|
||||
* change; or heterogenous, whereby a set can contain any type of entry as
|
||||
* long as it implements {@link Entry}. Homogenous sets take advantage of
|
||||
* their homogeneity by not transfering the classname of each entry as it
|
||||
* is sent over the wire.
|
||||
*
|
||||
* <p> Classes that wish to act as set elements must implement the {@link
|
||||
* com.threerings.presents.dobj.DSet.Element} interface which extends
|
||||
* {@link Streamable} and adds the requirement that the object provide a
|
||||
* key which will be used to identify element equality. Thus an element is
|
||||
* declared to be in a set of the object returned by that element's
|
||||
* <code>geyKey()</code> method is equal (using <code>equal()</code>) to
|
||||
* the element returned by the <code>getKey()</code> method of some other
|
||||
* element in the set. Additionally, in the case of element removal, only
|
||||
* the key for the element to be removed will be transmitted with the
|
||||
* removal event to save network bandwidth. Lastly, the object returned by
|
||||
* <code>getKey()</code> must be a valid distributed object type.
|
||||
* <p> Classes that wish to act as set entries must implement the {@link
|
||||
* Entry} interface which extends {@link Streamable} and adds the
|
||||
* requirement that the object provide a key which will be used to
|
||||
* identify entry equality. Thus an entry is declared to be in a set of
|
||||
* the object returned by that entry's <code>geyKey()</code> method is
|
||||
* equal (using <code>equal()</code>) to the entry returned by the
|
||||
* <code>getKey()</code> method of some other entry in the set.
|
||||
* Additionally, in the case of entry removal, only the key for the entry
|
||||
* to be removed will be transmitted with the removal event to save
|
||||
* network bandwidth. Lastly, the object returned by <code>getKey()</code>
|
||||
* must be a valid distributed object type.
|
||||
*/
|
||||
public class DSet
|
||||
implements Streamable, Cloneable
|
||||
{
|
||||
/**
|
||||
* Elements of the set must implement this interface.
|
||||
* Entries of the set must implement this interface.
|
||||
*/
|
||||
public static interface Element extends Streamable
|
||||
public static interface Entry extends Streamable
|
||||
{
|
||||
/**
|
||||
* Each element provide an associated key which is used to
|
||||
* determine its uniqueness in the set. See the {@link DSet} class
|
||||
* Each entry provide an associated key which is used to determine
|
||||
* its uniqueness in the set. See the {@link DSet} class
|
||||
* documentation for further information.
|
||||
*/
|
||||
public Object getKey ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a distributed set that will contain the specified
|
||||
* element type.
|
||||
* Constructs a distributed set that will contain the specified entry
|
||||
* type.
|
||||
*/
|
||||
public DSet (Class elementType)
|
||||
public DSet (Class entryType)
|
||||
{
|
||||
setElementType(elementType);
|
||||
setEntryType(entryType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a distributed set and populates it with values from the
|
||||
* supplied iterator. This should be done before the set is unleashed
|
||||
* into the wild distributed object world because no associated
|
||||
* element added events will be generated. Additionally, this
|
||||
* operation does not check for duplicates when adding elements, so
|
||||
* one should be sure that the iterator contains only unique elements.
|
||||
* into the wild distributed object world because no associated entry
|
||||
* added events will be generated. Additionally, this operation does
|
||||
* not check for duplicates when adding entries, so one should be sure
|
||||
* that the iterator contains only unique entries.
|
||||
*
|
||||
* @param elementType the type of elements that will be stored in this
|
||||
* set. <em>Only</em> elements of this <em>exact</em> type may be
|
||||
* @param entryType the type of entries that will be stored in this
|
||||
* set. <em>Only</em> entries of this <em>exact</em> type may be
|
||||
* stored in the set.
|
||||
* @param source an iterator from which we will initially populate the
|
||||
* set.
|
||||
*/
|
||||
public DSet (Class elementType, Iterator source)
|
||||
public DSet (Class entryType, Iterator source)
|
||||
{
|
||||
this(source);
|
||||
setElementType(elementType);
|
||||
setEntryType(entryType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a distributed set and populates it with values from the
|
||||
* supplied iterator. This should be done before the set is unleashed
|
||||
* into the wild distributed object world because no associated
|
||||
* element added events will be generated. Additionally, this
|
||||
* operation does not check for duplicates when adding elements, so
|
||||
* one should be sure that the iterator contains only unique elements.
|
||||
* into the wild distributed object world because no associated entry
|
||||
* added events will be generated. Additionally, this operation does
|
||||
* not check for duplicates when adding entries, so one should be sure
|
||||
* that the iterator contains only unique entries.
|
||||
*
|
||||
* @param source an iterator from which we will initially populate the
|
||||
* set.
|
||||
@@ -97,56 +97,55 @@ public class DSet
|
||||
public DSet (Iterator source)
|
||||
{
|
||||
for (int index = 0; source.hasNext(); index++) {
|
||||
Element elem = (Element)source.next();
|
||||
Entry elem = (Entry)source.next();
|
||||
|
||||
// expand the array if necessary
|
||||
if (index >= _elements.length) {
|
||||
if (index >= _entries.length) {
|
||||
expand(index);
|
||||
}
|
||||
|
||||
// insert the item
|
||||
_elements[index] = elem;
|
||||
_entries[index] = elem;
|
||||
_size++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a distributed set without specifying the element
|
||||
* type. The set will assume that it is heterogenous, unless a
|
||||
* homogenous class type is otherwise specified via {@link
|
||||
* #setElementType}.
|
||||
* Constructs a distributed set without specifying the entry type. The
|
||||
* set will assume that it is heterogenous, unless a homogenous class
|
||||
* type is otherwise specified via {@link #setEntryType}.
|
||||
*/
|
||||
public DSet ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this set contains only elements of exactly the same
|
||||
* Returns true if this set contains only entries of exactly the same
|
||||
* type, false if not.
|
||||
*/
|
||||
public boolean homogenous ()
|
||||
{
|
||||
return _elementType != null;
|
||||
return _entryType != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates what type of elements will be stored in this set. This
|
||||
* can be called multiple times before the set is used (in the event
|
||||
* that one wishes to further specialize the contents of a set that
|
||||
* has already been configured to use a particular element type), but
|
||||
* once the set goes into use, it must not be changed. Also bear in
|
||||
* mind that the class of elements added to the set are not checked at
|
||||
* runtime, and adding elements of invalid class will simply result in
|
||||
* Indicates what type of entries will be stored in this set. This can
|
||||
* be called multiple times before the set is used (in the event that
|
||||
* one wishes to further specialize the contents of a set that has
|
||||
* already been configured to use a particular entry type), but once
|
||||
* the set goes into use, it must not be changed. Also bear in mind
|
||||
* that the class of entries added to the set are not checked at
|
||||
* runtime, and adding entries of invalid class will simply result in
|
||||
* the serialization mechanism failing when an event is dispatched to
|
||||
* broadcast the addition of an element.
|
||||
* broadcast the addition of an entry.
|
||||
*/
|
||||
public void setElementType (Class elementType)
|
||||
public void setEntryType (Class entryType)
|
||||
{
|
||||
_elementType = elementType;
|
||||
_entryType = entryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this set.
|
||||
* Returns the number of entries in this set.
|
||||
*/
|
||||
public int size ()
|
||||
{
|
||||
@@ -154,18 +153,18 @@ public class DSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the set contains an element whose
|
||||
* Returns true if the set contains an entry whose
|
||||
* <code>getKey()</code> method returns a key that
|
||||
* <code>equals()</code> the key returned by <code>getKey()</code> of
|
||||
* the supplied element. Returns false otherwise.
|
||||
* the supplied entry. Returns false otherwise.
|
||||
*/
|
||||
public boolean contains (Element elem)
|
||||
public boolean contains (Entry elem)
|
||||
{
|
||||
return containsKey(elem.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an element in the set has a key that
|
||||
* Returns true if an entry in the set has a key that
|
||||
* <code>equals()</code> the supplied key. Returns false otherwise.
|
||||
*/
|
||||
public boolean containsKey (Object key)
|
||||
@@ -174,18 +173,18 @@ public class DSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element that matches
|
||||
* (<code>getKey().equals(key)</code>) the specified key or null if no
|
||||
* element could be found that matches the key.
|
||||
* Returns the entry that matches (<code>getKey().equals(key)</code>)
|
||||
* the specified key or null if no entry could be found that matches
|
||||
* the key.
|
||||
*/
|
||||
public Element get (Object key)
|
||||
public Entry get (Object key)
|
||||
{
|
||||
// scan the array looking for a matching element
|
||||
int elength = _elements.length;
|
||||
// scan the array looking for a matching entry
|
||||
int elength = _entries.length;
|
||||
for (int i = 0; i < elength; i++) {
|
||||
// the array may be sparse
|
||||
if (_elements[i] != null) {
|
||||
Element elem = _elements[i];
|
||||
if (_entries[i] != null) {
|
||||
Entry elem = _entries[i];
|
||||
if (elem.getKey().equals(key)) {
|
||||
return elem;
|
||||
}
|
||||
@@ -195,26 +194,26 @@ public class DSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the elements of this set. It does not
|
||||
* Returns an iterator over the entries of this set. It does not
|
||||
* support modification (nor iteration while modifications are being
|
||||
* made to the set). It should not be kept around as it can quickly
|
||||
* become out of date.
|
||||
*/
|
||||
public Iterator elements ()
|
||||
public Iterator entries ()
|
||||
{
|
||||
return new Iterator() {
|
||||
public boolean hasNext ()
|
||||
{
|
||||
// we need to scan to the next element the first time
|
||||
// we need to scan to the next entry the first time
|
||||
if (_index < 0) {
|
||||
scanToNext();
|
||||
}
|
||||
return (_index < _elements.length);
|
||||
return (_index < _entries.length);
|
||||
}
|
||||
|
||||
public Object next ()
|
||||
{
|
||||
Object val = _elements[_index];
|
||||
Object val = _entries[_index];
|
||||
scanToNext();
|
||||
return val;
|
||||
}
|
||||
@@ -226,8 +225,8 @@ public class DSet
|
||||
|
||||
protected void scanToNext ()
|
||||
{
|
||||
for (_index++; _index < _elements.length; _index++) {
|
||||
if (_elements[_index] != null) {
|
||||
for (_index++; _index < _entries.length; _index++) {
|
||||
if (_entries[_index] != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -238,24 +237,24 @@ public class DSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified element to the set. This should not be called
|
||||
* Adds the specified entry to the set. This should not be called
|
||||
* directly, instead the associated <code>addTo{Set}()</code> method
|
||||
* should be called on the distributed object that contains the set in
|
||||
* question.
|
||||
*
|
||||
* @return true if the element was added, false if it was already in
|
||||
* @return true if the entry was added, false if it was already in
|
||||
* the set.
|
||||
*/
|
||||
protected boolean add (Element elem)
|
||||
protected boolean add (Entry elem)
|
||||
{
|
||||
Object key = elem.getKey();
|
||||
int elength = _elements.length;
|
||||
int elength = _entries.length;
|
||||
int index = elength;
|
||||
|
||||
// scan the array looking for a slot and/or the element already in
|
||||
// scan the array looking for a slot and/or the entry already in
|
||||
// the set
|
||||
for (int i = 0; i < elength; i++) {
|
||||
Element el = _elements[i];
|
||||
Entry el = _entries[i];
|
||||
// the array may be sparse
|
||||
if (el == null) {
|
||||
if (index == elength) {
|
||||
@@ -267,47 +266,47 @@ public class DSet
|
||||
}
|
||||
|
||||
// expand the array if necessary
|
||||
if (index >= _elements.length) {
|
||||
if (index >= _entries.length) {
|
||||
expand(index);
|
||||
}
|
||||
|
||||
// insert the item
|
||||
_elements[index] = elem;
|
||||
_entries[index] = elem;
|
||||
_size++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified element from the set. This should not be
|
||||
* called directly, instead the associated
|
||||
* <code>removeFrom{Set}()</code> method should be called on the
|
||||
* distributed object that contains the set in question.
|
||||
* Removes the specified entry from the set. This should not be called
|
||||
* directly, instead the associated <code>removeFrom{Set}()</code>
|
||||
* method should be called on the distributed object that contains the
|
||||
* set in question.
|
||||
*
|
||||
* @return true if the element was removed, false if it was not in the
|
||||
* @return true if the entry was removed, false if it was not in the
|
||||
* set.
|
||||
*/
|
||||
protected boolean remove (Element elem)
|
||||
protected boolean remove (Entry elem)
|
||||
{
|
||||
return removeKey(elem.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes from the set the element whose key matches the supplied
|
||||
* Removes from the set the entry whose key matches the supplied
|
||||
* key. This should not be called directly, instead the associated
|
||||
* <code>removeFrom{Set}()</code> method should be called on the
|
||||
* distributed object that contains the set in question.
|
||||
*
|
||||
* @return true if a matching element was removed, false if no element
|
||||
* @return true if a matching entry was removed, false if no entry
|
||||
* in the set matched the key.
|
||||
*/
|
||||
protected boolean removeKey (Object key)
|
||||
{
|
||||
// scan the array looking for a matching element
|
||||
int elength = _elements.length;
|
||||
// scan the array looking for a matching entry
|
||||
int elength = _entries.length;
|
||||
for (int i = 0; i < elength; i++) {
|
||||
Element el = _elements[i];
|
||||
Entry el = _entries[i];
|
||||
if (el != null && el.getKey().equals(key)) {
|
||||
_elements[i] = null;
|
||||
_entries[i] = null;
|
||||
_size--;
|
||||
return true;
|
||||
}
|
||||
@@ -316,25 +315,25 @@ public class DSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the specified element by locating an element whose key
|
||||
* matches the key of the supplied element and overwriting it. This
|
||||
* should not be called directly, instead the associated
|
||||
* Updates the specified entry by locating an entry whose key matches
|
||||
* the key of the supplied entry and overwriting it. This should not
|
||||
* be called directly, instead the associated
|
||||
* <code>update{Set}()</code> method should be called on the
|
||||
* distributed object that contains the set in question.
|
||||
*
|
||||
* @return true if the element was updated, false if it was not
|
||||
* @return true if the entry was updated, false if it was not
|
||||
* already in the set (in which case nothing is updated).
|
||||
*/
|
||||
protected boolean update (Element elem)
|
||||
protected boolean update (Entry elem)
|
||||
{
|
||||
Object key = elem.getKey();
|
||||
|
||||
// scan the array looking for a matching element
|
||||
int elength = _elements.length;
|
||||
// scan the array looking for a matching entry
|
||||
int elength = _entries.length;
|
||||
for (int i = 0; i < elength; i++) {
|
||||
Element el = _elements[i];
|
||||
Entry el = _entries[i];
|
||||
if (el != null && el.getKey().equals(key)) {
|
||||
_elements[i] = elem;
|
||||
_entries[i] = elem;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -348,17 +347,17 @@ public class DSet
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
if (_elementType == null) {
|
||||
if (_entryType == null) {
|
||||
out.writeUTF("");
|
||||
} else {
|
||||
out.writeUTF(_elementType.getName());
|
||||
out.writeUTF(_entryType.getName());
|
||||
}
|
||||
out.writeInt(_size);
|
||||
int elength = _elements.length;
|
||||
int elength = _entries.length;
|
||||
for (int i = 0; i < elength; i++) {
|
||||
Element elem = _elements[i];
|
||||
Entry elem = _entries[i];
|
||||
if (elem != null) {
|
||||
if (_elementType == null) {
|
||||
if (_entryType == null) {
|
||||
out.writeUTF(elem.getClass().getName());
|
||||
}
|
||||
elem.writeTo(out);
|
||||
@@ -372,45 +371,45 @@ public class DSet
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
// read our element class and forName() it (if we read an element
|
||||
// read our entry class and forName() it (if we read an entry
|
||||
// class, we're a homogenous set; otherwise we're heterogenous)
|
||||
String eclass = in.readUTF();
|
||||
try {
|
||||
if (!StringUtil.blank(eclass)) {
|
||||
_elementType = Class.forName(eclass);
|
||||
_entryType = Class.forName(eclass);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
String err = "Unable to instantiate element class [err=" + e + "]";
|
||||
String err = "Unable to instantiate entry class [err=" + e + "]";
|
||||
throw new IOException(err);
|
||||
}
|
||||
|
||||
// find out how many elements we'll be reading
|
||||
// find out how many entries we'll be reading
|
||||
_size = in.readInt();
|
||||
|
||||
// make sure we can fit _size elements
|
||||
// make sure we can fit _size entries
|
||||
expand(_size);
|
||||
|
||||
for (int i = 0; i < _size; i++) {
|
||||
_elements[i] = readElement(in);
|
||||
_entries[i] = readEntry(in);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an element from the wire and unserializes it. Takes into
|
||||
* Reads an entry from the wire and unserializes it. Takes into
|
||||
* account whether or not we're a homogenous set.
|
||||
*/
|
||||
public Element readElement (DataInputStream in)
|
||||
public Entry readEntry (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
Element elem = null;
|
||||
Entry elem = null;
|
||||
|
||||
// instantiate the appropriate element instance
|
||||
if (_elementType != null) {
|
||||
elem = (Element)_elementType.newInstance();
|
||||
// instantiate the appropriate entry instance
|
||||
if (_entryType != null) {
|
||||
elem = (Entry)_entryType.newInstance();
|
||||
} else {
|
||||
elem = (Element)Class.forName(in.readUTF()).newInstance();
|
||||
elem = (Entry)Class.forName(in.readUTF()).newInstance();
|
||||
}
|
||||
|
||||
// unserialize it and return it
|
||||
@@ -418,7 +417,7 @@ public class DSet
|
||||
return elem;
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to unserialize set element " +
|
||||
Log.warning("Unable to unserialize set entry " +
|
||||
"[set=" + this + "].");
|
||||
Log.logStackTrace(e);
|
||||
return null;
|
||||
@@ -430,9 +429,9 @@ public class DSet
|
||||
*/
|
||||
public Object clone ()
|
||||
{
|
||||
DSet nset = new DSet(_elementType);
|
||||
nset._elements = new Element[_elements.length];
|
||||
System.arraycopy(_elements, 0, nset._elements, 0, _elements.length);
|
||||
DSet nset = new DSet(_entryType);
|
||||
nset._entries = new Entry[_entries.length];
|
||||
System.arraycopy(_entries, 0, nset._entries, 0, _entries.length);
|
||||
nset._size = _size;
|
||||
return nset;
|
||||
}
|
||||
@@ -443,15 +442,15 @@ public class DSet
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer("[");
|
||||
if (_elementType == null) {
|
||||
if (_entryType == null) {
|
||||
buf.append("etype=NONE");
|
||||
} else {
|
||||
buf.append("etype=").append(_elementType.getName());
|
||||
buf.append("etype=").append(_entryType.getName());
|
||||
}
|
||||
buf.append(", elems=(");
|
||||
String prefix = "";
|
||||
for (int i = 0; i < _elements.length; i++) {
|
||||
Element elem = _elements[i];
|
||||
for (int i = 0; i < _entries.length; i++) {
|
||||
Entry elem = _entries[i];
|
||||
if (elem != null) {
|
||||
buf.append(prefix);
|
||||
prefix = ", ";
|
||||
@@ -473,7 +472,7 @@ public class DSet
|
||||
}
|
||||
|
||||
// increase our length in powers of two until we're big enough
|
||||
int tlength = _elements.length;
|
||||
int tlength = _entries.length;
|
||||
while (index >= tlength) {
|
||||
tlength *= 2;
|
||||
}
|
||||
@@ -486,18 +485,18 @@ public class DSet
|
||||
}
|
||||
|
||||
// create a new array and copy our data into it
|
||||
Element[] elems = new Element[tlength];
|
||||
System.arraycopy(_elements, 0, elems, 0, _elements.length);
|
||||
_elements = elems;
|
||||
Entry[] elems = new Entry[tlength];
|
||||
System.arraycopy(_entries, 0, elems, 0, _entries.length);
|
||||
_entries = elems;
|
||||
}
|
||||
|
||||
/** The type of element this set holds. */
|
||||
protected Class _elementType;
|
||||
/** The type of entry this set holds. */
|
||||
protected Class _entryType;
|
||||
|
||||
/** The elements of the set (in a sparse array). */
|
||||
protected Element[] _elements = new Element[INITIAL_CAPACITY];
|
||||
/** The entries of the set (in a sparse array). */
|
||||
protected Entry[] _entries = new Entry[INITIAL_CAPACITY];
|
||||
|
||||
/** The number of elements in this set. */
|
||||
/** The number of entries in this set. */
|
||||
protected int _size;
|
||||
|
||||
/** The default capacity of a set instance. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryAddedEvent.java,v 1.6 2002/02/04 00:50:11 mdb Exp $
|
||||
// $Id: EntryAddedEvent.java,v 1.7 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -8,40 +8,39 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.dobj.io.ElementUtil;
|
||||
import com.threerings.presents.dobj.io.EntryUtil;
|
||||
|
||||
/**
|
||||
* An element added event is dispatched when an element is added to a
|
||||
* <code>DSet</code> attribute of a distributed element. It can also be
|
||||
* constructed to request the addition of an element to a set and posted
|
||||
* to the dobjmgr.
|
||||
* An entry added event is dispatched when an entry is added to a {@link
|
||||
* DSet} attribute of a distributed entry. It can also be constructed to
|
||||
* request the addition of an entry to a set and posted to the dobjmgr.
|
||||
*
|
||||
* @see DObjectManager#postEvent
|
||||
*/
|
||||
public class ElementAddedEvent extends TypedEvent
|
||||
public class EntryAddedEvent extends TypedEvent
|
||||
{
|
||||
/** The typed object code for this event. */
|
||||
public static final short TYPE = TYPE_BASE + 8;
|
||||
|
||||
/**
|
||||
* Constructs a new element added event on the specified target object
|
||||
* with the supplied set attribute name and element to add.
|
||||
* Constructs a new entry added event on the specified target object
|
||||
* with the supplied set attribute name and entry to add.
|
||||
*
|
||||
* @param targetOid the object id of the object to whose set we will
|
||||
* add an element.
|
||||
* add an entry.
|
||||
* @param name the name of the attribute to which to add the specified
|
||||
* element.
|
||||
* @param elem the element to add to the set attribute.
|
||||
* @param qualified whether or not the element need be qualified with
|
||||
* entry.
|
||||
* @param entry the entry to add to the set attribute.
|
||||
* @param qualified whether or not the entry need be qualified with
|
||||
* its class when serializing (true for heterogenous sets, false for
|
||||
* homogenous sets).
|
||||
*/
|
||||
public ElementAddedEvent (int targetOid, String name, DSet.Element elem,
|
||||
public EntryAddedEvent (int targetOid, String name, DSet.Entry entry,
|
||||
boolean qualified)
|
||||
{
|
||||
super(targetOid);
|
||||
_name = name;
|
||||
_elem = elem;
|
||||
_entry = entry;
|
||||
_qualified = qualified;
|
||||
}
|
||||
|
||||
@@ -49,12 +48,12 @@ public class ElementAddedEvent extends TypedEvent
|
||||
* Constructs a blank instance of this event in preparation for
|
||||
* unserialization from the network.
|
||||
*/
|
||||
public ElementAddedEvent ()
|
||||
public EntryAddedEvent ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the set attribute to which an element has been
|
||||
* Returns the name of the set attribute to which an entry has been
|
||||
* added.
|
||||
*/
|
||||
public String getName ()
|
||||
@@ -63,11 +62,11 @@ public class ElementAddedEvent extends TypedEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element that has been added.
|
||||
* Returns the entry that has been added.
|
||||
*/
|
||||
public DSet.Element getElement ()
|
||||
public DSet.Entry getEntry ()
|
||||
{
|
||||
return _elem;
|
||||
return _entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,18 +78,18 @@ public class ElementAddedEvent extends TypedEvent
|
||||
DSet set = (DSet)target.getAttribute(_name);
|
||||
|
||||
// now that we have access to our target set, we can unflatten our
|
||||
// element (if need be)
|
||||
if (_elem == null) {
|
||||
// entry (if need be)
|
||||
if (_entry == null) {
|
||||
try {
|
||||
_elem = ElementUtil.unflatten(set, _bytes);
|
||||
_entry = EntryUtil.unflatten(set, _bytes);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Error unflattening element " + this + ".");
|
||||
Log.warning("Error unflattening entry " + this + ".");
|
||||
Log.logStackTrace(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
set.add(_elem);
|
||||
set.add(_entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ public class ElementAddedEvent extends TypedEvent
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeUTF(_name);
|
||||
ElementUtil.flatten(out, _elem, _qualified);
|
||||
EntryUtil.flatten(out, _entry, _qualified);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -116,9 +115,9 @@ public class ElementAddedEvent extends TypedEvent
|
||||
super.readFrom(in);
|
||||
_name = in.readUTF();
|
||||
|
||||
// we read in the raw element data now and decode it later when we
|
||||
// we read in the raw entry data now and decode it later when we
|
||||
// have access to the object and the DSet instance that knows what
|
||||
// type of element we need to decode
|
||||
// type of entry we need to decode
|
||||
int bcount = in.readInt();
|
||||
_bytes = new byte[bcount];
|
||||
in.readFully(_bytes, 0, bcount);
|
||||
@@ -128,7 +127,7 @@ public class ElementAddedEvent extends TypedEvent
|
||||
protected void notifyListener (Object listener)
|
||||
{
|
||||
if (listener instanceof SetListener) {
|
||||
((SetListener)listener).elementAdded(this);
|
||||
((SetListener)listener).entryAdded(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,11 +137,11 @@ public class ElementAddedEvent extends TypedEvent
|
||||
buf.append("ELADD:");
|
||||
super.toString(buf);
|
||||
buf.append(", name=").append(_name);
|
||||
buf.append(", elem=").append(_elem);
|
||||
buf.append(", entry=").append(_entry);
|
||||
}
|
||||
|
||||
protected String _name;
|
||||
protected byte[] _bytes;
|
||||
protected DSet.Element _elem;
|
||||
protected DSet.Entry _entry;
|
||||
protected boolean _qualified;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryRemovedEvent.java,v 1.7 2002/02/01 23:32:37 mdb Exp $
|
||||
// $Id: EntryRemovedEvent.java,v 1.8 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -10,30 +10,29 @@ import java.io.IOException;
|
||||
import com.threerings.presents.io.ValueMarshaller;
|
||||
|
||||
/**
|
||||
* An element removed event is dispatched when an element is removed from
|
||||
* a <code>DSet</code> attribute of a distributed object. It can also be
|
||||
* constructed to request the removal of an element from a set and posted
|
||||
* to the dobjmgr.
|
||||
* An entry removed event is dispatched when an entry is removed from a
|
||||
* {@link DSet} attribute of a distributed object. It can also be
|
||||
* constructed to request the removal of an entry from a set and posted to
|
||||
* the dobjmgr.
|
||||
*
|
||||
* @see DObjectManager#postEvent
|
||||
*/
|
||||
public class ElementRemovedEvent extends TypedEvent
|
||||
public class EntryRemovedEvent extends TypedEvent
|
||||
{
|
||||
/** The typed object code for this event. */
|
||||
public static final short TYPE = TYPE_BASE + 9;
|
||||
|
||||
/**
|
||||
* Constructs a new element removed event on the specified target
|
||||
* object with the supplied set attribute name and element key to
|
||||
* remove.
|
||||
* Constructs a new entry removed event on the specified target object
|
||||
* with the supplied set attribute name and entry key to remove.
|
||||
*
|
||||
* @param targetOid the object id of the object from whose set we will
|
||||
* remove an element.
|
||||
* remove an entry.
|
||||
* @param name the name of the attribute from which to remove the
|
||||
* specified element.
|
||||
* @param key the element key that identifies the element to remove.
|
||||
* specified entry.
|
||||
* @param key the entry key that identifies the entry to remove.
|
||||
*/
|
||||
public ElementRemovedEvent (int targetOid, String name, Object key)
|
||||
public EntryRemovedEvent (int targetOid, String name, Object key)
|
||||
{
|
||||
super(targetOid);
|
||||
_name = name;
|
||||
@@ -44,7 +43,7 @@ public class ElementRemovedEvent extends TypedEvent
|
||||
* Constructs a blank instance of this event in preparation for
|
||||
* unserialization from the network.
|
||||
*/
|
||||
public ElementRemovedEvent ()
|
||||
public EntryRemovedEvent ()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +57,7 @@ public class ElementRemovedEvent extends TypedEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that identifies the element that has been removed.
|
||||
* Returns the key that identifies the entry that has been removed.
|
||||
*/
|
||||
public Object getKey ()
|
||||
{
|
||||
@@ -105,7 +104,7 @@ public class ElementRemovedEvent extends TypedEvent
|
||||
protected void notifyListener (Object listener)
|
||||
{
|
||||
if (listener instanceof SetListener) {
|
||||
((SetListener)listener).elementRemoved(this);
|
||||
((SetListener)listener).entryRemoved(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryUpdatedEvent.java,v 1.4 2002/02/04 00:50:11 mdb Exp $
|
||||
// $Id: EntryUpdatedEvent.java,v 1.5 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -8,40 +8,39 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.dobj.io.ElementUtil;
|
||||
import com.threerings.presents.dobj.io.EntryUtil;
|
||||
|
||||
/**
|
||||
* An element updated event is dispatched when an element of a
|
||||
* <code>DSet</code> is updated. It can also be constructed to request the
|
||||
* update of an element and posted to the dobjmgr.
|
||||
* An entry updated event is dispatched when an entry of a {@link DSet} is
|
||||
* updated. It can also be constructed to request the update of an entry
|
||||
* and posted to the dobjmgr.
|
||||
*
|
||||
* @see DObjectManager#postEvent
|
||||
*/
|
||||
public class ElementUpdatedEvent extends TypedEvent
|
||||
public class EntryUpdatedEvent extends TypedEvent
|
||||
{
|
||||
/** The typed object code for this event. */
|
||||
public static final short TYPE = TYPE_BASE + 10;
|
||||
|
||||
/**
|
||||
* Constructs a new element updated event on the specified target
|
||||
* object for the specified set name and with the supplied updated
|
||||
* element.
|
||||
* Constructs a new entry updated event on the specified target object
|
||||
* for the specified set name and with the supplied updated entry.
|
||||
*
|
||||
* @param targetOid the object id of the object to whose set we will
|
||||
* add an element.
|
||||
* add an entry.
|
||||
* @param name the name of the attribute in which to update the
|
||||
* specified element.
|
||||
* @param elem the element to update.
|
||||
* @param qualified whether or not the element need be qualified with
|
||||
* specified entry.
|
||||
* @param entry the entry to update.
|
||||
* @param qualified whether or not the entry need be qualified with
|
||||
* its class when serializing (true for heterogenous sets, false for
|
||||
* homogenous sets).
|
||||
*/
|
||||
public ElementUpdatedEvent (int targetOid, String name, DSet.Element elem,
|
||||
public EntryUpdatedEvent (int targetOid, String name, DSet.Entry entry,
|
||||
boolean qualified)
|
||||
{
|
||||
super(targetOid);
|
||||
_name = name;
|
||||
_elem = elem;
|
||||
_entry = entry;
|
||||
_qualified = qualified;
|
||||
}
|
||||
|
||||
@@ -49,12 +48,12 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
* Constructs a blank instance of this event in preparation for
|
||||
* unserialization from the network.
|
||||
*/
|
||||
public ElementUpdatedEvent ()
|
||||
public EntryUpdatedEvent ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the set attribute for which an element has been
|
||||
* Returns the name of the set attribute for which an entry has been
|
||||
* updated.
|
||||
*/
|
||||
public String getName ()
|
||||
@@ -63,11 +62,11 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element that has been updated.
|
||||
* Returns the entry that has been updated.
|
||||
*/
|
||||
public DSet.Element getElement ()
|
||||
public DSet.Entry getEntry ()
|
||||
{
|
||||
return _elem;
|
||||
return _entry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,21 +78,21 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
DSet set = (DSet)target.getAttribute(_name);
|
||||
|
||||
// now that we have access to our target set, we can unflatten our
|
||||
// element (if need be)
|
||||
if (_elem == null) {
|
||||
// entry (if need be)
|
||||
if (_entry == null) {
|
||||
try {
|
||||
_elem = ElementUtil.unflatten(set, _bytes);
|
||||
_entry = EntryUtil.unflatten(set, _bytes);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Error unflattening element " + this + ".");
|
||||
Log.warning("Error unflattening entry " + this + ".");
|
||||
Log.logStackTrace(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// update the element
|
||||
if (!set.update(_elem)) {
|
||||
// update the entry
|
||||
if (!set.update(_entry)) {
|
||||
// complain if we didn't update anything
|
||||
Log.warning("No matching element to update " + this + ".");
|
||||
Log.warning("No matching entry to update " + this + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,7 +111,7 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeUTF(_name);
|
||||
ElementUtil.flatten(out, _elem, _qualified);
|
||||
EntryUtil.flatten(out, _entry, _qualified);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -122,9 +121,9 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
super.readFrom(in);
|
||||
_name = in.readUTF();
|
||||
|
||||
// we read in the raw element data now and decode it later when we
|
||||
// we read in the raw entry data now and decode it later when we
|
||||
// have access to the object and the DSet instance that knows what
|
||||
// type of element we need to decode
|
||||
// type of entry we need to decode
|
||||
int bcount = in.readInt();
|
||||
_bytes = new byte[bcount];
|
||||
in.readFully(_bytes, 0, bcount);
|
||||
@@ -134,7 +133,7 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
protected void notifyListener (Object listener)
|
||||
{
|
||||
if (listener instanceof SetListener) {
|
||||
((SetListener)listener).elementUpdated(this);
|
||||
((SetListener)listener).entryUpdated(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,11 +143,11 @@ public class ElementUpdatedEvent extends TypedEvent
|
||||
buf.append("ELUPD:");
|
||||
super.toString(buf);
|
||||
buf.append(", name=").append(_name);
|
||||
buf.append(", elem=").append(_elem);
|
||||
buf.append(", entry=").append(_entry);
|
||||
}
|
||||
|
||||
protected String _name;
|
||||
protected byte[] _bytes;
|
||||
protected DSet.Element _elem;
|
||||
protected DSet.Entry _entry;
|
||||
protected boolean _qualified;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: SetListener.java,v 1.2 2002/02/03 04:38:05 mdb Exp $
|
||||
// $Id: SetListener.java,v 1.3 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
@@ -12,29 +12,29 @@ package com.threerings.presents.dobj;
|
||||
public interface SetListener extends ChangeListener
|
||||
{
|
||||
/**
|
||||
* Called when an element added event has been dispatched on an
|
||||
* Called when an entry added event has been dispatched on an
|
||||
* object. This will be called <em>after</em> the event has been
|
||||
* applied to the object.
|
||||
*
|
||||
* @param event The event that was dispatched on the object.
|
||||
*/
|
||||
public void elementAdded (ElementAddedEvent event);
|
||||
public void entryAdded (EntryAddedEvent event);
|
||||
|
||||
/**
|
||||
* Called when an element updated event has been dispatched on an
|
||||
* Called when an entry updated event has been dispatched on an
|
||||
* object. This will be called <em>after</em> the event has been
|
||||
* applied to the object.
|
||||
*
|
||||
* @param event The event that was dispatched on the object.
|
||||
*/
|
||||
public void elementUpdated (ElementUpdatedEvent event);
|
||||
public void entryUpdated (EntryUpdatedEvent event);
|
||||
|
||||
/**
|
||||
* Called when an element removed event has been dispatched on an
|
||||
* Called when an entry removed event has been dispatched on an
|
||||
* object. This will be called <em>after</em> the event has been
|
||||
* applied to the object.
|
||||
*
|
||||
* @param event The event that was dispatched on the object.
|
||||
*/
|
||||
public void elementRemoved (ElementRemovedEvent event);
|
||||
public void entryRemoved (EntryRemovedEvent event);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: EntryUtil.java,v 1.4 2002/02/04 00:50:12 mdb Exp $
|
||||
// $Id: EntryUtil.java,v 1.5 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj.io;
|
||||
|
||||
@@ -9,31 +9,31 @@ import com.threerings.presents.Log;
|
||||
import com.threerings.presents.dobj.DSet;
|
||||
|
||||
/**
|
||||
* Routines to simplify the process of moving set elements over the wire.
|
||||
* Because we don't know the type of the element when the event is
|
||||
* Routines to simplify the process of moving set entries over the wire.
|
||||
* Because we don't know the type of the entry when the event is
|
||||
* unserialized (we only know later when the event is applied to the
|
||||
* object and the event has access to the target set object), then we need
|
||||
* to do some jockeying.
|
||||
*/
|
||||
public class ElementUtil
|
||||
public class EntryUtil
|
||||
{
|
||||
/**
|
||||
* Flattens the supplied element into a byte array, counts the number
|
||||
* of bytes in the array and writes the count followed by the bytes to
|
||||
* Flattens the supplied entry into a byte array, counts the number of
|
||||
* bytes in the array and writes the count followed by the bytes to
|
||||
* the supplied data output stream. This method should really only be
|
||||
* called by the conmgr thread, but we synchronize just in case
|
||||
* someone decides to write an event out in some other peculiar
|
||||
* context; uncontested syncs are pretty fast.
|
||||
*/
|
||||
public static synchronized void flatten (
|
||||
DataOutputStream out, DSet.Element elem, boolean qualified)
|
||||
DataOutputStream out, DSet.Entry entry, boolean qualified)
|
||||
throws IOException
|
||||
{
|
||||
// write the element classname out if requested
|
||||
// write the entry classname out if requested
|
||||
if (qualified) {
|
||||
_dout.writeUTF(elem.getClass().getName());
|
||||
_dout.writeUTF(entry.getClass().getName());
|
||||
}
|
||||
elem.writeTo(_dout);
|
||||
entry.writeTo(_dout);
|
||||
_dout.flush();
|
||||
out.writeInt(_bout.size());
|
||||
_bout.writeTo(out);
|
||||
@@ -41,20 +41,20 @@ public class ElementUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Unflattens an element given the serialized element data. We know
|
||||
* Unflattens an entry given the serialized entry data. We know
|
||||
* this will always be called on the dobjmgr thread, so we need not
|
||||
* synchronize.
|
||||
*/
|
||||
public static DSet.Element unflatten (DSet set, byte[] data)
|
||||
public static DSet.Entry unflatten (DSet set, byte[] data)
|
||||
throws IOException
|
||||
{
|
||||
_bin.setBytes(data);
|
||||
return set.readElement(_din);
|
||||
return set.readEntry(_din);
|
||||
}
|
||||
|
||||
/**
|
||||
* We extend byte array input stream to avoid having to create a new
|
||||
* input stream every time we unserialize an element. Our extensions
|
||||
* input stream every time we unserialize an entry. Our extensions
|
||||
* allow us to repurpose this input stream to read from a new byte
|
||||
* array each time we unserialize.
|
||||
*/
|
||||
@@ -74,16 +74,16 @@ public class ElementUtil
|
||||
}
|
||||
}
|
||||
|
||||
/** Used when serializing elements. */
|
||||
/** Used when serializing entries. */
|
||||
protected static ByteArrayOutputStream _bout = new ByteArrayOutputStream();
|
||||
|
||||
/** Used when serializing elements. */
|
||||
/** Used when serializing entries. */
|
||||
protected static DataOutputStream _dout = new DataOutputStream(_bout);
|
||||
|
||||
/** Used when unserializing elements. */
|
||||
/** Used when unserializing entries. */
|
||||
protected static ReByteArrayInputStream _bin =
|
||||
new ReByteArrayInputStream();
|
||||
|
||||
/** Used when unserializing elements. */
|
||||
/** Used when unserializing entries. */
|
||||
protected static DataInputStream _din = new DataInputStream(_bin);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TypedObjectRegistry.java,v 1.8 2001/10/23 20:22:47 mdb Exp $
|
||||
// $Id: TypedObjectRegistry.java,v 1.9 2002/03/18 23:21:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.io;
|
||||
|
||||
@@ -66,11 +66,11 @@ public class TypedObjectRegistry
|
||||
ReleaseLockEvent.class);
|
||||
TypedObjectFactory.registerClass(ObjectDestroyedEvent.TYPE,
|
||||
ObjectDestroyedEvent.class);
|
||||
TypedObjectFactory.registerClass(ElementAddedEvent.TYPE,
|
||||
ElementAddedEvent.class);
|
||||
TypedObjectFactory.registerClass(ElementRemovedEvent.TYPE,
|
||||
ElementRemovedEvent.class);
|
||||
TypedObjectFactory.registerClass(ElementUpdatedEvent.TYPE,
|
||||
ElementUpdatedEvent.class);
|
||||
TypedObjectFactory.registerClass(EntryAddedEvent.TYPE,
|
||||
EntryAddedEvent.class);
|
||||
TypedObjectFactory.registerClass(EntryRemovedEvent.TYPE,
|
||||
EntryRemovedEvent.class);
|
||||
TypedObjectFactory.registerClass(EntryUpdatedEvent.TYPE,
|
||||
EntryUpdatedEvent.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user