コード例 #1
0
  protected ServerSessionImpl(
      BayeuxServerImpl bayeux, LocalSessionImpl localSession, String idHint) {
    _bayeux = bayeux;
    _localSession = localSession;

    StringBuilder id = new StringBuilder(30);
    int len = 20;
    if (idHint != null) {
      len += idHint.length() + 1;
      id.append(idHint);
      id.append('_');
    }
    int index = id.length();

    while (id.length() < len) {
      long random = _bayeux.randomLong();
      id.append(Long.toString(random < 0 ? -random : random, 36));
    }

    id.insert(index, Long.toString(_idCount.incrementAndGet(), 36));

    _id = id.toString();

    ServerTransport transport = _bayeux.getCurrentTransport();
    if (transport != null)
      _intervalTimestamp = System.currentTimeMillis() + transport.getMaxInterval();

    _broadcastToPublisher = _bayeux.isBroadcastToPublisher();
  }
コード例 #2
0
  public Map<String, Object> takeAdvice(ServerTransport transport) {
    if (transport != null && transport != _advisedTransport) {
      _advisedTransport = transport;

      // The timeout is calculated based on the values of the session/transport
      // because we want to send to the client the *next* timeout
      long timeout = getTimeout() < 0 ? transport.getTimeout() : getTimeout();

      // The interval is calculated using also the transient value
      // because we want to send to the client the *current* interval
      long interval = calculateInterval(transport.getInterval());

      Map<String, Object> advice = new HashMap<>(3);
      advice.put(Message.RECONNECT_FIELD, Message.RECONNECT_RETRY_VALUE);
      advice.put(Message.INTERVAL_FIELD, interval);
      advice.put(Message.TIMEOUT_FIELD, timeout);
      return advice;
    }

    // advice has not changed, so return null.
    return null;
  }