summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-09 08:14:29 (EDT)
committerEike Stepper2007-10-09 08:14:29 (EDT)
commit950db174d7800e51f6582579fc7a406b3a7c7473 (patch)
tree06597af922545c3a4936d366d0e21c4940f71d95
parent8b072fba7146175991fde2fd69a79f0b4068111e (diff)
downloadcdo-950db174d7800e51f6582579fc7a406b3a7c7473.zip
cdo-950db174d7800e51f6582579fc7a406b3a7c7473.tar.gz
cdo-950db174d7800e51f6582579fc7a406b3a7c7473.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.java31
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/CollaborationInitiatedNotification.java27
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java6
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java3
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java54
5 files changed, 109 insertions, 12 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 d0fec3e..0387d48 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
@@ -18,6 +18,7 @@ import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
import org.eclipse.net4j.buddies.internal.protocol.CollaborationContainer;
import org.eclipse.net4j.buddies.internal.server.bundle.OM;
import org.eclipse.net4j.buddies.internal.server.protocol.BuddyRemovedNotification;
+import org.eclipse.net4j.buddies.internal.server.protocol.CollaborationInitiatedNotification;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
@@ -102,26 +103,46 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
return session;
}
- public ICollaboration initiateCollaboration(String... userIDs)
+ public ICollaboration initiateCollaboration(IBuddy initiator, String... userIDs)
{
- long id;
+ long collaborationID;
Set<IBuddy> buddies = new HashSet<IBuddy>();
+ buddies.add(initiator);
synchronized (this)
{
- id = ++lastCollaborationID;
+ collaborationID = ++lastCollaborationID;
for (String userID : userIDs)
{
ISession session = sessions.get(userID);
if (session != null)
{
buddies.add(session.getSelf());
-
}
}
}
- Collaboration collaboration = new Collaboration(id, buddies);
+ Collaboration collaboration = new Collaboration(collaborationID, buddies);
addCollaboration(collaboration);
+ for (IBuddy buddy : buddies)
+ {
+ if (buddy != initiator)
+ {
+ try
+ {
+ buddies.remove(buddy);
+ new CollaborationInitiatedNotification(buddy.getSession().getChannel(), collaborationID, buddies).send();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ finally
+ {
+ buddies.add(buddy);
+ }
+ }
+ }
+
return collaboration;
}
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/CollaborationInitiatedNotification.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/CollaborationInitiatedNotification.java
index e7c52ad..bc50e84 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/CollaborationInitiatedNotification.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/CollaborationInitiatedNotification.java
@@ -12,33 +12,50 @@ package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.signal.Request;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import java.io.IOException;
+import java.util.Set;
/**
* @author Eike Stepper
*/
public class CollaborationInitiatedNotification extends Request
{
- private String buddy;
+ private long collaborationID;
- public CollaborationInitiatedNotification(IChannel channel, String buddy)
+ private Set<IBuddy> buddies;
+
+ public CollaborationInitiatedNotification(IChannel channel, long collaborationID, Set<IBuddy> buddies)
{
super(channel);
- this.buddy = buddy;
+ this.collaborationID = collaborationID;
+ this.buddies = buddies;
}
@Override
protected short getSignalID()
{
- return ProtocolConstants.SIGNAL_BUDDY_ADDED;
+ return ProtocolConstants.SIGNAL_COLLABORATION_INITIATED;
}
@Override
protected void requesting(ExtendedDataOutputStream out) throws IOException
{
- out.writeString(buddy);
+ out.writeLong(collaborationID);
+ if (buddies == null)
+ {
+ out.writeInt(0);
+ }
+ else
+ {
+ out.writeInt(buddies.size());
+ for (IBuddy buddy : buddies)
+ {
+ out.writeString(buddy.getUserID());
+ }
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java
index f735873..b98aea5 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java
@@ -11,7 +11,9 @@
package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
import org.eclipse.net4j.signal.IndicationWithResponse;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -46,7 +48,9 @@ public class InitiateCollaborationIndication extends IndicationWithResponse
userIDs[i] = in.readString();
}
- collaboration = IBuddyAdmin.INSTANCE.initiateCollaboration(userIDs);
+ ISession session = (ISession)getProtocol().getInfraStructure();
+ IBuddy initiator = session.getSelf();
+ collaboration = IBuddyAdmin.INSTANCE.initiateCollaboration(initiator, userIDs);
}
@Override
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
index 7347fcf..8a57521 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
@@ -13,6 +13,7 @@ package org.eclipse.net4j.buddies.server;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.server.BuddyAdmin;
import org.eclipse.net4j.buddies.protocol.IAccount;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.ICollaboration;
import org.eclipse.net4j.buddies.protocol.ICollaborationContainer;
import org.eclipse.net4j.buddies.protocol.ISession;
@@ -32,5 +33,5 @@ public interface IBuddyAdmin extends ICollaborationContainer
public ISession openSession(IChannel channel, String userID, String password, String[] facilityTypes);
- public ICollaboration initiateCollaboration(String... userIDs);
+ public ICollaboration initiateCollaboration(IBuddy initiator, String... userIDs);
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java
new file mode 100644
index 0000000..1387a2f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * 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.internal.protocol.ProtocolConstants;
+import org.eclipse.net4j.internal.buddies.ClientSession;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationInitiatedIndication extends Indication
+{
+ public CollaborationInitiatedIndication()
+ {
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_BUDDY_REMOVED;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ String buddy = in.readString();
+ for (int i = 0; i < 50; i++)
+ {
+ ClientSession session = (ClientSession)getProtocol().getInfraStructure();
+ if (session == null)
+ {
+ ConcurrencyUtil.sleep(100);
+ }
+ else
+ {
+ session.buddyRemoved(buddy);
+ break;
+ }
+ }
+ }
+}