org.apache.qpid.proton.amqp.transaction.Coordinator Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.transaction.Coordinator. 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: CoordinatorType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public Coordinator newInstance(Object described)
{
    List l = (List) described;

    Coordinator o = new Coordinator();


    switch(1 - l.size())
    {

        case 0:
            Object val0 = l.get( 0 );
            if( val0 == null || val0.getClass().isArray() )
            {
                o.setCapabilities( (Symbol[]) val0 );
            }
            else
            {
                o.setCapabilities( (Symbol) val0 );
            }
    }


    return o;
}
 
Example #2
Source File: AmqpTransactionCoordinator.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOpen() {
   Coordinator coordinator = new Coordinator();
   coordinator.setCapabilities(TxnCapability.LOCAL_TXN);
   Source source = new Source();

   String coordinatorName = "qpid-jms:coordinator:" + session.getConnection().getConnectionId();

   Sender sender = session.getEndpoint().sender(coordinatorName);
   sender.setSource(source);
   sender.setTarget(coordinator);
   sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
   sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

   setEndpoint(sender);

   super.doOpen();
}
 
Example #3
Source File: AmqpSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Given an AMQP endpoint, deduce the appropriate ActiveMQDestination type and create
 * a new instance.  By default if the endpoint address does not carry the standard prefix
 * value then we default to a Queue type destination.  If the endpoint is null or is an
 * AMQP Coordinator type endpoint this method returns null to indicate no destination
 * can be mapped.
 *
 * @param endpoint the AMQP endpoint to construct an ActiveMQDestination from.
 * @return a new ActiveMQDestination that best matches the address of the given endpoint
 * @throws AmqpProtocolException if an error occurs while deducing the destination type.
 */
public static ActiveMQDestination createDestination(Object endpoint) throws AmqpProtocolException {
   if (endpoint == null) {
      return null;
   } else if (endpoint instanceof Coordinator) {
      return null;
   } else if (endpoint instanceof org.apache.qpid.proton.amqp.messaging.Terminus) {
      org.apache.qpid.proton.amqp.messaging.Terminus terminus = (org.apache.qpid.proton.amqp.messaging.Terminus) endpoint;
      if (terminus.getAddress() == null || terminus.getAddress().length() == 0) {
         if (terminus instanceof org.apache.qpid.proton.amqp.messaging.Source) {
            throw new AmqpProtocolException("amqp:invalid-field", "source address not set");
         } else {
            throw new AmqpProtocolException("amqp:invalid-field", "target address not set");
         }
      }

      return ActiveMQDestination.createDestination(terminus.getAddress(), ActiveMQDestination.QUEUE_TYPE);
   } else {
      throw new RuntimeException("Unexpected terminus type: " + endpoint);
   }
}
 
Example #4
Source File: AMQPConnectionContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void remoteLinkOpened(Link link) throws Exception {

      AMQPSessionContext protonSession = getSessionExtension(link.getSession());

      link.setSource(link.getRemoteSource());
      link.setTarget(link.getRemoteTarget());
      if (link instanceof Receiver) {
         Receiver receiver = (Receiver) link;
         if (link.getRemoteTarget() instanceof Coordinator) {
            Coordinator coordinator = (Coordinator) link.getRemoteTarget();
            protonSession.addTransactionHandler(coordinator, receiver);
         } else {
            protonSession.addReceiver(receiver);
         }
      } else {
         Sender sender = (Sender) link;
         protonSession.addSender(sender);
      }
   }
 
Example #5
Source File: AmqpTransactionCoordinatorBuilder.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
protected Sender createEndpoint(JmsSessionInfo resourceInfo) {
    Coordinator coordinator = new Coordinator();
    coordinator.setCapabilities(TxnCapability.LOCAL_TXN);

    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };

    Source source = new Source();
    source.setOutcomes(outcomes);

    String coordinatorName = "qpid-jms:coordinator:" + resourceInfo.getId().toString();

    Sender sender = getParent().getSession().getEndpoint().sender(coordinatorName);
    sender.setSource(source);
    sender.setTarget(coordinator);
    sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    return sender;
}
 
Example #6
Source File: CoordinatorType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
protected List wrap(Coordinator val)
{
    Symbol[] capabilities = val.getCapabilities();
    return capabilities == null || capabilities.length == 0
            ? Collections.EMPTY_LIST
            : Collections.singletonList(capabilities);
}
 
Example #7
Source File: AMQPSessionContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void addTransactionHandler(Coordinator coordinator, Receiver receiver) {
   ProtonTransactionHandler transactionHandler = new ProtonTransactionHandler(sessionSPI, connection);

   coordinator.setCapabilities(Symbol.getSymbol("amqp:local-transactions"), Symbol.getSymbol("amqp:multi-txns-per-ssn"), Symbol.getSymbol("amqp:multi-ssns-per-txn"));

   receiver.setContext(transactionHandler);
   connection.runNow(() -> {
      receiver.open();
      receiver.flow(connection.getAmqpCredits());
      connection.flush();
   });
}
 
Example #8
Source File: CoordinatorType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Class<Coordinator> getTypeClass()
{
    return Coordinator.class;
}