summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-09 07:34:52 (EDT)
committerEike Stepper2007-10-09 07:34:52 (EDT)
commitb6877dea3ff7bf29ca40a778d7977569be52d351 (patch)
tree203de289421101e70ffdc23de081c54cf44e3e63
parent8704a4307a4d79b6bbf146bd6d6f75a743f83b88 (diff)
downloadcdo-b6877dea3ff7bf29ca40a778d7977569be52d351.zip
cdo-b6877dea3ff7bf29ca40a778d7977569be52d351.tar.gz
cdo-b6877dea3ff7bf29ca40a778d7977569be52d351.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.java29
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java57
-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/BuddyCollaboration.java6
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java2
5 files changed, 94 insertions, 3 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 1d3a354..b0f93e9 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
@@ -14,11 +14,14 @@ import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.IProtocol;
import org.eclipse.net4j.buddies.internal.protocol.Account;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateNotification;
+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.protocol.IAccount;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
+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.internal.util.om.trace.ContextTracer;
@@ -29,7 +32,9 @@ import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -46,6 +51,8 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
private Map<String, ISession> sessions = new HashMap<String, ISession>();
+ private long lastCollaborationID;
+
public BuddyAdmin()
{
LifecycleUtil.activate(this);
@@ -96,6 +103,28 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
return session;
}
+ public ICollaboration initiateCollaboration(String... userIDs)
+ {
+ long id;
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ synchronized (this)
+ {
+ id = ++lastCollaborationID;
+ for (String userID : userIDs)
+ {
+ ISession session = sessions.get(userID);
+ if (session != null)
+ {
+ buddies.add(session.getSelf());
+ }
+ }
+ }
+
+ Collaboration collaboration = new Collaboration(id, buddies.toArray(new IBuddy[buddies.size()]));
+ addCollaboration(collaboration);
+ return collaboration;
+ }
+
@Override
public void notifyEvent(IEvent event)
{
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
new file mode 100644
index 0000000..f735873
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InitiateCollaborationIndication.java
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * 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.buddies.internal.server.protocol;
+
+import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.server.IBuddyAdmin;
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class InitiateCollaborationIndication extends IndicationWithResponse
+{
+ private ICollaboration collaboration;
+
+ public InitiateCollaborationIndication()
+ {
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return ProtocolConstants.SIGNAL_INITIATE_COLLABORATION;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ int size = in.readInt();
+ String[] userIDs = new String[size];
+ for (int i = 0; i < size; i++)
+ {
+ userIDs[i] = in.readString();
+ }
+
+ collaboration = IBuddyAdmin.INSTANCE.initiateCollaboration(userIDs);
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeLong(collaboration.getID());
+ }
+}
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 821aaa7..7347fcf 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.ICollaboration;
import org.eclipse.net4j.buddies.protocol.ICollaborationContainer;
import org.eclipse.net4j.buddies.protocol.ISession;
@@ -30,4 +31,6 @@ public interface IBuddyAdmin extends ICollaborationContainer
public Map<String, ISession> getSessions();
public ISession openSession(IChannel channel, String userID, String password, String[] facilityTypes);
+
+ public ICollaboration initiateCollaboration(String... userIDs);
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
index e65c646..904e2df 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
@@ -31,9 +31,9 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
private IBuddySession session;
- public BuddyCollaboration(long id)
+ public BuddyCollaboration(long id, IBuddy[] buddies)
{
- super(id);
+ super(id, buddies);
}
public IBuddySession getSession()
@@ -62,6 +62,7 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
}
}
+ @Override
public void sendMessage(IMessage message)
{
if (message instanceof Message)
@@ -69,6 +70,7 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
((Message)message).setSenderID(session.getSelf().getUserID());
}
+
try
{
new MessageNotification(session.getChannel(), message).send();
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
index b75b8ad..5cfb3ec 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
@@ -53,7 +53,7 @@ public class Self extends Buddy
try
{
long id = new InitiateCollaborationRequest(getSession().getChannel(), buddies).send(5000L);
- BuddyCollaboration collaboration = new BuddyCollaboration(id);
+ BuddyCollaboration collaboration = new BuddyCollaboration(id, buddies);
addCollaboration(collaboration);
return collaboration;
}