Пример #1
0
  //
  // Any exception destroys the session.
  //
  // Should only be called from the main thread.
  //
  private void destroyWithError(final String msg) {
    List<ChatRoomListener> copy;

    synchronized (this) {
      destroy();
      _error = msg;

      copy = new ArrayList<ChatRoomListener>(_listeners);
    }

    for (ChatRoomListener listener : copy) {
      listener.error();
    }
  }
Пример #2
0
    public void init(String[] users, Ice.Current current) {
      List<ChatRoomListener> copy;
      final List<String> u = Arrays.asList(users);

      synchronized (this) {
        _users.clear();
        _users.addAll(u);

        // No replay event for init.
        copy = new ArrayList<ChatRoomListener>(_listeners);
      }

      for (ChatRoomListener listener : copy) {
        listener.init(u);
      }
    }
Пример #3
0
  // This method is only called by the UI thread.
  public synchronized String addChatRoomListener(ChatRoomListener cb, boolean replay) {
    _listeners.add(cb);
    cb.init(_users);

    if (replay) {
      // Replay the entire state.
      for (ChatEventReplay r : _replay) {
        r.replay(cb);
      }
    }

    if (_error != null) {
      cb.error();
    }

    return _hostname;
  }
Пример #4
0
    public void send(
        final long timestamp, final String name, final String message, Ice.Current current) {
      List<ChatRoomListener> copy;

      synchronized (this) {
        _replay.add(
            new ChatEventReplay() {
              public void replay(ChatRoomListener cb) {
                cb.send(timestamp, name, message);
              }
            });
        if (_replay.size() > MAX_MESSAGES) {
          _replay.removeFirst();
        }

        copy = new ArrayList<ChatRoomListener>(_listeners);
      }

      for (ChatRoomListener listener : copy) {
        listener.send(timestamp, name, message);
      }
    }