Java Code Examples for org.apache.qpid.proton.engine.Connection#setHostname()

The following examples show how to use org.apache.qpid.proton.engine.Connection#setHostname() . 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: Pool.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private <T extends Link> T resolve(String remote, String local,
                                   LinkResolver<T> resolver,
                                   LinkConstructor<T> constructor) {
    String host = remote.substring(2).split("/", 2)[0];
    T link = resolver.resolve(remote);
    if (link == null) {
        Connection conn = connections.get(host);
        if (conn == null) {
            conn = Connection.Factory.create();
            conn.collect(collector);
            conn.setHostname(host);
            conn.open();
            connections.put(host, conn);
        }

        Session ssn = conn.session();
        ssn.open();

        link = constructor.create(ssn, remote, local);
        link.open();
    }
    return link;
}
 
Example 2
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testOutputTooBigToBeWrittenInOneGo()
{
    int smallMaxFrameSize = 512;
    _transport = new TransportImpl(smallMaxFrameSize);

    Connection conn = new ConnectionImpl();
    _transport.bind(conn);

    // Open frame sized in order to produce a frame that will almost fill output buffer
    conn.setHostname(stringOfLength("x", 500));
    conn.open();

    // Close the connection to generate a Close frame which will cause an overflow
    // internally - we'll get the remaining bytes on the next interaction.
    conn.close();

    ByteBuffer buf = _transport.getOutputBuffer();
    assertEquals("Expecting buffer to be full", smallMaxFrameSize, buf.remaining());
    buf.position(buf.limit());
    _transport.outputConsumed();

    buf  = _transport.getOutputBuffer();
    assertTrue("Expecting second buffer to have bytes", buf.remaining() > 0);
    assertTrue("Expecting second buffer to not be full", buf.remaining() < Transport.MIN_MAX_FRAME_SIZE);
}
 
Example 3
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 4
Source File: AmqpConnectionBuilder.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected Connection createEndpoint(JmsConnectionInfo resourceInfo) {
    String hostname = getParent().getVhost();
    if (hostname == null) {
        hostname = getParent().getRemoteURI().getHost();
    } else if (hostname.isEmpty()) {
        hostname = null;
    }

    final Map<Symbol, Object> props = new LinkedHashMap<Symbol, Object>();

    if (resourceInfo.getExtensionMap().containsKey(JmsConnectionExtensions.AMQP_OPEN_PROPERTIES)) {
        final Map<String, Object> userConnectionProperties = (Map<String, Object>) resourceInfo.getExtensionMap().get(
            JmsConnectionExtensions.AMQP_OPEN_PROPERTIES).apply(resourceInfo.getConnection(), parent.getTransport().getRemoteLocation());
        if (userConnectionProperties != null && !userConnectionProperties.isEmpty()) {
            userConnectionProperties.forEach((key, value) -> props.put(Symbol.valueOf(key), value));
        }
    }

    // Client properties override anything the user added.
    props.put(AmqpSupport.PRODUCT, MetaDataSupport.PROVIDER_NAME);
    props.put(AmqpSupport.VERSION, MetaDataSupport.PROVIDER_VERSION);
    props.put(AmqpSupport.PLATFORM, MetaDataSupport.PLATFORM_DETAILS);

    Connection connection = getParent().getProtonConnection();
    connection.setHostname(hostname);
    connection.setContainer(resourceInfo.getClientId());
    connection.setDesiredCapabilities(new Symbol[] { SOLE_CONNECTION_CAPABILITY, DELAYED_DELIVERY, ANONYMOUS_RELAY, SHARED_SUBS});
    connection.setProperties(props);

    return connection;
}