Package org.apache.qpid.amqp_1_0.messaging

Examples of org.apache.qpid.amqp_1_0.messaging.SectionEncoder


    public ProtocolHandler parse(ByteBuffer in)
    {
        try
        {
        Error frameParsingError = null;
        int size = _size;
        State state = _state;
        ByteBuffer oldIn = null;

        while(in.hasRemaining() && state != State.ERROR)
View Full Code Here


    private Error createError(final ErrorCondition framingError,
                              final String description,
                              final Object... args)
    {
        Error error = new Error();
        error.setCondition(framingError);
        Formatter formatter = new Formatter();
        error.setDescription(formatter.format(description, args).toString());
        return error;
    }
View Full Code Here

    private SessionEndpoint getSession(final short channel)
    {
        SessionEndpoint session = _receivingSessions[channel];
        if (session == null)
        {
            Error error = new Error();
            error.setCondition(ConnectionError.FRAMING_ERROR);
            error.setDescription("Frame received on channel " + channel + " which is not known as a begun session.");
            this.handleError(error);
        }
       
        return session;
    }
View Full Code Here

                    catch (JMSException e)
                    {
                    }
                    try
                    {
                        final Error error = end == null ? null : end.getError();
                        final ExceptionListener exceptionListener = _connection.getExceptionListener();
                        if(exceptionListener != null)
                        {
                            if(error != null)
                            {
                                SessionException se = new SessionException(
                                        error.getDescription(),
                                        error.getCondition().getValue().toString());

                                exceptionListener.onException(se);
                            }
                            else
                            {
View Full Code Here

        if(_syncPublish && !action.wasAccepted(_syncPublishTimeout))
        {
            if (action.getOutcome() instanceof Rejected)
            {
                Error err = ((Rejected) action.getOutcome()).getError();
                if(err != null)
                {
                    throw new MessageRejectedException(err.getDescription(), err.getCondition().toString());
                }
                else
                {
                    throw new MessageRejectedException("Message was rejected: " + action.getOutcome());
                }
View Full Code Here

                            actualFilters.put(entry.getKey(), entry.getValue());
                        }
                        catch (ParseException e)
                        {
                            Error error = new Error();
                            error.setCondition(AmqpError.INVALID_FIELD);
                            error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                            error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                            throw new AmqpErrorException(error);
                        }
                        catch (SelectorParsingException e)
                        {
                            Error error = new Error();
                            error.setCondition(AmqpError.INVALID_FIELD);
                            error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                            error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                            throw new AmqpErrorException(error);
                        }


                    }
                }
            }
            source.setFilter(actualFilters.isEmpty() ? null : actualFilters);

            _subscription = new Subscription_1_0(this, qd, source.getDistributionMode() != StdDistMode.COPY);
        }
        else if(destination instanceof ExchangeDestination)
        {
            try
            {

                ExchangeDestination exchangeDestination = (ExchangeDestination) destination;

                boolean isDurable = exchangeDestination.getDurability() == TerminusDurability.CONFIGURATION
                                    || exchangeDestination.getDurability() == TerminusDurability.UNSETTLED_STATE;
                String name;
                if(isDurable)
                {
                    String remoteContainerId = getEndpoint().getSession().getConnection().getRemoteContainerId();
                    remoteContainerId = remoteContainerId.replace("_","__").replace(".", "_:");

                    String endpointName = linkAttachment.getEndpoint().getName();
                    endpointName = endpointName
                                    .replace("_", "__")
                                    .replace(".", "_:")
                                    .replace("(", "_O")
                                    .replace(")", "_C")
                                    .replace("<", "_L")
                                    .replace(">", "_R");
                    name = "qpid_/" + remoteContainerId + "_/" + endpointName;
                }
                else
                {
                    name = UUID.randomUUID().toString();
                }

                queue = _vhost.getQueue(name);
                Exchange exchange = exchangeDestination.getExchange();

                if(queue == null)
                {
                    queue = _vhost.createQueue(
                                UUIDGenerator.generateQueueUUID(name, _vhost.getName()),
                                name,
                                isDurable,
                                null,
                                true,
                                true,
                                true,
                                Collections.EMPTY_MAP);
                }
                else
                {
                    List<Binding> bindings = queue.getBindings();
                    List<Binding> bindingsToRemove = new ArrayList<Binding>();
                    for(Binding existingBinding : bindings)
                    {
                        if(existingBinding.getExchange() != _vhost.getDefaultExchange()
                            && existingBinding.getExchange() != exchange)
                        {
                            bindingsToRemove.add(existingBinding);
                        }
                    }
                    for(Binding existingBinding : bindingsToRemove)
                    {
                        existingBinding.getExchange().removeBinding(existingBinding);
                    }
                }


                String binding = "";

                Map<Symbol,Filter> filters = source.getFilter();
                Map<Symbol,Filter> actualFilters = new HashMap<Symbol,Filter>();
                boolean hasBindingFilter = false;
                if(filters != null && !filters.isEmpty())
                {

                    for(Map.Entry<Symbol,Filter> entry : filters.entrySet())
                    {
                        if(!hasBindingFilter
                           && entry.getValue() instanceof ExactSubjectFilter
                           && exchange.getType() == DirectExchange.TYPE)
                        {
                            ExactSubjectFilter filter = (ExactSubjectFilter) filters.values().iterator().next();
                            source.setFilter(filters);
                            binding = filter.getValue();
                            actualFilters.put(entry.getKey(), entry.getValue());
                            hasBindingFilter = true;
                        }
                        else if(!hasBindingFilter
                                && entry.getValue() instanceof MatchingSubjectFilter
                                && exchange.getType() == TopicExchange.TYPE)
                        {
                            MatchingSubjectFilter filter = (MatchingSubjectFilter) filters.values().iterator().next();
                            source.setFilter(filters);
                            binding = filter.getValue();
                            actualFilters.put(entry.getKey(), entry.getValue());
                            hasBindingFilter = true;
                        }
                        else if(entry.getValue() instanceof NoLocalFilter)
                        {
                            actualFilters.put(entry.getKey(), entry.getValue());
                            noLocal = true;
                        }
                        else if(messageFilter == null && entry.getValue() instanceof org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter)
                        {

                            org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter) entry.getValue();
                            try
                            {
                                messageFilter = new JMSSelectorFilter(selectorFilter.getValue());

                                actualFilters.put(entry.getKey(), entry.getValue());
                            }
                            catch (ParseException e)
                            {
                                Error error = new Error();
                                error.setCondition(AmqpError.INVALID_FIELD);
                                error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                                error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                                throw new AmqpErrorException(error);
                            }
                            catch (SelectorParsingException e)
                            {
                                Error error = new Error();
                                error.setCondition(AmqpError.INVALID_FIELD);
                                error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                                error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                                throw new AmqpErrorException(error);
                            }


                        }
View Full Code Here

           
            return session;
        }
        catch(JMSException e)
        {
            Error remoteError;
            if(started
               && e.getLinkedException() instanceof ConnectionErrorException
               && (remoteError = ((ConnectionErrorException)e.getLinkedException()).getRemoteError()).getCondition() == ConnectionError.REDIRECT)
            {
                String networkHost = (String) remoteError.getInfo().get(Symbol.valueOf("network-host"));
                int port = (Integer) remoteError.getInfo().get(Symbol.valueOf("port"));
                String hostName = (String) remoteError.getInfo().get(Symbol.valueOf("hostname"));
                reconnect(networkHost,port,hostName);
                return createSession(acknowledgeMode);

            }
            else
View Full Code Here

        AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance()
                .registerTransportLayer()
                .registerMessagingLayer()
                .registerTransactionLayer();

        Open open = new Open();
        // Open(container_id="venture", channel_max=10, hostname="foo", offered_capabilities=[Symbol("one"), Symbol("two"), Symbol("three")])
        open.setContainerId("venture");
        open.setChannelMax(UnsignedShort.valueOf((short) 10));
        open.setHostname("foo");
        open.setOfferedCapabilities(new Symbol[] {Symbol.valueOf("one"),Symbol.valueOf("two"),Symbol.valueOf("three")});

        ValueWriter<Open> writer = registry.getValueWriter(open);

        System.out.println("------ Encode (time in ms for 1 million opens)");
        Long myLong = Long.valueOf(32);
View Full Code Here

        {
            final MessageConverter converter = MessageConverterRegistry.getConverter(serverMessage.getClass(), Message_1_0.class);
            message = (Message_1_0) converter.convert(serverMessage, queueEntry.getQueue().getVirtualHost());
        }

        Transfer transfer = new Transfer();
        //TODO


        List<ByteBuffer> fragments = message.getFragments();
        ByteBuffer payload;
        if(fragments.size() == 1)
        {
            payload = fragments.get(0);
        }
        else
        {
            int size = 0;
            for(ByteBuffer fragment : fragments)
            {
                size += fragment.remaining();
            }

            payload = ByteBuffer.allocate(size);

            for(ByteBuffer fragment : fragments)
            {
                payload.put(fragment.duplicate());
            }

            payload.flip();
        }

        if(queueEntry.getDeliveryCount() != 0)
        {
            payload = payload.duplicate();
            ValueHandler valueHandler = new ValueHandler(_typeRegistry);

            Header oldHeader = null;
            try
            {
                ByteBuffer encodedBuf = payload.duplicate();
                Object value = valueHandler.parse(payload);
                if(value instanceof Header)
                {
                    oldHeader = (Header) value;
                }
                else
                {
                    payload.position(0);
                }
            }
            catch (AmqpErrorException e)
            {
                //TODO
                throw new RuntimeException(e);
            }

            Header header = new Header();
            if(oldHeader != null)
            {
                header.setDurable(oldHeader.getDurable());
                header.setPriority(oldHeader.getPriority());
                header.setTtl(oldHeader.getTtl());
            }
            header.setDeliveryCount(UnsignedInteger.valueOf(queueEntry.getDeliveryCount()));
            _sectionEncoder.reset();
            _sectionEncoder.encodeObject(header);
            Binary encodedHeader = _sectionEncoder.getEncoding();

            ByteBuffer oldPayload = payload;
            payload = ByteBuffer.allocate(oldPayload.remaining() + encodedHeader.getLength());
            payload.put(encodedHeader.getArray(),encodedHeader.getArrayOffset(),encodedHeader.getLength());
            payload.put(oldPayload);
            payload.flip();
        }

        transfer.setPayload(payload);
        byte[] data = new byte[8];
        ByteBuffer.wrap(data).putLong(_deliveryTag++);
        final Binary tag = new Binary(data);

        transfer.setDeliveryTag(tag);

        synchronized(_link.getLock())
        {
            if(_link.isAttached())
            {
                if(SenderSettleMode.SETTLED.equals(getEndpoint().getSendingSettlementMode()))
                {
                    transfer.setSettled(true);
                }
                else
                {
                    UnsettledAction action = _acquires
                                             ? new DispositionAction(tag, queueEntry)
                                             : new DoNothingAction(tag, queueEntry);

                    _link.addUnsettled(tag, action, queueEntry);
                }

                if(_transactionId != null)
                {
                    TransactionalState state = new TransactionalState();
                    state.setTxnId(_transactionId);
                    transfer.setState(state);
                }
                // TODO - need to deal with failure here
                if(_acquires && _transactionId != null)
                {
                    ServerTransaction txn = _link.getTransaction(_transactionId);
View Full Code Here

        {
            Accepted accepted = new Accepted();
            synchronized(getLock())
            {

                Transfer xfr = new Transfer();
                Binary dt = _resumeAcceptedTransfers.remove(0);
                xfr.setDeliveryTag(dt);
                xfr.setState(accepted);
                xfr.setResume(Boolean.TRUE);
                getEndpoint().transfer(xfr);
            }

        }
        if(_resumeAcceptedTransfers.isEmpty())
View Full Code Here

TOP

Related Classes of org.apache.qpid.amqp_1_0.messaging.SectionEncoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.