diff --git a/src/java/com/threerings/presents/peer/data/NodeObject.java b/src/java/com/threerings/presents/peer/data/NodeObject.java
index a597b352d..faeeaac29 100644
--- a/src/java/com/threerings/presents/peer/data/NodeObject.java
+++ b/src/java/com/threerings/presents/peer/data/NodeObject.java
@@ -60,20 +60,20 @@ public class NodeObject extends DObject
{
/** The resource type. Only resources of the same type will have their ids compared. */
public String type;
-
+
/** The resource identifier, which can be null for singleton resources. */
public Comparable id;
-
+
public Lock ()
{
}
-
+
public Lock (String type, Comparable id)
{
this.type = type;
this.id = id;
}
-
+
// documentation inherited from interface Comparable
public int compareTo (Object other)
{
@@ -85,19 +85,19 @@ public class NodeObject extends DObject
@SuppressWarnings("unchecked") int v2 = id.compareTo(olock.id);
return v2;
}
-
+
// documentation inherited from interface DSet.Entry
public Comparable getKey ()
{
return this;
}
-
+
@Override // documentation inherited
public int hashCode ()
{
return type.hashCode() + (id == null ? 0 : id.hashCode());
}
-
+
@Override // documentation inherited
public boolean equals (Object other)
{
@@ -105,7 +105,7 @@ public class NodeObject extends DObject
return type.equals(olock.type) && ObjectUtil.equals(id, olock.id);
}
}
-
+
/** Used for informing peers of changes to persistent data. */
public static class CacheData extends SimpleStreamableObject
{
@@ -115,8 +115,8 @@ public class NodeObject extends DObject
/** The stale data in the cache. */
public Streamable data;
- public CacheData ()
- {
+ public CacheData ()
+ {
}
public CacheData (String cache, Streamable data)
@@ -128,7 +128,7 @@ public class NodeObject extends DObject
/** The service used to make requests of the node. */
public PeerMarshaller peerService;
-
+
/** Contains information on all clients connected to this node. */
public DSet clients = new DSet();
@@ -137,13 +137,21 @@ public class NodeObject extends DObject
/** Used to broadcast a node's desire to acquire a lock. */
public Lock acquiringLock;
-
+
/** Used to broadcast a node's desire to release a lock. */
public Lock releasingLock;
-
+
/** A field we use to broadcast changes to possible cached data. */
public CacheData cacheData;
+ /**
+ * Returns the number of subscribers to this node.
+ */
+ public int getSubscriberCount ()
+ {
+ return _scount;
+ }
+
// AUTO-GENERATED: METHODS START
/**
* Requests that the peerService field be set to the
diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java
index 3dbf42db0..ba66be2d2 100644
--- a/src/java/com/threerings/presents/peer/server/PeerManager.java
+++ b/src/java/com/threerings/presents/peer/server/PeerManager.java
@@ -296,7 +296,12 @@ public class PeerManager
queryLock(lock, new ResultListener() {
public void requestCompleted (String result) {
if (result == null) {
- _locks.put(lock, new LockHandler(lock, true, listener));
+ if (_nodeobj.getSubscriberCount() == 0) {
+ _nodeobj.addToLocks(lock);
+ listener.requestCompleted(_nodeName);
+ } else {
+ _locks.put(lock, new LockHandler(lock, true, listener));
+ }
} else {
listener.requestCompleted(result);
}
@@ -318,7 +323,12 @@ public class PeerManager
queryLock(lock, new ResultListener() {
public void requestCompleted (String result) {
if (_nodeName.equals(result)) {
- _locks.put(lock, new LockHandler(lock, false, listener));
+ if (_nodeobj.getSubscriberCount() == 0) {
+ _nodeobj.removeFromLocks(lock);
+ listener.requestCompleted(null);
+ } else {
+ _locks.put(lock, new LockHandler(lock, false, listener));
+ }
} else {
if (result != null) {
log.warning("Tried to release lock held by another peer [lock=" +
@@ -796,7 +806,7 @@ public class PeerManager
}
// find out exactly how many responses we need
- _remaining = _peers.size();
+ _remaining = _nodeobj.getSubscriberCount();
// schedule a timeout to act if something goes wrong
(_timeout = new Interval(PresentsServer.omgr) {