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