Пример #1
0
  private void sendInternal(
      final IByteStreamConnection connection, final TransferDescription description, byte[] payload)
      throws IOException {

    boolean sendPacket = true;

    for (IPacketInterceptor packetInterceptor : packetInterceptors)
      sendPacket &= packetInterceptor.sendPacket(description, payload);

    if (!sendPacket) return;

    long sizeUncompressed = payload.length;

    if (description.compressContent()) payload = deflate(payload);

    final long transferStartTime = System.currentTimeMillis();

    try {
      connection.send(description, payload);
    } catch (IOException e) {
      LOG.error(
          "failed to send " + description + ", connection=" + connection + ":" + e.getMessage(), e);
      throw e;
    }

    notifyDataSent(
        connection.getMode(),
        payload.length,
        sizeUncompressed,
        System.currentTimeMillis() - transferStartTime);
  }
Пример #2
0
  @Override
  public boolean closeConnection(String connectionIdentifier, JID peer) {

    final String outID = toConnectionIDToken(connectionIdentifier, OUT, peer);

    final String inID = toConnectionIDToken(connectionIdentifier, IN, peer);

    final IByteStreamConnection out = connectionPool.remove(outID);
    final IByteStreamConnection in = connectionPool.remove(inID);

    boolean closed = false;

    if (out != null) {
      closed |= true;
      out.close();
      LOG.debug("closed connection [pool id=" + outID + "]: " + out);
    }

    if (in != null) {
      closed |= true;
      in.close();
      LOG.debug("closed connection [pool id=" + inID + "]: " + in);
    }

    return closed;
  }
Пример #3
0
        @Override
        public void connectionChanged(
            final String connectionID,
            final JID peer,
            final IByteStreamConnection connection,
            final boolean incomingRequest) {

          // FIXME init first, than add to pool and finally start the receiver
          // thread !

          final String id = toConnectionIDToken(connectionID, incomingRequest ? IN : OUT, peer);

          LOG.debug(
              "bytestream connection changed "
                  + connection
                  + ", inc="
                  + incomingRequest
                  + ", pool id="
                  + id
                  + "]");

          /*
           * this may return the current connection if the pool is closed so
           * close it anyway
           */
          final IByteStreamConnection current = connectionPool.add(id, connection);

          if (current != null) {
            current.close();
            if (current == connection) {
              LOG.warn(
                  "closed connection [pool id="
                      + id
                      + "]: "
                      + current
                      + " , no connections are currently allowed");

              return;
            } else {
              LOG.warn(
                  "existing connection [pool id="
                      + id
                      + "] "
                      + current
                      + " was replaced with connection "
                      + connection);
            }
          }

          connection.initialize();
        }
Пример #4
0
 @Override
 public ConnectionMode getTransferMode(String connectionID, JID jid) {
   IByteStreamConnection connection = getCurrentConnection(connectionID, jid);
   return connection == null ? ConnectionMode.NONE : connection.getMode();
 }