summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-08 08:07:34 (EDT)
committerEike Stepper2007-10-08 08:07:34 (EDT)
commit94ca450fe38c01ad9851444b2d3c6a3e3030d439 (patch)
treeb5215183f0a4d989831f50cc1275727d5386dcbe
parent02d49b0152d3c7a7ce6a8ad2281dc532b0d359c3 (diff)
downloadcdo-94ca450fe38c01ad9851444b2d3c6a3e3030d439.zip
cdo-94ca450fe38c01ad9851444b2d3c6a3e3030d439.tar.gz
cdo-94ca450fe38c01ad9851444b2d3c6a3e3030d439.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/buddies/IBuddySession.java8
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddySession.java70
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java1
5 files changed, 8 insertions, 74 deletions
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddySession.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddySession.java
index 88ff356..5d8ef39 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddySession.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/buddies/IBuddySession.java
@@ -12,20 +12,16 @@ package org.eclipse.net4j.buddies;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.util.container.IContainer;
-
-import java.util.Map;
+import org.eclipse.net4j.buddies.protocol.IBuddyContainer;
/**
* @author Eike Stepper
*/
-public interface IBuddySession extends IContainer<IBuddy>
+public interface IBuddySession extends IBuddyContainer
{
public IChannel getChannel();
public IBuddy getSelf();
- public Map<String, IBuddy> getBuddies();
-
public void close();
}
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 938a0c4..945384d 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
@@ -12,33 +12,24 @@ package org.eclipse.net4j.internal.buddies;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.internal.protocol.BuddyContainer;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateNotification;
-import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
import org.eclipse.net4j.internal.buddies.bundle.OM;
-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;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author Eike Stepper
*/
-public class BuddySession extends Lifecycle implements IBuddySession, IListener
+public class BuddySession extends BuddyContainer implements IBuddySession, IListener
{
private IChannel channel;
private Self self;
- private Map<String, IBuddy> buddies = new HashMap<String, IBuddy>();
-
public BuddySession(IChannel channel)
{
this.channel = channel;
@@ -60,45 +51,6 @@ public class BuddySession extends Lifecycle implements IBuddySession, IListener
self.addListener(this);
}
- public Buddy addBuddy(String userID)
- {
- Buddy buddy = null;
- synchronized (buddies)
- {
- if (!buddies.containsKey(userID))
- {
- buddy = new Buddy(this, userID);
- buddies.put(userID, buddy);
- }
- }
-
- return buddy;
- }
-
- public Map<String, IBuddy> getBuddies()
- {
- synchronized (buddies)
- {
- return Collections.unmodifiableMap(buddies);
- }
- }
-
- public IBuddy[] getElements()
- {
- synchronized (buddies)
- {
- return buddies.values().toArray(new Buddy[buddies.size()]);
- }
- }
-
- public boolean isEmpty()
- {
- synchronized (buddies)
- {
- return buddies.isEmpty();
- }
- }
-
public void close()
{
channel.close();
@@ -135,25 +87,13 @@ public class BuddySession extends Lifecycle implements IBuddySession, IListener
public void buddyAdded(String userID)
{
- Buddy buddy = addBuddy(userID);
- if (buddy != null)
- {
- fireEvent(new SingleDeltaContainerEvent<IBuddy>(this, buddy, IContainerDelta.Kind.ADDED));
- }
+ Buddy buddy = new Buddy(this, userID);
+ addBuddy(buddy);
}
public void buddyRemoved(String userID)
{
- IBuddy buddy;
- synchronized (buddies)
- {
- buddy = buddies.remove(userID);
- }
-
- if (buddy != null)
- {
- fireEvent(new SingleDeltaContainerEvent<IBuddy>(this, buddy, IContainerDelta.Kind.REMOVED));
- }
+ removeBuddy(userID);
}
@Override
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
index 32ba25d..5a8f219 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/OpenSessionRequest.java
@@ -67,7 +67,7 @@ public class OpenSessionRequest extends RequestWithConfirmation<IBuddySession>
int size = in.readInt();
for (int i = 0; i < size; i++)
{
- session.addBuddy(in.readString());
+ session.buddyAdded(in.readString());
}
getProtocol().setInfraStructure(session);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
index 7d7c3be..243411e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
@@ -41,7 +41,6 @@ public abstract class Indication extends SignalReactor
}
InputStream wrappedInputStream = wrapInputStream(in);
- getProtocol().getChannel().getConnector().waitForConnection(5000L);
indicating(ExtendedDataInputStream.wrap(wrappedInputStream));
finishInputStream(wrappedInputStream);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
index 405332b..9dc8ace 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
@@ -43,7 +43,6 @@ public abstract class IndicationWithResponse extends SignalReactor
}
InputStream wrappedInputStream = wrapInputStream(in);
- getProtocol().getChannel().getConnector().waitForConnection(5000L);
indicating(ExtendedDataInputStream.wrap(wrappedInputStream));
finishInputStream(wrappedInputStream);
if (TRACER.isEnabled())