@Override
  protected JID changeDataReceiver(
      Packet packet, JID newAddress, String command_sessionId, XMPPIOService<Object> serv) {
    BoshSession session = getBoshSession(packet.getTo());

    if (session != null) {
      String sessionId = session.getSessionId();

      if (sessionId.equals(command_sessionId)) {
        JID old_receiver = session.getDataReceiver();

        session.setDataReceiver(newAddress);

        return old_receiver;
      } else {
        log.info("Incorrect session ID, ignoring data redirect for: " + newAddress);
      }
    }

    return null;
  }
  /**
   * Method adds packets to the output queue stamping it with the appropriate {@link BoshSession}
   * data
   *
   * @param out_results collection of {@link Packet} objects to be added to queue
   * @param bs related {@link BoshSession}
   */
  protected void addOutPackets(Queue<Packet> out_results, BoshSession bs) {
    for (Packet res : out_results) {
      res.setPacketFrom(getFromAddress(bs.getSid().toString()));
      res.setPacketTo(bs.getDataReceiver());
      if (res.getCommand() != null) {
        switch (res.getCommand()) {
          case STREAM_CLOSED:
          case GETFEATURES:
            res.initVars(res.getPacketFrom(), res.getPacketTo());

            break;

          default:

            // Do nothing...
        }
      }
      addOutPacket(res);
    }
    out_results.clear();
  }
  @Override
  public boolean addOutStreamClosed(Packet packet, BoshSession bs, boolean withTimeout) {
    packet.setPacketFrom(getFromAddress(bs.getSid().toString()));
    packet.setPacketTo(bs.getDataReceiver());
    packet.initVars(packet.getPacketFrom(), packet.getPacketTo());
    bs.close();
    if (log.isLoggable(Level.FINEST)) {
      log.log(
          Level.FINEST,
          "{0} : {1} ({2})",
          new Object[] {BOSH_OPERATION_TYPE.REMOVE, bs.getSid(), "Closing bosh session"});
    }

    sessions.remove(bs.getSid());

    if (withTimeout) {
      return addOutPacketWithTimeout(packet, stoppedHandler, 15l, TimeUnit.SECONDS);
    } else {
      return addOutPacket(packet);
    }
  }
  @Override
  public boolean addOutStreamOpen(Packet packet, BoshSession bs) {
    packet.initVars(getFromAddress(bs.getSid().toString()), bs.getDataReceiver());

    return addOutPacketWithTimeout(packet, startedHandler, 15l, TimeUnit.SECONDS);
  }