summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-09 06:34:10 (EDT)
committerEike Stepper2007-10-09 06:34:10 (EDT)
commit75dd38168e7d900b3fa2ed616cb70259d20bbfcc (patch)
tree9ad36e1b879e0292e140dac76ec5204fe4bca5ea
parent3edaa01a92258526c2495a514076ac43542be0d9 (diff)
downloadcdo-75dd38168e7d900b3fa2ed616cb70259d20bbfcc.zip
cdo-75dd38168e7d900b3fa2ed616cb70259d20bbfcc.tar.gz
cdo-75dd38168e7d900b3fa2ed616cb70259d20bbfcc.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/protocol/ServerBuddyStateIndication.java34
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerMessageIndication.java33
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerProtocol.java45
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java40
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientMessageIndication.java40
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java60
6 files changed, 151 insertions, 101 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java
new file mode 100644
index 0000000..c75e23c
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java
@@ -0,0 +1,34 @@
+package org.eclipse.net4j.buddies.internal.server.protocol;
+
+import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
+import org.eclipse.net4j.buddies.internal.server.ServerBuddy;
+import org.eclipse.net4j.buddies.protocol.ISession;
+import org.eclipse.net4j.buddies.protocol.IBuddy.State;
+import org.eclipse.net4j.buddies.server.IBuddyAdmin;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class ServerBuddyStateIndication extends BuddyStateIndication
+{
+ public ServerBuddyStateIndication()
+ {
+ }
+
+ @Override
+ protected void stateChanged(String userID, State state)
+ {
+ synchronized (IBuddyAdmin.INSTANCE)
+ {
+ Map<String, ISession> sessions = IBuddyAdmin.INSTANCE.getSessions();
+ ISession session = sessions.get(userID);
+ if (session != null)
+ {
+ ServerBuddy buddy = (ServerBuddy)session.getSelf();
+ buddy.setState(state);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerMessageIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerMessageIndication.java
new file mode 100644
index 0000000..3cee0e0
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerMessageIndication.java
@@ -0,0 +1,33 @@
+package org.eclipse.net4j.buddies.internal.server.protocol;
+
+import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.MessageIndication;
+import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMessage;
+import org.eclipse.net4j.buddies.server.IBuddyAdmin;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class ServerMessageIndication extends MessageIndication
+{
+ public ServerMessageIndication()
+ {
+ }
+
+ @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);
+ }
+ }
+ }
+} \ No newline at end of file
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 b79787a..c9d2a1f 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
@@ -10,20 +10,10 @@
**************************************************************************/
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;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
-import java.util.Map;
/**
* @author Eike Stepper
@@ -48,44 +38,13 @@ public class ServerProtocol extends SignalProtocol
return new OpenSessionIndication();
case ProtocolConstants.SIGNAL_BUDDY_STATE:
- return new BuddyStateIndication()
- {
- @Override
- protected void stateChanged(String userID, State state)
- {
- synchronized (IBuddyAdmin.INSTANCE)
- {
- Map<String, ISession> sessions = IBuddyAdmin.INSTANCE.getSessions();
- ISession session = sessions.get(userID);
- if (session != null)
- {
- ServerBuddy buddy = (ServerBuddy)session.getSelf();
- buddy.setState(state);
- }
- }
- }
- };
+ return new ServerBuddyStateIndication();
case ProtocolConstants.SIGNAL_INSTALL_FACILITY:
return new InstallFacilityIndication();
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 new ServerMessageIndication();
}
return null;
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java
new file mode 100644
index 0000000..d6eb5e6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java
@@ -0,0 +1,40 @@
+package org.eclipse.net4j.internal.buddies.protocol;
+
+import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
+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.util.concurrent.ConcurrencyUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class ClientBuddyStateIndication extends BuddyStateIndication
+{
+ public ClientBuddyStateIndication()
+ {
+ }
+
+ @Override
+ protected void stateChanged(String userID, State state)
+ {
+ for (int i = 0; i < 50; i++)
+ {
+ ClientSession session = (ClientSession)getProtocol().getInfraStructure();
+ if (session == null)
+ {
+ ConcurrencyUtil.sleep(100);
+ }
+ else
+ {
+ ClientBuddy buddy = (ClientBuddy)session.getBuddies().get(userID);
+ if (buddy != null)
+ {
+ buddy.setState(state);
+ }
+
+ break;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientMessageIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientMessageIndication.java
new file mode 100644
index 0000000..47810e6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientMessageIndication.java
@@ -0,0 +1,40 @@
+package org.eclipse.net4j.internal.buddies.protocol;
+
+import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.MessageIndication;
+import org.eclipse.net4j.buddies.protocol.IMessage;
+import org.eclipse.net4j.internal.buddies.ClientSession;
+import org.eclipse.net4j.internal.buddies.Self;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class ClientMessageIndication extends MessageIndication
+{
+ public ClientMessageIndication()
+ {
+ }
+
+ @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;
+ }
+ }
+ }
+} \ No newline at end of file
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 098b2dd..184e943 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
@@ -10,18 +10,9 @@
**************************************************************************/
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;
/**
* @author Eike Stepper
@@ -49,57 +40,10 @@ public class ClientProtocol extends SignalProtocol
return new BuddyRemovedIndication();
case ProtocolConstants.SIGNAL_BUDDY_STATE:
- return new BuddyStateIndication()
- {
- @Override
- protected void stateChanged(String userID, State state)
- {
- for (int i = 0; i < 50; i++)
- {
- ClientSession session = (ClientSession)getProtocol().getInfraStructure();
- if (session == null)
- {
- ConcurrencyUtil.sleep(100);
- }
- else
- {
- ClientBuddy buddy = (ClientBuddy)session.getBuddies().get(userID);
- if (buddy != null)
- {
- buddy.setState(state);
- }
-
- break;
- }
- }
- }
- };
+ return new ClientBuddyStateIndication();
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 new ClientMessageIndication();
}
return null;