summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-09 04:08:07 (EDT)
committerEike Stepper2007-10-09 04:08:07 (EDT)
commit2fccaed57d28b7f995af8d5ec4f557fa0ae947a5 (patch)
treec6a18214d050ad3f41ce0dd117cf54f648a4076f
parent6caddede4a012b47bcd3e7b22b3996af52e1a0db (diff)
downloadcdo-2fccaed57d28b7f995af8d5ec4f557fa0ae947a5.zip
cdo-2fccaed57d28b7f995af8d5ec4f557fa0ae947a5.tar.gz
cdo-2fccaed57d28b7f995af8d5ec4f557fa0ae947a5.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.java7
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java22
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/Collaboration.java38
-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/buddies/IBuddyCollaboration.java (renamed from plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/ICollaboration.java)12
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java61
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java30
7 files changed, 123 insertions, 50 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 1a39db0..3ea43f5 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,13 +14,13 @@ 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.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.ISession;
import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
+import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
-import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.event.IEvent;
@@ -34,7 +34,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
+public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, IListener
{
public static final BuddyAdmin INSTANCE = new BuddyAdmin();
@@ -94,6 +94,7 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
return session;
}
+ @Override
public void notifyEvent(IEvent event)
{
if (event.getSource() instanceof ServerSession)
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java
index dc3b2a1..698b576 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java
@@ -11,8 +11,12 @@
package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
+import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.MessageIndication;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.internal.server.ServerBuddy;
+import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMessage;
import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
@@ -61,6 +65,24 @@ public class ServerProtocol extends SignalProtocol
}
}
};
+
+ case ProtocolConstants.SIGNAL_MESSAGE:
+ return new MessageIndication()
+ {
+ @Override
+ protected void messageReceived(IMessage message)
+ {
+ synchronized (IBuddyAdmin.INSTANCE)
+ {
+ Map<String, ICollaboration> collaborations = IBuddyAdmin.INSTANCE.getCollaborations();
+ Collaboration collaboration = (Collaboration)collaborations.get(message.getCollaborationID());
+ if (collaboration != null)
+ {
+ collaboration.notifyMessage(message);
+ }
+ }
+ }
+ };
}
return null;
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/Collaboration.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/Collaboration.java
deleted file mode 100644
index 1bfed8b..0000000
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/Collaboration.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/***************************************************************************
- * 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.server;
-
-import org.eclipse.net4j.buddies.internal.protocol.BuddyContainer;
-
-/**
- * @author Eike Stepper
- */
-public class Collaboration extends BuddyContainer implements ICollaboration
-{
- public Collaboration()
- {
- }
-
- public int getID()
- {
- return 0;
- }
-
- public String getType()
- {
- return null;
- }
-
- public boolean isPublic()
- {
- return false;
- }
-}
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 c421e6b..f2b6a16 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.ICollaborationContainer;
import org.eclipse.net4j.buddies.protocol.ISession;
import java.util.Map;
@@ -20,7 +21,7 @@ import java.util.Map;
/**
* @author Eike Stepper
*/
-public interface IBuddyAdmin
+public interface IBuddyAdmin extends ICollaborationContainer
{
public static final IBuddyAdmin INSTANCE = BuddyAdmin.INSTANCE;
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/ICollaboration.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java
index 621e4f2..6f1427a 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/ICollaboration.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddyCollaboration.java
@@ -8,18 +8,14 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.buddies.server;
+package org.eclipse.net4j.buddies;
-import org.eclipse.net4j.buddies.protocol.IBuddyContainer;
+import org.eclipse.net4j.buddies.protocol.ICollaboration;
/**
* @author Eike Stepper
*/
-public interface ICollaboration extends IBuddyContainer
+public interface IBuddyCollaboration extends ICollaboration
{
- public int getID();
-
- public String getType();
-
- public boolean isPublic();
+ public IBuddySession getSession();
}
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
new file mode 100644
index 0000000..8222363
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * 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;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.Message;
+import org.eclipse.net4j.buddies.internal.protocol.MessageNotification;
+import org.eclipse.net4j.buddies.protocol.IMessage;
+import org.eclipse.net4j.util.WrappedException;
+
+import java.util.UUID;
+
+/**
+ * @author Eike Stepper
+ */
+public class BuddyCollaboration extends Collaboration implements IBuddyCollaboration
+{
+ private IBuddySession session;
+
+ public BuddyCollaboration()
+ {
+ super(createID());
+ }
+
+ public IBuddySession getSession()
+ {
+ return session;
+ }
+
+ public void sendMessage(IMessage message)
+ {
+ if (message instanceof Message)
+ {
+ ((Message)message).setSenderID(session.getSelf().getUserID());
+
+ }
+ try
+ {
+ new MessageNotification(session.getChannel(), message).send();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ private static String createID()
+ {
+ return UUID.randomUUID().toString();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
index 8d8ac0c..098b2dd 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
@@ -11,10 +11,14 @@
package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
+import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.MessageIndication;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
+import org.eclipse.net4j.buddies.protocol.IMessage;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
import org.eclipse.net4j.internal.buddies.ClientBuddy;
import org.eclipse.net4j.internal.buddies.ClientSession;
+import org.eclipse.net4j.internal.buddies.Self;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
@@ -70,6 +74,32 @@ public class ClientProtocol extends SignalProtocol
}
}
};
+
+ case ProtocolConstants.SIGNAL_MESSAGE:
+ return new MessageIndication()
+ {
+ @Override
+ protected void messageReceived(IMessage message)
+ {
+ for (int i = 0; i < 50; i++)
+ {
+ ClientSession session = (ClientSession)getProtocol().getInfraStructure();
+ if (session == null)
+ {
+ ConcurrencyUtil.sleep(100);
+ }
+ else
+ {
+ Self self = session.getSelf();
+ String collaborationID = message.getCollaborationID();
+
+ Collaboration collaboration = (Collaboration)self.getCollaborations().get(collaborationID);
+ collaboration.notifyMessage(message);
+ break;
+ }
+ }
+ }
+ };
}
return null;