Java Code Examples for org.apache.qpid.proton.engine.EndpointState#CLOSED

The following examples show how to use org.apache.qpid.proton.engine.EndpointState#CLOSED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmqpAbstractResource.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void close(AsyncResult request) {
   // If already closed signal success or else the caller might never get notified.
   if (getEndpoint().getLocalState() == EndpointState.CLOSED || getEndpoint().getRemoteState() == EndpointState.CLOSED) {

      if (getEndpoint().getLocalState() != EndpointState.CLOSED) {
         doClose();
         getEndpoint().free();
      }

      request.onSuccess();
   } else {
      this.closeRequest = request;
      doClose();
   }
}
 
Example 2
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void bind(Connection conn)
{
    // TODO - check if already bound

    _connectionEndpoint = (ConnectionImpl) conn;
    put(Event.Type.CONNECTION_BOUND, conn);
    _connectionEndpoint.setTransport(this);
    _connectionEndpoint.incref();

    if(getRemoteState() != EndpointState.UNINITIALIZED)
    {
        _connectionEndpoint.handleOpen(_open);
        if(getRemoteState() == EndpointState.CLOSED)
        {
            _connectionEndpoint.setRemoteState(EndpointState.CLOSED);
        }

        _frameParser.flush();
    }
}
 
Example 3
Source File: AmqpAbstractResource.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void detach(AsyncResult request) {
   // If already closed signal success or else the caller might never get notified.
   if (getEndpoint().getLocalState() == EndpointState.CLOSED || getEndpoint().getRemoteState() == EndpointState.CLOSED) {

      if (getEndpoint().getLocalState() != EndpointState.CLOSED) {
         doDetach();
         getEndpoint().free();
      }

      request.onSuccess();
   } else {
      this.closeRequest = request;
      doDetach();
   }
}
 
Example 4
Source File: SenderImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public int sendNoCopy(final ReadableBuffer buffer)
{
    if (getLocalState() == EndpointState.CLOSED)
    {
        throw new IllegalStateException("send not allowed after the sender is closed.");
    }
    DeliveryImpl current = current();
    if (current == null || current.getLink() != this)
    {
        throw new IllegalArgumentException();
    }
    int sent = current.sendNoCopy(buffer);
    if (sent > 0) {
        getSession().incrementOutgoingBytes(sent);
    }
    return sent;
}
 
Example 5
Source File: ProtonServerSenderContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void executeDelivery(MessageReference messageReference) {

      try {
         if (sender.getLocalState() == EndpointState.CLOSED) {
            log.debug("Not delivering message " + messageReference + " as the sender is closed and credits were available, if you see too many of these it means clients are issuing credits and closing the connection with pending credits a lot of times");
            return;
         }
         AMQPMessage message = CoreAmqpConverter.checkAMQP(messageReference.getMessage(), sessionSPI.getStorageManager());

         if (sessionSPI.invokeOutgoing(message, (ActiveMQProtonRemotingConnection) sessionSPI.getTransportConnection().getProtocolConnection()) != null) {
            return;
         }
         if (message instanceof AMQPLargeMessage) {
            deliverLarge(messageReference, (AMQPLargeMessage) message);
         } else {
            deliverStandard(messageReference, message);
         }

      } catch (Exception e) {
         log.warn(e.getMessage(), e);
         brokerConsumer.errorProcessing(e, messageReference);
      }
   }
 
Example 6
Source File: SenderImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public int send(final ReadableBuffer buffer)
{
    if (getLocalState() == EndpointState.CLOSED)
    {
        throw new IllegalStateException("send not allowed after the sender is closed.");
    }
    DeliveryImpl current = current();
    if (current == null || current.getLink() != this)
    {
        throw new IllegalArgumentException();
    }
    int sent = current.send(buffer);
    if (sent > 0) {
        getSession().incrementOutgoingBytes(sent);
    }
    return sent;
}
 
Example 7
Source File: SenderImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public int send(final byte[] bytes, int offset, int length)
{
    if (getLocalState() == EndpointState.CLOSED)
    {
        throw new IllegalStateException("send not allowed after the sender is closed.");
    }
    DeliveryImpl current = current();
    if (current == null || current.getLink() != this)
    {
        throw new IllegalArgumentException();//TODO.
    }
    int sent = current.send(bytes, offset, length);
    if (sent > 0) {
        getSession().incrementOutgoingBytes(sent);
    }
    return sent;
}
 
Example 8
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onSessionRemoteClose(Event evt) {
    Session ssn = evt.getSession();
    if (ssn.getLocalState() != EndpointState.CLOSED) {
        ssn.close();
    }
}
 
Example 9
Source File: ProtonServerSenderContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public boolean hasCredits() {
   if (hasLarge) {
      // we will resume accepting once the large message is finished
      return false;
   }

   if (!connection.flowControl(onflowControlReady)) {
      return false;
   }

   synchronized (creditsLock) {
      return credits > 0 && sender.getLocalState() != EndpointState.CLOSED;
   }
}
 
Example 10
Source File: EndpointImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void close()
{
    if (getLocalState() != EndpointState.CLOSED)
    {
        _localState = EndpointState.CLOSED;
        localClose();
        modified();
    }
}
 
Example 11
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void processEnd()
{
    if(_connectionEndpoint != null && _isOpenSent)
    {
        EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
        while(endpoint != null)
        {
            SessionImpl session;
            TransportSession transportSession;

            if((endpoint instanceof SessionImpl)) {
                if ((session = (SessionImpl)endpoint).getLocalState() == EndpointState.CLOSED
                    && (transportSession = session.getTransportSession()).isLocalChannelSet()
                    && !_isCloseSent)
                {
                    if (hasSendableMessages(session)) {
                        endpoint = endpoint.transportNext();
                        continue;
                    }

                    int channel = freeLocalChannel(transportSession);
                    End end = new End();
                    ErrorCondition localError = endpoint.getCondition();
                    if( localError.getCondition() !=null )
                    {
                        end.setError(localError);
                    }

                    writeFrame(channel, end, null, null);
                }

                endpoint.clearModified();
            }

            endpoint = endpoint.transportNext();
        }
    }
}
 
Example 12
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
/**
 * This method is public as it is used by Python layer.
 * @see org.apache.qpid.proton.engine.Transport#input(byte[], int, int)
 */
public TransportResult oldApiCheckStateBeforeInput(int inputLength)
{
    _lastTransportResult.checkIsOk();
    if(inputLength == 0)
    {
        if(_connectionEndpoint == null || _connectionEndpoint.getRemoteState() != EndpointState.CLOSED)
        {
            return TransportResultFactory.error(new TransportException("Unexpected EOS when remote connection not closed: connection aborted"));
        }
    }
    return TransportResultFactory.ok();
}
 
Example 13
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onLinkRemoteClose(Event evt) {
    Link link = evt.getLink();
    if (link.getLocalState() != EndpointState.CLOSED) {
        link.close();
    }
}
 
Example 14
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionRemoteClose(Event evt) {
    Connection conn = evt.getConnection();
    if (conn.getLocalState() != EndpointState.CLOSED) {
        conn.close();
    }
}
 
Example 15
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public long tick(long now)
{
    long deadline = 0;

    if (_localIdleTimeout > 0) {
        if (_localIdleDeadline == 0 || _lastBytesInput != _bytesInput) {
            _localIdleDeadline = computeDeadline(now, _localIdleTimeout);
            _lastBytesInput = _bytesInput;
        } else if (_localIdleDeadline - now <= 0) {
            _localIdleDeadline = computeDeadline(now, _localIdleTimeout);
            if (_connectionEndpoint != null &&
                _connectionEndpoint.getLocalState() != EndpointState.CLOSED) {
                ErrorCondition condition =
                        new ErrorCondition(Symbol.getSymbol("amqp:resource-limit-exceeded"),
                                                            "local-idle-timeout expired");
                _connectionEndpoint.setCondition(condition);
                _connectionEndpoint.setLocalState(EndpointState.CLOSED);

                if (!_isOpenSent) {
                    if ((_sasl != null) && (!_sasl.isDone())) {
                        _sasl.fail();
                    }
                    Open open = new Open();
                    _isOpenSent = true;
                    writeFrame(0, open, null, null);
                }
                if (!_isCloseSent) {
                    Close close = new Close();
                    close.setError(condition);
                    _isCloseSent = true;
                    writeFrame(0, close, null, null);
                }
                close_tail();
            }
        }
        deadline = _localIdleDeadline;
    }

    if (_remoteIdleTimeout != 0 && !_isCloseSent) {
        if (_remoteIdleDeadline == 0 || _lastBytesOutput != _bytesOutput) {
            _remoteIdleDeadline = computeDeadline(now, _remoteIdleTimeout / 2);
            _lastBytesOutput = _bytesOutput;
        } else if (_remoteIdleDeadline - now <= 0) {
            _remoteIdleDeadline = computeDeadline(now, _remoteIdleTimeout / 2);
            if (pending() == 0) {
                writeFrame(0, null, null, null);
                _lastBytesOutput += pending();
            }
        }

        if(deadline == 0) {
            deadline = _remoteIdleDeadline;
        } else {
            if(_remoteIdleDeadline - _localIdleDeadline <= 0) {
                deadline = _remoteIdleDeadline;
            } else {
                deadline = _localIdleDeadline;
            }
        }
    }

    return deadline;
}
 
Example 16
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void processDetach()
{
    if(_connectionEndpoint != null && _isOpenSent)
    {
        EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
        while(endpoint != null)
        {

            if(endpoint instanceof LinkImpl)
            {
                LinkImpl link = (LinkImpl) endpoint;
                TransportLink<?> transportLink = getTransportState(link);
                SessionImpl session = link.getSession();
                TransportSession transportSession = getTransportState(session);

                if(((link.getLocalState() == EndpointState.CLOSED) || link.detached())
                   && transportLink.isLocalHandleSet()
                   && transportSession.isLocalChannelSet()
                   && !_isCloseSent)
                {
                    if((link instanceof SenderImpl)
                       && link.getQueued() > 0
                       && !transportLink.detachReceived()
                       && !transportSession.endReceived()
                       && !_closeReceived) {
                        endpoint = endpoint.transportNext();
                        continue;
                    }

                    UnsignedInteger localHandle = transportLink.getLocalHandle();
                    transportLink.clearLocalHandle();
                    transportSession.freeLocalHandle(localHandle);

                    Detach detach = new Detach();
                    detach.setHandle(localHandle);
                    detach.setClosed(!link.detached());

                    ErrorCondition localError = link.getCondition();
                    if( localError.getCondition() !=null )
                    {
                        detach.setError(localError);
                    }

                    writeFrame(transportSession.getLocalChannel(), detach, null, null);
                }

                endpoint.clearModified();

            }
            endpoint = endpoint.transportNext();
        }
    }
}
 
Example 17
Source File: AmqpAnonymousFallbackProducer.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isComplete() {
    return pendingCloseProducer.getRemoteState() == EndpointState.CLOSED;
}
 
Example 18
Source File: AmqpAbstractResource.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isClosed() {
   return getEndpoint().getLocalState() == EndpointState.CLOSED;
}
 
Example 19
Source File: AMQPSessionCallback.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isWritable(ReadyListener callback, Object protocolContext) {
   ProtonServerSenderContext senderContext = (ProtonServerSenderContext) protocolContext;
   return transportConnection.isWritable(callback) && senderContext.getSender().getLocalState() != EndpointState.CLOSED;
}
 
Example 20
Source File: AmqpAbstractResource.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public boolean isClosed() {
    return getEndpoint().getLocalState() == EndpointState.CLOSED;
}