Modified the DefaultServer to send a second client
info message to indicate that all of the local hosted services have been notified about the new connection. Modified DefaultClient to wait to start its services until it has seen this second message. Client services may want to send things to the server during their start() method but it's important that things like the serializer registry service has already processed its messages or any sends might fail. The client generally has the luxury of being able to register handlers/listeners/etc during initialize where as the server must do this when the connection arrives. So it seems reasonable to delay client service start() until all of the server-side hosted services have had a chance to initialize themselves.
This commit is contained in:
parent
d3c644123a
commit
57dbf384a2
@ -177,6 +177,10 @@ public class DefaultClient implements Client
|
||||
continue;
|
||||
send(ch, reg, false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
protected void waitForConnected()
|
||||
@ -351,13 +355,16 @@ public class DefaultClient implements Client
|
||||
|
||||
protected void fireConnected()
|
||||
{
|
||||
// Let the services know we are finally started
|
||||
services.start();
|
||||
|
||||
for( ClientStateListener l : stateListeners ) {
|
||||
l.clientConnected( this );
|
||||
}
|
||||
}
|
||||
|
||||
protected void startServices()
|
||||
{
|
||||
// Let the services know we are finally started
|
||||
services.start();
|
||||
}
|
||||
|
||||
protected void fireDisconnected( DisconnectInfo info )
|
||||
{
|
||||
@ -416,11 +423,19 @@ public class DefaultClient implements Client
|
||||
// Pull off the connection management messages we're
|
||||
// interested in and then pass on the rest.
|
||||
if( m instanceof ClientRegistrationMessage ) {
|
||||
// Then we've gotten our real id
|
||||
this.id = (int)((ClientRegistrationMessage)m).getId();
|
||||
log.log( Level.FINE, "Connection established, id:{0}.", this.id );
|
||||
connecting.countDown();
|
||||
fireConnected();
|
||||
ClientRegistrationMessage crm = (ClientRegistrationMessage)m;
|
||||
// See if it has a real ID
|
||||
if( crm.getId() >= 0 ) {
|
||||
// Then we've gotten our real id
|
||||
this.id = (int)crm.getId();
|
||||
log.log( Level.FINE, "Connection established, id:{0}.", this.id );
|
||||
connecting.countDown();
|
||||
fireConnected();
|
||||
} else {
|
||||
// Else it's a message letting us know that the
|
||||
// hosted services have been started
|
||||
startServices();
|
||||
}
|
||||
return;
|
||||
} else if( m instanceof ChannelInfoMessage ) {
|
||||
// This is an interum step in the connection process and
|
||||
|
@ -412,7 +412,14 @@ public class DefaultServer implements Server
|
||||
|
||||
// Now we can notify the listeners about the
|
||||
// new connection.
|
||||
fireConnectionAdded( addedConnection );
|
||||
fireConnectionAdded( addedConnection );
|
||||
|
||||
// Send a second registration message with an invalid ID
|
||||
// to let the connection know that it can start its services
|
||||
m = new ClientRegistrationMessage();
|
||||
m.setId(-1);
|
||||
m.setReliable(true);
|
||||
addedConnection.send(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user