Feature #95
ClosedListener Support for serverside
| Status: | Assigned | Start date: | 05/21/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | achristian | % Done: | 0% |
|
| Category: | Core | |||
| Target version: | 1.2.0 |
Description
Please implement ClosedListener support on serverside to recognize when a client has disconnected or connection was lost to be able to do some cleanup stuff like removing unreferenced instances.
History
Updated by achristian about 1 year ago
In general this would be possible. But how will you indicate which client has lost the connection? You do not have any relation. You just would know: Client with IP XYZ and Port ABC is gone. Sou would have to implement your own relation.
I suggest to use the "unreferenced" mechanism, in combination with the session-pattern: http://dev.root1.de/projects/simon/wiki/Sample_session_pattern
Comments/Remarks??
Updated by achristian about 1 year ago
- Status changed from New to Feedback
Updated by achristian about 1 year ago
- Status changed from Feedback to New
Updated by Noctarius about 1 year ago
achristian wrote:
In general this would be possible. But how will you indicate which client has lost the connection? You do not have any relation. You just would know: Client with IP XYZ and Port ABC is gone. Sou would have to implement your own relation.
I suggest to use the "unreferenced" mechanism, in combination with the session-pattern: http://dev.root1.de/projects/simon/wiki/Sample_session_pattern
Comments/Remarks??
How to indicate? About the channel that was disconnected. That should be possible by using MINA.
Updated by achristian about 1 year ago
That was not the correct direction of my question. It's clear that the server is able to know which clients got disconnected.
But how will you establish a relation in your ClosedListener implementation?!
On client side it's easy. You know that you are connected to the server. But the server in general does not know about clients. SIMON has, beside the client's IP and port no information or any relation to the client. So the only information one could pass on the server side to the ClosedListener is the IP and maybe the port of the client. You would have to implement your own session-information/relation anyhow. That's why I suggested the session-pattern.
Maybe you could explain what kind of stuff you would cleanup on lost connection to client?! Maybe I then get the point ... :-)
Updated by Noctarius about 1 year ago
I use some kind of session pattern like stuff. On login the remoteserver transmits a ManagerAdvisor which can retrieve any "service" on the other side. Since the same client can connect on more than one IP I increment the count for same instances of managers. That count should be decremented on connectionlost or on clean logout and the manager instance should be removed if could reaches 0.
@Override
public void login(final IManagerAdvisor managerAdvisor) {
try {
managerAdvisorLock.lock();
final AtomicInteger integer = managerAdvisors.get(managerAdvisor);
if (integer != null && integer.get() > 1) {
integer.incrementAndGet();
} else {
managerAdvisors.put(managerAdvisor, new AtomicInteger(1));
}
final IChannelManager channelManager = managerAdvisor
.getManager(IChannelManager.class.getSimpleName());
channelManager.registerChannelListener(this);
} finally {
managerAdvisorLock.unlock();
}
}
@Override
public void logout(final IManagerAdvisor managerAdvisor) {
try {
managerAdvisorLock.lock();
final AtomicInteger integer = managerAdvisors.get(managerAdvisor);
if (integer == null) {
return;
}
if (integer.get() > 1) {
integer.decrementAndGet();
} else {
managerAdvisors.remove(managerAdvisor);
}
final IChannelManager channelManager = managerAdvisor
.getManagerByClassName(IChannelManager.class
.getCanonicalName());
if (channelManager != null) {
channelManager.removeChannelListener(this);
}
} finally {
managerAdvisorLock.unlock();
}
}
Updated by achristian 12 months ago
- Category set to Core
- Status changed from New to Assigned
- Assignee set to achristian
- Target version set to 1.2.0
I see. To complete the simon session-patter, you woud have to provide a remote-object to the client vie the return-value on login() method. If you then add the "Unreferenced" interface to this "session-object", you will be notified when the client get's disconnected. So in detail:
- create a class which has @SimonRemote and implements "Unreferenced"
- on login, create a instance of this class an pass it via return to the client. Passing via "return" is important here. Only with "return" the remote-object is attached to the current session.
- when client looses the connection, unreferenced() method will be called
So this would be the current available solution.
I will check about the possibility to add a closedlistener for server side. But as I said: There must be a relation of the closed-listener-instance to the current client-session. To get this into your code, there must be a line something like that:
1Simon.addClosedListenerForCurrentClientSession(myListener);
And this would only work if the callstack which calls this add-listener-method was triggered by a client-session. If it's not called from a client-session, there must be an exception. So all in all: I really prefer the already suggestes session pattern. Because there it is very clear what happens when.