Hi
Today i watched a few tutorials for java RMI API.
So to be able to share object and method invocation in RMI we should have an interface and an implementation of it.
Client only knows about interface.
So sorry to ask it here, i am a noob and I am a bit confused how this is done in chat service in sim-eth example.
Client has it’s own implementation of interface ChatSessionListener through class ChatSessionCallback and share it with server.
Server has it’s own implementation of ChatSessionListener through class ChatSessionImpl and share with client.
Can you please explain why? (with more details please)
And why should we have this object in client service :
/**
* Shared with the server over RMI so that it can notify us about account
* related stuff.
*/
private class ChatSessionCallback implements ChatSessionListener {
@Override
public void playerJoined( int clientId, String playerName ) {
if( log.isTraceEnabled() ) {
log.trace("playerJoined(" + clientId + ", " + playerName + ")");
}
for( ChatSessionListener l : listeners ) {
l.playerJoined(clientId, playerName);
}
}
@Override
public void newMessage( int clientId, String playerName, String message ) {
if( log.isTraceEnabled() ) {
log.trace("newMessage(" + clientId + ", " + playerName + ", " + message + ")");
}
for( ChatSessionListener l : listeners ) {
l.newMessage(clientId, playerName, message);
}
}
@Override
public void playerLeft( int clientId, String playerName ) {
if( log.isTraceEnabled() ) {
log.trace("playerLeft(" + clientId + ", " + playerName + ")");
}
for( ChatSessionListener l : listeners ) {
l.playerLeft(clientId, playerName);
}
}
}
which tries to notify other clients and has access to private List<ChatSessionListener> listeners = new CopyOnWriteArrayList<>();
Seems i have some fundamental issues understanding logic here, will appreciate if you direct me to some resources that can help me understand logic and concept better.