Let's enforce that client reference copying with the structure of ObserverOps.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5541 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-11-11 19:09:42 +00:00
parent 0f8c7d8f4c
commit c16731c8d1
4 changed files with 37 additions and 27 deletions
@@ -211,10 +211,9 @@ public class BlockingCommunicator extends Communicator
log.info("Connection failed", ioe); log.info("Connection failed", ioe);
// let the client know that things went south // let the client know that things went south
final Client client = _client; notifyClientObservers(new ObserverOps.Client(_client) {
notifyClientObservers(new ObserverOps.Client() {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
obs.clientConnectionFailed(client, ioe); obs.clientConnectionFailed(_client, ioe);
} }
}); });
@@ -268,10 +267,9 @@ public class BlockingCommunicator extends Communicator
log.debug("Writer thread exited."); log.debug("Writer thread exited.");
// let the client observers know that we're logged off // let the client observers know that we're logged off
final Client client = _client; notifyClientObservers(new ObserverOps.Session(_client) {
notifyClientObservers(new ObserverOps.Session() {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientDidLogoff(client); obs.clientDidLogoff(_client);
} }
}); });
@@ -419,9 +419,9 @@ public class Client
} }
// notify our observers immediately // notify our observers immediately
_observers.apply(new ObserverOps.Session() { _observers.apply(new ObserverOps.Session(this) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientWillLogon(Client.this); obs.clientWillLogon(_client);
} }
}); });
@@ -505,9 +505,9 @@ public class Client
// if the request is abortable, let's run it past the observers before we act upon it // if the request is abortable, let's run it past the observers before we act upon it
final boolean[] rejected = new boolean[] { false }; final boolean[] rejected = new boolean[] { false };
_observers.apply(new ObserverOps.Client() { _observers.apply(new ObserverOps.Client(this) {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
if (!obs.clientWillLogoff(Client.this)) { if (!obs.clientWillLogoff(_client)) {
rejected[0] = true; rejected[0] = true;
} }
} }
@@ -530,9 +530,9 @@ public class Client
{ {
_standalone = true; _standalone = true;
// notify our observers immediately // notify our observers immediately
_observers.apply(new ObserverOps.Session() { _observers.apply(new ObserverOps.Session(this) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientWillLogon(Client.this); obs.clientWillLogon(_client);
} }
}); });
return getBootGroups(); return getBootGroups();
@@ -555,9 +555,9 @@ public class Client
*/ */
public void standaloneLogoff () public void standaloneLogoff ()
{ {
notifyObservers(new ObserverOps.Session() { notifyObservers(new ObserverOps.Session(this) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientDidLogoff(Client.this); obs.clientDidLogoff(_client);
} }
}); });
cleanup(null); // this will set _standalone to false cleanup(null); // this will set _standalone to false
@@ -726,9 +726,9 @@ public class Client
*/ */
protected void reportLogonTribulations (final LogonException cause) protected void reportLogonTribulations (final LogonException cause)
{ {
notifyObservers(new ObserverOps.Client() { notifyObservers(new ObserverOps.Client(this) {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
obs.clientFailedToLogon(Client.this, cause); obs.clientFailedToLogon(_client, cause);
} }
}); });
} }
@@ -743,9 +743,9 @@ public class Client
_clobj = clobj; _clobj = clobj;
// let the client know that logon has now fully succeeded // let the client know that logon has now fully succeeded
notifyObservers(new ObserverOps.Session() { notifyObservers(new ObserverOps.Session(this) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientDidLogon(Client.this); obs.clientDidLogon(_client);
} }
}); });
} }
@@ -756,9 +756,9 @@ public class Client
protected void getClientObjectFailed (final Exception cause) protected void getClientObjectFailed (final Exception cause)
{ {
// pass the buck onto the listeners // pass the buck onto the listeners
notifyObservers(new ObserverOps.Client() { notifyObservers(new ObserverOps.Client(this) {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
obs.clientFailedToLogon(Client.this, cause); obs.clientFailedToLogon(_client, cause);
} }
}); });
} }
@@ -772,9 +772,9 @@ public class Client
_cloid = _clobj.getOid(); _cloid = _clobj.getOid();
// report to our observers // report to our observers
notifyObservers(new ObserverOps.Session() { notifyObservers(new ObserverOps.Session(this) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientObjectDidChange(Client.this); obs.clientObjectDidChange(_client);
} }
}); });
} }
@@ -825,12 +825,12 @@ public class Client
// now that the communicator is cleaned up; this allows a logon failure listener to // now that the communicator is cleaned up; this allows a logon failure listener to
// immediately try another logon (hopefully with something changed like the server // immediately try another logon (hopefully with something changed like the server
// or port) // or port)
notifyObservers(new ObserverOps.Client() { notifyObservers(new ObserverOps.Client(Client.this) {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
if (logonError != null) { if (logonError != null) {
obs.clientFailedToLogon(Client.this, logonError); obs.clientFailedToLogon(_client, logonError);
} else { } else {
obs.clientDidClear(Client.this); obs.clientDidClear(_client);
} }
} }
}); });
@@ -30,20 +30,32 @@ public class ObserverOps
{ {
public abstract static class Session implements ObserverList.ObserverOp<SessionObserver> public abstract static class Session implements ObserverList.ObserverOp<SessionObserver>
{ {
public Session (com.threerings.presents.client.Client client) {
_client = client;
}
public boolean apply (SessionObserver obs) { public boolean apply (SessionObserver obs) {
notify(obs); notify(obs);
return true; return true;
} }
protected abstract void notify (SessionObserver obs); protected abstract void notify (SessionObserver obs);
protected com.threerings.presents.client.Client _client;
} }
public abstract static class Client extends Session public abstract static class Client extends Session
{ {
public Client (com.threerings.presents.client.Client client) {
super(client);
}
@Override public void notify (SessionObserver obs) { @Override public void notify (SessionObserver obs) {
if (obs instanceof ClientObserver) { if (obs instanceof ClientObserver) {
notify((ClientObserver)obs); notify((ClientObserver)obs);
} }
} }
protected abstract void notify (ClientObserver obs); protected abstract void notify (ClientObserver obs);
} }
} }
@@ -76,7 +76,7 @@ public class ServerCommunicator extends Communicator
} }
@Override public void networkFailure (final IOException ioe) { @Override public void networkFailure (final IOException ioe) {
notifyClientObservers(new ObserverOps.Client() { notifyClientObservers(new ObserverOps.Client(_client) {
protected void notify (ClientObserver obs) { protected void notify (ClientObserver obs) {
obs.clientConnectionFailed(_client, ioe); obs.clientConnectionFailed(_client, ioe);
} }
@@ -185,7 +185,7 @@ public class ServerCommunicator extends Communicator
{ {
if (_logonError == null) { if (_logonError == null) {
// we were logged on successfully, so report didLogoff first // we were logged on successfully, so report didLogoff first
notifyClientObservers(new ObserverOps.Session() { notifyClientObservers(new ObserverOps.Session(_client) {
protected void notify (SessionObserver obs) { protected void notify (SessionObserver obs) {
obs.clientDidLogoff(_client); obs.clientDidLogoff(_client);
} }