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

The following examples show how to use org.apache.qpid.proton.engine.EndpointState#UNINITIALIZED . 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: 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 2
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onSessionRemoteOpen(Event evt) {
    Session ssn = evt.getSession();
    if (ssn.getLocalState() == EndpointState.UNINITIALIZED) {
        ssn.open();
    }
}
 
Example 3
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onLinkRemoteOpen(Event evt) {
    Link link = evt.getLink();
    if (link.getLocalState() == EndpointState.UNINITIALIZED) {
        link.setSource(link.getRemoteSource());
        link.setTarget(link.getRemoteTarget());
        link.open();
    }
}
 
Example 4
Source File: Driver.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionLocalOpen(Event evt) {
    Connection conn = evt.getConnection();
    if (conn.getRemoteState() == EndpointState.UNINITIALIZED) {
        // Give the connection a [random] container-id
        conn.setContainer(UUID.randomUUID().toString());
        try {
            new Connector(conn);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 5
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionRemoteOpen(Event evt) {
    Connection conn = evt.getConnection();
    if (conn.getLocalState() == EndpointState.UNINITIALIZED) {
        conn.open();
    }
}
 
Example 6
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void processOpen()
{
    if (!_isOpenSent && (_conditionSet ||
         (_connectionEndpoint != null &&
          _connectionEndpoint.getLocalState() != EndpointState.UNINITIALIZED)))
    {
        Open open = new Open();
        if (_connectionEndpoint != null) {
            String cid = _connectionEndpoint.getLocalContainerId();
            open.setContainerId(cid == null ? "" : cid);
            open.setHostname(_connectionEndpoint.getHostname());
            open.setDesiredCapabilities(_connectionEndpoint.getDesiredCapabilities());
            open.setOfferedCapabilities(_connectionEndpoint.getOfferedCapabilities());
            open.setProperties(_connectionEndpoint.getProperties());
        } else {
            open.setContainerId("");
        }

        if (_maxFrameSize > 0) {
            open.setMaxFrameSize(UnsignedInteger.valueOf(_maxFrameSize));
        }
        if (_channelMax > 0) {
            open.setChannelMax(UnsignedShort.valueOf((short) _channelMax));
        }

        // as per the recommendation in the spec, advertise half our
        // actual timeout to the remote
        if (_localIdleTimeout > 0) {
            open.setIdleTimeOut(new UnsignedInteger(_localIdleTimeout / 2));
        }
        _isOpenSent = true;

        writeFrame(0, open, null, null);
    }
}
 
Example 7
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onLinkRemoteOpen(Event event) {
    Link link = event.getLink();
    if (link.getLocalState() == EndpointState.UNINITIALIZED) {
        if (link.getRemoteSource() != null) {
            link.setSource(link.getRemoteSource().copy());
        }
        if (link.getRemoteTarget() != null) {
            link.setTarget(link.getRemoteTarget().copy());
        }
    }
    open(link);
}
 
Example 8
Source File: IOHandler.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void handleOpen(Reactor reactor, Event event) {
    Connection connection = event.getConnection();
    if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
        return;
    }
    // Outgoing Reactor connections set the virtual host automatically using the
    // following rules:
    String vhost = connection.getHostname();
    if (vhost == null) {
        // setHostname never called, use the host from the connection's
        // socket address as the default virtual host:
        String conAddr = reactor.getConnectionAddress(connection);
        if (conAddr != null) {
            Address addr = new Address(conAddr);
            connection.setHostname(addr.getHost());
        }
    } else if (vhost.isEmpty()) {
        // setHostname called explictly with a null string. This allows
        // the application to completely avoid sending a virtual host
        // name
        connection.setHostname(null);
    } else {
        // setHostname set by application - use it.
    }
    Transport transport = Proton.transport();

    int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
    if (maxFrameSizeOption != 0) {
        transport.setMaxFrameSize(maxFrameSizeOption);
    }

    if (reactor.getOptions().isEnableSaslByDefault()) {
        Sasl sasl = transport.sasl();
        sasl.client();
        sasl.setMechanisms("ANONYMOUS");
    }

    transport.bind(connection);
}
 
Example 9
Source File: AmqpResourceBuilder.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
/**
 * Called to initiate the process of building the resource type that is
 * managed by this builder.  The resource is created and the open process
 * occurs asynchronously.  If the resource is successfully opened it will
 * added to its parent resource for use.
 *
 * @param request
 *      The request that initiated the resource creation.
 */
public void buildResource(final AsyncResult request) {
    this.request = request;

    // Create the local end of the manage resource.
    endpoint = createEndpoint(resourceInfo);
    endpoint.setContext(this);
    endpoint.open();

    // Create the resource object now
    resource = createResource(parent, resourceInfo, endpoint);

    AmqpProvider provider = parent.getProvider();

    if (getRequestTimeout() > JmsConnectionInfo.INFINITE) {

        // Attempt to schedule a cancellation of the pending open request, can return
        // null if there is no configured request timeout.
        requestTimeoutTask = provider.scheduleRequestTimeout(new AsyncResult() {

            @Override
            public void onSuccess() {
                // Nothing to do here.
            }

            @Override
            public void onFailure(ProviderException result) {
                handleClosed(provider, result);
            }

            @Override
            public boolean isComplete() {
                return request.isComplete();
            }

        }, getRequestTimeout(), this);
    }

    // Check it wasn't already opened, if it is then handle it
    if (endpoint.getRemoteState() != EndpointState.UNINITIALIZED) {
        provider.scheduleExecuteAndPump(new Runnable() {
            @Override
            public void run() {
                handleOpened(provider);
            }
        });
    }
}
 
Example 10
Source File: AmqpAbstractResource.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public EndpointState getRemoteState() {
    if (getEndpoint() == null) {
        return EndpointState.UNINITIALIZED;
    }
    return getEndpoint().getRemoteState();
}
 
Example 11
Source File: AmqpAbstractResource.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public EndpointState getLocalState() {
    if (getEndpoint() == null) {
        return EndpointState.UNINITIALIZED;
    }
    return getEndpoint().getLocalState();
}
 
Example 12
Source File: AmqpAbstractResource.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public EndpointState getRemoteState() {
   if (getEndpoint() == null) {
      return EndpointState.UNINITIALIZED;
   }
   return getEndpoint().getRemoteState();
}
 
Example 13
Source File: AmqpAbstractResource.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public EndpointState getLocalState() {
   if (getEndpoint() == null) {
      return EndpointState.UNINITIALIZED;
   }
   return getEndpoint().getLocalState();
}
 
Example 14
Source File: Handshaker.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void open(Endpoint endpoint) {
    if (endpoint.getLocalState() == EndpointState.UNINITIALIZED) {
        endpoint.open();
    }
}
 
Example 15
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHandlingFrames()
{
    return _connectionEndpoint != null || getRemoteState() == EndpointState.UNINITIALIZED;
}
 
Example 16
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void processBegin()
{
    if(_connectionEndpoint != null && _isOpenSent && !_isCloseSent)
    {
        EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
        while(endpoint != null)
        {
            if(endpoint instanceof SessionImpl)
            {
                SessionImpl session = (SessionImpl) endpoint;
                TransportSession transportSession = getTransportState(session);
                if(session.getLocalState() != EndpointState.UNINITIALIZED && !transportSession.beginSent())
                {
                    int channelId = allocateLocalChannel(transportSession);
                    Begin begin = new Begin();

                    if(session.getRemoteState() != EndpointState.UNINITIALIZED)
                    {
                        begin.setRemoteChannel(UnsignedShort.valueOf((short) transportSession.getRemoteChannel()));
                    }

                    transportSession.updateIncomingWindow();

                    begin.setHandleMax(transportSession.getHandleMax());
                    begin.setIncomingWindow(transportSession.getIncomingWindowSize());
                    begin.setOutgoingWindow(transportSession.getOutgoingWindowSize());
                    begin.setNextOutgoingId(transportSession.getNextOutgoingId());

                    if(session.getProperties() != null)
                    {
                        begin.setProperties(session.getProperties());
                    }

                    if(session.getOfferedCapabilities() != null)
                    {
                        begin.setOfferedCapabilities(session.getOfferedCapabilities());
                    }

                    if(session.getDesiredCapabilities() != null)
                    {
                        begin.setDesiredCapabilities(session.getDesiredCapabilities());
                    }

                    writeFrame(channelId, begin, null, null);
                    transportSession.sentBegin();
                }
            }
            endpoint = endpoint.transportNext();
        }
    }
}
 
Example 17
Source File: TransportImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void processAttach()
{
    if(_connectionEndpoint != null && _isOpenSent && !_isCloseSent)
    {
        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.UNINITIALIZED && !transportLink.attachSent() && transportSession.isLocalChannelSet())
                {

                    if( (link.getRemoteState() == EndpointState.ACTIVE
                        && !transportLink.isLocalHandleSet()) || link.getRemoteState() == EndpointState.UNINITIALIZED)
                    {

                        UnsignedInteger localHandle = transportSession.allocateLocalHandle(transportLink);

                        if(link.getRemoteState() == EndpointState.UNINITIALIZED)
                        {
                            transportSession.addHalfOpenLink(transportLink);
                        }

                        Attach attach = new Attach();
                        attach.setHandle(localHandle);
                        attach.setName(transportLink.getName());

                        if(link.getSenderSettleMode() != null)
                        {
                            attach.setSndSettleMode(link.getSenderSettleMode());
                        }

                        if(link.getReceiverSettleMode() != null)
                        {
                            attach.setRcvSettleMode(link.getReceiverSettleMode());
                        }

                        if(link.getSource() != null)
                        {
                            attach.setSource(link.getSource());
                        }

                        if(link.getTarget() != null)
                        {
                            attach.setTarget(link.getTarget());
                        }

                        if(link.getProperties() != null)
                        {
                            attach.setProperties(link.getProperties());
                        }

                        if(link.getOfferedCapabilities() != null)
                        {
                            attach.setOfferedCapabilities(link.getOfferedCapabilities());
                        }

                        if(link.getDesiredCapabilities() != null)
                        {
                            attach.setDesiredCapabilities(link.getDesiredCapabilities());
                        }

                        if(link.getMaxMessageSize() != null)
                        {
                            attach.setMaxMessageSize(link.getMaxMessageSize());
                        }

                        attach.setRole(endpoint instanceof ReceiverImpl ? Role.RECEIVER : Role.SENDER);

                        if(link instanceof SenderImpl)
                        {
                            attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
                        }

                        writeFrame(transportSession.getLocalChannel(), attach, null, null);
                        transportLink.sentAttach();
                    }
                }
            }
            endpoint = endpoint.transportNext();
        }
    }
}