summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-07 18:22:39 (EDT)
committerEike Stepper2007-10-07 18:22:39 (EDT)
commit67a0d44030f37db2923f89aba924c13f9bc6ac5f (patch)
treeb17bbc2c71af9a73835c5b1fc5ab8bb67f2a374d
parentd7992989e952b43eb492b962def7eee235d9be60 (diff)
downloadcdo-67a0d44030f37db2923f89aba924c13f9bc6ac5f.zip
cdo-67a0d44030f37db2923f89aba924c13f9bc6ac5f.tar.gz
cdo-67a0d44030f37db2923f89aba924c13f9bc6ac5f.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
index 9523ea4..32420ed 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
@@ -12,10 +12,15 @@ package org.eclipse.net4j.buddies.internal.server;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.protocol.BuddyAccount;
+import org.eclipse.net4j.buddies.internal.server.bundle.OM;
+import org.eclipse.net4j.buddies.internal.server.protocol.BuddyRemovedNotification;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
import org.eclipse.net4j.buddies.server.IBuddySession;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import java.util.HashMap;
@@ -24,7 +29,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public class BuddyAdmin extends Lifecycle implements IBuddyAdmin
+public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
{
public static final BuddyAdmin INSTANCE = new BuddyAdmin();
@@ -70,6 +75,38 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin
BuddySession session = new BuddySession(channel, account);
sessions.put(userID, session);
+ session.addListener(this);
return session;
}
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event.getSource() instanceof IBuddySession)
+ {
+ if (event instanceof ILifecycleEvent)
+ {
+ if (((ILifecycleEvent)event).getKind() == ILifecycleEvent.Kind.DEACTIVATED)
+ {
+ String userID = ((IBuddySession)event.getSource()).getAccount().getUserID();
+ synchronized (this)
+ {
+ if (sessions.remove(userID) != null)
+ {
+ for (IBuddySession session : sessions.values())
+ {
+ try
+ {
+ new BuddyRemovedNotification(session.getChannel(), userID).send();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}