Java Code Examples for org.apache.qpid.proton.amqp.messaging.Target#setAddress()

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Target#setAddress() . 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: HonoConnectionImplTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Verifies that the attempt to create a sender succeeds when sender never gets credits.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testCreateSenderThatGetsNoCredits(final VertxTestContext ctx) {
    final ProtonSender sender = mock(ProtonSender.class);
    when(sender.isOpen()).thenReturn(Boolean.TRUE);
    when(con.createSender(anyString())).thenReturn(sender);
    final Target target = new Target();
    target.setAddress("someAddress");
    when(sender.getRemoteTarget()).thenReturn(target);
    when(sender.getCredit()).thenReturn(0);
    // just invoke openHandler with succeeded future
    doAnswer(AdditionalAnswers.answerVoid(
            (final Handler<AsyncResult<ProtonSender>> handler) -> handler.handle(Future.succeededFuture(sender))))
                    .when(sender).openHandler(VertxMockSupport.anyHandler());
    final Handler<String> remoteCloseHook = VertxMockSupport.mockHandler();

    // GIVEN an established connection
    honoConnection.connect()
        .compose(c -> honoConnection.createSender(
            "target", ProtonQoS.AT_LEAST_ONCE, remoteCloseHook))
        .onComplete(ctx.succeeding(s -> {
                ctx.verify(() -> {
                    assertThat(s).isEqualTo(sender);
                    // sendQueueDrainHandler gets unset
                    verify(sender).sendQueueDrainHandler(null);
                });
                ctx.completeNow();
            }));
}
 
Example 2
Source File: HonoConnectionImplTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Verifies that the attempt to create a sender fails with a
 * {@code ServerErrorException} if the connection gets disconnected
 * before the remote peer has sent its attach frame. It is verified
 * that this is done before the link establishment timeout.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testCreateSenderFailsOnDisconnectBeforeOpen(final VertxTestContext ctx) {
    final long linkEstablishmentTimeout = 444L; // choose a distinct value here
    props.setLinkEstablishmentTimeout(linkEstablishmentTimeout);
    // don't run linkEstablishmentTimeout timer handler
    when(vertx.setTimer(eq(linkEstablishmentTimeout), VertxMockSupport.anyHandler())).thenAnswer(invocation -> 0L);

    final ProtonSender sender = mock(ProtonSender.class);
    when(sender.isOpen()).thenReturn(Boolean.TRUE);
    when(con.createSender(anyString())).thenReturn(sender);
    final Target target = new Target();
    target.setAddress("someAddress");
    when(sender.getRemoteTarget()).thenReturn(target);
    when(sender.getCredit()).thenReturn(0);
    // mock handlers
    final Handler<String> remoteCloseHook = VertxMockSupport.mockHandler();

    // GIVEN an established connection
    honoConnection.connect()
        .compose(c -> {
            // WHEN creating a sender link with a close hook
            final Future<ProtonSender> result = honoConnection.createSender(
                    "target", ProtonQoS.AT_LEAST_ONCE, remoteCloseHook);
            // THEN the result is not completed at first
            ctx.verify(() -> assertThat(result.isComplete()).isFalse());
            // WHEN the downstream connection fails
            connectionFactory.getDisconnectHandler().handle(con);
            return result;
        })
        // THEN the attempt is failed
        .onComplete(ctx.failing(t -> {
            ctx.verify(() -> assertThat(((ServerErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_UNAVAILABLE));
            ctx.completeNow();
        }));
}
 
Example 3
Source File: Pool.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public Sender newOutgoing(Session ssn, String remote, String local) {
    Sender snd = ssn.sender(String.format("%s-%s", local, remote));
    Source src = new Source();
    src.setAddress(local);
    snd.setSource(src);
    Target tgt = new Target();
    tgt.setAddress(remote);
    snd.setTarget(tgt);
    return snd;
}
 
Example 4
Source File: Pool.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public Receiver newIncoming(Session ssn, String remote, String local) {
    Receiver rcv = ssn.receiver(String.format("%s-%s", remote, local));
    Source src = new Source();
    src.setAddress(remote);
    rcv.setSource(src);
    Target tgt = new Target();
    tgt.setAddress(remote);
    rcv.setTarget(tgt);
    return rcv;
}
 
Example 5
Source File: ProtonSessionImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public ProtonSender createSender(String address, ProtonLinkOptions senderOptions) {
  Sender sender = session.sender(getOrCreateLinkName(senderOptions));

  Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL,
      Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
  Source source = new Source();
  source.setOutcomes(outcomes);

  Target target = new Target();
  target.setAddress(address);
  if(senderOptions.isDynamic()) {
    target.setDynamic(true);
  }

  sender.setSource(source);
  sender.setTarget(target);

  ProtonSenderImpl s = new ProtonSenderImpl(sender);
  if (address == null) {
    s.setAnonymousSender(true);
  }

  s.openHandler((result) -> {
    LOG.trace("Sender open completed");
  });
  s.closeHandler((result) -> {
    if (result.succeeded()) {
      LOG.trace("Sender closed");
    } else {
      LOG.warn("Sender closed with error", result.cause());
    }
  });

  // Default to at-least-once
  s.setQoS(ProtonQoS.AT_LEAST_ONCE);

  return s;
}
 
Example 6
Source File: AmqpProducerBuilder.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected Sender createEndpoint(JmsProducerInfo resourceInfo) {
    JmsDestination destination = resourceInfo.getDestination();
    AmqpConnection connection = getParent().getConnection();

    String targetAddress = AmqpDestinationHelper.getDestinationAddress(destination, connection);

    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
    String sourceAddress = resourceInfo.getId().toString();
    Source source = new Source();
    source.setAddress(sourceAddress);
    source.setOutcomes(outcomes);
    // TODO: default outcome. Accepted normally, Rejected for transaction controller?

    Target target = new Target();
    target.setAddress(targetAddress);
    Symbol typeCapability =  AmqpDestinationHelper.toTypeCapability(destination);
    if (typeCapability != null) {
        target.setCapabilities(typeCapability);
    }

    String senderName = "qpid-jms:sender:" + sourceAddress + ":" + targetAddress;

    Sender sender = getParent().getEndpoint().sender(senderName);
    sender.setSource(source);
    sender.setTarget(target);
    if (resourceInfo.isPresettle()) {
        sender.setSenderSettleMode(SenderSettleMode.SETTLED);
    } else {
        sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    }
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    if (!connection.getProperties().isDelayedDeliverySupported()) {
        validateDelayedDeliveryLinkCapability = true;
        sender.setDesiredCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
    }

    return sender;
}
 
Example 7
Source File: VertxBasedAmqpProtocolAdapterTest.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
private Target getTarget(final ResourceIdentifier resource) {
    final Target target = new Target();
    target.setAddress(resource.toString());
    return target;
}
 
Example 8
Source File: QueueTerminusFactory.java    From enmasse with Apache License 2.0 4 votes vote down vote up
@Override
public Target getTarget(String address) {
    Target target = new Target();
    target.setAddress(address);
    return target;
}
 
Example 9
Source File: TargetType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Target newInstance(Object described)
{
    List l = (List) described;

    Target o = new Target();


    switch(7 - l.size())
    {

        case 0:
            Object val0 = l.get( 6 );
            if( val0 == null || val0.getClass().isArray() )
            {
                o.setCapabilities( (Symbol[]) val0 );
            }
            else
            {
                o.setCapabilities( (Symbol) val0 );
            }
        case 1:
            o.setDynamicNodeProperties( (Map) l.get( 5 ) );
        case 2:
            Boolean dynamic = (Boolean) l.get(4);
            o.setDynamic(dynamic == null ? false : dynamic);
        case 3:
            UnsignedInteger timeout = (UnsignedInteger) l.get(3);
            o.setTimeout(timeout == null ? UnsignedInteger.ZERO : timeout);
        case 4:
            Symbol expiryPolicy = (Symbol) l.get(2);
            o.setExpiryPolicy(expiryPolicy == null ? TerminusExpiryPolicy.SESSION_END : TerminusExpiryPolicy.valueOf(expiryPolicy));
        case 5:
            UnsignedInteger durable = (UnsignedInteger) l.get(1);
            o.setDurable(durable == null ? TerminusDurability.NONE : TerminusDurability.get(durable));
        case 6:
            o.setAddress( (String) l.get( 0 ) );
    }


    return o;
}
 
Example 10
Source File: LinkTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testMaxMessageSizeValue() throws Exception
{
    LOGGER.fine(bold("======== About to create transports"));

    Transport clientTransport = Proton.transport();
    getClient().setTransport(clientTransport);
    ProtocolTracerEnabler.setProtocolTracer(clientTransport, TestLoggingHelper.CLIENT_PREFIX);

    Transport serverTransport = Proton.transport();
    getServer().setTransport(serverTransport);
    ProtocolTracerEnabler.setProtocolTracer(serverTransport, "            " + TestLoggingHelper.SERVER_PREFIX);

    doOutputInputCycle();

    Connection clientConnection = Proton.connection();
    getClient().setConnection(clientConnection);
    clientTransport.bind(clientConnection);

    Connection serverConnection = Proton.connection();
    getServer().setConnection(serverConnection);
    serverTransport.bind(serverConnection);

    LOGGER.fine(bold("======== About to open connections"));
    clientConnection.open();
    serverConnection.open();

    doOutputInputCycle();

    LOGGER.fine(bold("======== About to open sessions"));
    Session clientSession = clientConnection.session();
    getClient().setSession(clientSession);
    clientSession.open();

    pumpClientToServer();

    Session serverSession = serverConnection.sessionHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSession(serverSession);

    serverSession.open();

    pumpServerToClient();

    LOGGER.fine(bold("======== About to create receiver"));

    Source clientSource = new Source();
    getClient().setSource(clientSource);
    clientSource.setAddress(_sourceAddress);

    Target clientTarget = new Target();
    getClient().setTarget(clientTarget);
    clientTarget.setAddress(null);

    Receiver clientReceiver = clientSession.receiver("link1");
    getClient().setReceiver(clientReceiver);
    clientReceiver.setTarget(clientTarget);
    clientReceiver.setSource(clientSource);

    clientReceiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    clientReceiver.setSenderSettleMode(SenderSettleMode.UNSETTLED);

    // Set the local link max-message-size
    assertNull("Expected no value to be set", clientReceiver.getMaxMessageSize());
    clientReceiver.setMaxMessageSize(CLIENT_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, clientReceiver.getMaxMessageSize());

    clientReceiver.open();
    pumpClientToServer();

    LOGGER.fine(bold("======== About to set up implicitly created sender"));

    Sender serverSender = (Sender) getServer().getConnection().linkHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSender(serverSender);

    serverSender.setReceiverSettleMode(serverSender.getRemoteReceiverSettleMode());
    serverSender.setSenderSettleMode(serverSender.getRemoteSenderSettleMode());

    org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = serverSender.getRemoteSource();
    serverSender.setSource(serverRemoteSource);

    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, serverSender.getRemoteMaxMessageSize());

    // Set the local link max-message-size
    assertNull("Expected no value to be set", serverSender.getMaxMessageSize());
    serverSender.setMaxMessageSize(SERVER_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, serverSender.getMaxMessageSize());

    serverSender.open();

    assertNull("Expected no value to be present yet", clientReceiver.getRemoteMaxMessageSize());

    pumpServerToClient();

    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, clientReceiver.getRemoteMaxMessageSize());
}