Example #1
0
  public synchronized void receiveEnd(short channel, End end) {
    SessionEndpoint endpoint = _receivingSessions[channel];
    if (endpoint != null) {
      _receivingSessions[channel] = null;

      endpoint.end(end);
    } else {
      // TODO error
    }
  }
Example #2
0
  public synchronized SessionEndpoint createSession(String name) {
    // todo assert connection state
    SessionEndpoint endpoint = new SessionEndpoint(this);
    short channel = getFirstFreeChannel();
    if (channel != -1) {
      _sendingSessions[channel] = endpoint;
      endpoint.setSendingChannel(channel);
      Begin begin = new Begin();
      begin.setNextOutgoingId(endpoint.getNextOutgoingId());
      begin.setOutgoingWindow(endpoint.getOutgoingWindowSize());
      begin.setIncomingWindow(endpoint.getIncomingWindowSize());

      begin.setHandleMax(_handleMax);
      send(channel, begin);

    } else {
      // todo error
    }
    return endpoint;
  }
Example #3
0
 public synchronized void receiveFlow(short channel, Flow flow) {
   SessionEndpoint endPoint = getSession(channel);
   endPoint.receiveFlow(flow);
 }
Example #4
0
 public synchronized void receiveDisposition(short channel, Disposition disposition) {
   SessionEndpoint endPoint = getSession(channel);
   endPoint.receiveDisposition(disposition);
 }
Example #5
0
 public synchronized void receiveTransfer(short channel, Transfer transfer) {
   SessionEndpoint endPoint = getSession(channel);
   endPoint.receiveTransfer(transfer);
 }
Example #6
0
 public synchronized void receiveDetach(short channel, Detach detach) {
   SessionEndpoint endPoint = getSession(channel);
   endPoint.receiveDetach(detach);
 }
Example #7
0
  public synchronized void receiveBegin(short channel, Begin begin) {
    short myChannelId;

    if (begin.getRemoteChannel() != null) {
      myChannelId = begin.getRemoteChannel().shortValue();
      SessionEndpoint endpoint;
      try {
        endpoint = _sendingSessions[myChannelId];
      } catch (IndexOutOfBoundsException e) {
        final Error error = new Error();
        error.setCondition(ConnectionError.FRAMING_ERROR);
        error.setDescription(
            "BEGIN received on channel "
                + channel
                + " with given remote-channel "
                + begin.getRemoteChannel()
                + " which is outside the valid range of 0 to "
                + _channelMax
                + ".");
        connectionError(error);
        return;
      }
      if (endpoint != null) {
        if (_receivingSessions[channel] == null) {
          _receivingSessions[channel] = endpoint;
          endpoint.setReceivingChannel(channel);
          endpoint.setNextIncomingId(begin.getNextOutgoingId());
          endpoint.setOutgoingSessionCredit(begin.getIncomingWindow());
        } else {
          final Error error = new Error();
          error.setCondition(ConnectionError.FRAMING_ERROR);
          error.setDescription(
              "BEGIN received on channel " + channel + " which is already in use.");
          connectionError(error);
        }
      } else {
        final Error error = new Error();
        error.setCondition(ConnectionError.FRAMING_ERROR);
        error.setDescription(
            "BEGIN received on channel "
                + channel
                + " with given remote-channel "
                + begin.getRemoteChannel()
                + " which is not known as a begun session.");
        connectionError(error);
      }

    } else // Peer requesting session creation
    {

      myChannelId = getFirstFreeChannel();
      if (myChannelId == -1) {
        // close any half open channel
        myChannelId = getFirstFreeChannel();
      }

      if (_receivingSessions[channel] == null) {
        SessionEndpoint endpoint = new SessionEndpoint(this, begin);

        _receivingSessions[channel] = endpoint;
        _sendingSessions[myChannelId] = endpoint;

        Begin beginToSend = new Begin();

        endpoint.setReceivingChannel(channel);
        endpoint.setSendingChannel(myChannelId);
        beginToSend.setRemoteChannel(UnsignedShort.valueOf(channel));
        beginToSend.setNextOutgoingId(endpoint.getNextOutgoingId());
        beginToSend.setOutgoingWindow(endpoint.getOutgoingWindowSize());
        beginToSend.setIncomingWindow(endpoint.getIncomingWindowSize());
        send(myChannelId, beginToSend);

        _connectionEventListener.remoteSessionCreation(endpoint);
      } else {
        final Error error = new Error();
        error.setCondition(ConnectionError.FRAMING_ERROR);
        error.setDescription("BEGIN received on channel " + channel + " which is already in use.");
        connectionError(error);
      }
    }
  }