Use the number of subscribers to determine how many responses to expect.
Take the lock immediately if there are no subscribers. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4576 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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 <code>null</code> 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<ClientInfo> clients = new DSet<ClientInfo>();
|
||||
|
||||
@@ -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 <code>peerService</code> field be set to the
|
||||
|
||||
@@ -296,7 +296,12 @@ public class PeerManager
|
||||
queryLock(lock, new ResultListener<String>() {
|
||||
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<String>() {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user