summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-07 16:42:16 (EDT)
committerEike Stepper2007-10-07 16:42:16 (EDT)
commitdcb7845c8b8b5cdd849f792ac75013d145a4c891 (patch)
tree6dad1e771d6bcf019afc8bb4a0e79c638c2b59ba
parenta9dbe947b6c81168c023bf325611fb685d81359c (diff)
downloadcdo-dcb7845c8b8b5cdd849f792ac75013d145a4c891.zip
cdo-dcb7845c8b8b5cdd849f792ac75013d145a4c891.tar.gz
cdo-dcb7845c8b8b5cdd849f792ac75013d145a4c891.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java22
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java5
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java4
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java42
4 files changed, 73 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java
index 45ec24e..f2e135e 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java
@@ -13,7 +13,9 @@ package org.eclipse.net4j.internal.buddies;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.IBuddySession;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
+import org.eclipse.net4j.internal.util.container.SingleDeltaContainerEvent;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
@@ -100,6 +102,26 @@ public class BuddySession extends Lifecycle implements IBuddySession, IListener
}
}
+ public void buddyAdded(String buddy)
+ {
+ synchronized (buddies)
+ {
+ buddies.add(buddy);
+ }
+
+ fireEvent(new SingleDeltaContainerEvent<String>(this, buddy, IContainerDelta.Kind.ADDED));
+ }
+
+ public void buddyRemoved(String buddy)
+ {
+ synchronized (buddies)
+ {
+ buddies.remove(buddy);
+ }
+
+ fireEvent(new SingleDeltaContainerEvent<String>(this, buddy, IContainerDelta.Kind.REMOVED));
+ }
+
@Override
protected void doActivate() throws Exception
{
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
index 9b9220d..71c8158 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
@@ -34,6 +34,11 @@ public class BuddiesClientProtocol extends SignalProtocol
{
switch (signalID)
{
+ case BuddiesProtocolConstants.SIGNAL_BUDDY_ADDED:
+ return new BuddyAddedIndication();
+
+ case BuddiesProtocolConstants.SIGNAL_BUDDY_REMOVED:
+ return new BuddyRemovedIndication();
}
return null;
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
index 843adc6..de7761f 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
+import org.eclipse.net4j.internal.buddies.BuddySession;
import org.eclipse.net4j.signal.Indication;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -34,5 +35,8 @@ public class BuddyAddedIndication extends Indication
@Override
protected void indicating(ExtendedDataInputStream in) throws IOException
{
+ String buddy = in.readString();
+ BuddySession session = (BuddySession)getProtocol().getInfraStructure();
+ session.buddyAdded(buddy);
}
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java
new file mode 100644
index 0000000..bc28bb6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.buddies.protocol;
+
+import org.eclipse.net4j.buddies.protocol.BuddiesProtocolConstants;
+import org.eclipse.net4j.internal.buddies.BuddySession;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddyRemovedIndication extends Indication
+{
+ public BuddyRemovedIndication()
+ {
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return BuddiesProtocolConstants.SIGNAL_BUDDY_REMOVED;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ String buddy = in.readString();
+ BuddySession session = (BuddySession)getProtocol().getInfraStructure();
+ session.buddyRemoved(buddy);
+ }
+}