Search in sources :

Example 1 with DeliveryState

use of org.apache.qpid.proton.amqp.transport.DeliveryState in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method onDelivery.

/**
     * Event handler for the delivery event. This method handles both sending and receiving a message.
     * @param event The Proton Event object.
     */
@Override
public void onDelivery(Event event) {
    logger.LogDebug("Entered in method %s", logger.getMethodName());
    if (event.getLink().getName().equals(RECEIVE_TAG)) {
        logger.LogInfo("Reading the receiver link, method name is %s ", logger.getMethodName());
        // Codes_SRS_AMQPSIOTHUBCONNECTION_15_034: [If this link is the Receiver link, the event handler shall get the Receiver and Delivery (Proton) objects from the event.]
        Receiver receiveLink = (Receiver) event.getLink();
        Delivery delivery = receiveLink.current();
        if (delivery.isReadable() && !delivery.isPartial()) {
            logger.LogInfo("Reading the received buffer, method name is %s ", logger.getMethodName());
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_035: [The event handler shall read the received buffer.]
            int size = delivery.pending();
            byte[] buffer = new byte[size];
            int read = receiveLink.recv(buffer, 0, buffer.length);
            receiveLink.advance();
            logger.LogInfo("Reading the received buffer completed, method name is %s ", logger.getMethodName());
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_036: [The event handler shall create an AmqpsMessage object from the decoded buffer.]
            AmqpsMessage msg = new AmqpsMessage();
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_037: [The event handler shall set the AmqpsMessage Deliver (Proton) object.]
            msg.setDelivery(delivery);
            logger.LogInfo("Decoding the received message , method name is %s ", logger.getMethodName());
            msg.decode(buffer, 0, read);
            logger.LogInfo("Decoding the received message completed , method name is %s ", logger.getMethodName());
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_049: [All the listeners shall be notified that a message was received from the server.]
            this.messageReceivedFromServer(msg);
        }
    } else {
        //Sender specific section for dispositions it receives
        if (event.getType() == Event.Type.DELIVERY) {
            logger.LogInfo("Reading the delivery event in Sender link, method name is %s ", logger.getMethodName());
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.]
            Delivery d = event.getDelivery();
            DeliveryState remoteState = d.getRemoteState();
            // Codes_SRS_AMQPSIOTHUBCONNECTION_15_039: [The event handler shall note the remote delivery state and use it and the Delivery (Proton) hash code to inform the AmqpsIotHubConnection of the message receipt.]
            boolean state = remoteState.equals(Accepted.getInstance());
            logger.LogInfo("Is state of remote Delivery COMPLETE ? %s, method name is %s ", state, logger.getMethodName());
            logger.LogInfo("Inform listener that a message has been sent to IoT Hub along with remote state, method name is %s ", logger.getMethodName());
            //let any listener know that the message was received by the server
            for (ServerListener listener : listeners) {
                listener.messageSent(d.hashCode(), state);
            }
            // release the delivery object which created in sendMessage().
            d.free();
        }
    }
    logger.LogDebug("Exited from method %s", logger.getMethodName());
}
Also used : DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState)

Example 2 with DeliveryState

use of org.apache.qpid.proton.amqp.transport.DeliveryState in project azure-iot-sdk-java by Azure.

the class AmqpFileUploadNotificationReceivedHandlerTest method createProtonObjects.

private void createProtonObjects() {
    final String exceptionMessage = "Not expected function called";
    message = Proton.message();
    receiver = new Receiver() {

        @Override
        public void flow(int i) {
        }

        @Override
        public int recv(byte[] bytes, int i, int i1) {
            return 0;
        }

        @Override
        public int recv(WritableBuffer writableBuffer) {
            return 0;
        }

        @Override
        public void drain(int i) {
        }

        @Override
        public boolean advance() {
            return false;
        }

        @Override
        public boolean draining() {
            return false;
        }

        @Override
        public void setDrain(boolean b) {
        }

        @Override
        public String getName() {
            return "filenotificationreceiver";
        }

        @Override
        public Delivery delivery(byte[] bytes) {
            return null;
        }

        @Override
        public Delivery delivery(byte[] bytes, int i, int i1) {
            return null;
        }

        @Override
        public Delivery head() {
            return null;
        }

        @Override
        public Delivery current() {
            return delivery;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getTarget() {
            return null;
        }

        @Override
        public void setSource(org.apache.qpid.proton.amqp.transport.Source source) {
        }

        @Override
        public void setTarget(org.apache.qpid.proton.amqp.transport.Target target) {
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getRemoteSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getRemoteTarget() {
            return null;
        }

        @Override
        public Link next(EnumSet<EndpointState> enumSet, EnumSet<EndpointState> enumSet1) {
            return null;
        }

        @Override
        public int getCredit() {
            return 0;
        }

        @Override
        public int getQueued() {
            return 0;
        }

        @Override
        public int getUnsettled() {
            return 0;
        }

        @Override
        public Session getSession() {
            return session;
        }

        @Override
        public SenderSettleMode getSenderSettleMode() {
            return null;
        }

        @Override
        public void setSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public SenderSettleMode getRemoteSenderSettleMode() {
            return null;
        }

        @Override
        public ReceiverSettleMode getReceiverSettleMode() {
            return null;
        }

        @Override
        public void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode) {
        }

        @Override
        public ReceiverSettleMode getRemoteReceiverSettleMode() {
            return null;
        }

        @Override
        public void setRemoteSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public Map<Symbol, Object> getProperties() {
            return null;
        }

        @Override
        public void setProperties(Map<Symbol, Object> map) {
        }

        @Override
        public Map<Symbol, Object> getRemoteProperties() {
            return null;
        }

        @Override
        public int drained() {
            return 0;
        }

        @Override
        public int getRemoteCredit() {
            return 0;
        }

        @Override
        public boolean getDrain() {
            return false;
        }

        @Override
        public void detach() {
        }

        @Override
        public boolean detached() {
            return false;
        }

        @Override
        public void setOfferedCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public void setDesiredCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public EndpointState getLocalState() {
            return null;
        }

        @Override
        public EndpointState getRemoteState() {
            return null;
        }

        @Override
        public ErrorCondition getCondition() {
            return null;
        }

        @Override
        public void setCondition(ErrorCondition errorCondition) {
        }

        @Override
        public ErrorCondition getRemoteCondition() {
            return null;
        }

        @Override
        public void free() {
        }

        @Override
        public void open() {
        }

        @Override
        public void close() {
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
    event = new Event() {

        @Override
        public EventType getEventType() {
            return null;
        }

        @Override
        public Type getType() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Object getContext() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Handler getRootHandler() {
            return null;
        }

        @Override
        public void dispatch(Handler hndlr) throws HandlerException {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public void redispatch(EventType eventType, Handler handler) throws HandlerException {
        }

        @Override
        public void delegate() throws HandlerException {
        }

        @Override
        public Connection getConnection() {
            return connection;
        }

        @Override
        public Session getSession() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public Sender getSender() {
            return null;
        }

        @Override
        public Receiver getReceiver() {
            return null;
        }

        @Override
        public Delivery getDelivery() {
            return delivery;
        }

        @Override
        public Transport getTransport() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Reactor getReactor() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Selectable getSelectable() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Task getTask() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Event copy() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Record attachments() {
            throw new UnsupportedOperationException(exceptionMessage);
        }
    };
    delivery = new Delivery() {

        @Override
        public byte[] getTag() {
            return new byte[0];
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public DeliveryState getLocalState() {
            return null;
        }

        @Override
        public DeliveryState getRemoteState() {
            return null;
        }

        @Override
        public int getMessageFormat() {
            return 0;
        }

        @Override
        public int available() {
            return 0;
        }

        @Override
        public void disposition(DeliveryState deliveryState) {
        }

        @Override
        public void settle() {
        }

        @Override
        public boolean isSettled() {
            return false;
        }

        @Override
        public boolean remotelySettled() {
            return false;
        }

        @Override
        public void free() {
        }

        @Override
        public Delivery getWorkNext() {
            return null;
        }

        @Override
        public Delivery next() {
            return null;
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isReadable() {
            return true;
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public boolean isUpdated() {
            return false;
        }

        @Override
        public void clear() {
        }

        @Override
        public boolean isPartial() {
            return false;
        }

        @Override
        public int pending() {
            return 0;
        }

        @Override
        public boolean isBuffered() {
            return false;
        }

        @Override
        public void setDefaultDeliveryState(DeliveryState deliveryState) {
        }

        @Override
        public DeliveryState getDefaultDeliveryState() {
            return null;
        }

        @Override
        public void setMessageFormat(int i) {
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
}
Also used : Symbol(org.apache.qpid.proton.amqp.Symbol) Source(org.apache.qpid.proton.amqp.messaging.Source) ReceiverSettleMode(org.apache.qpid.proton.amqp.transport.ReceiverSettleMode) Target(org.apache.qpid.proton.amqp.messaging.Target) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpFileUploadNotificationReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceivedHandler) SenderSettleMode(org.apache.qpid.proton.amqp.transport.SenderSettleMode) WritableBuffer(org.apache.qpid.proton.codec.WritableBuffer) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) AmqpFeedbackReceivedEvent(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent) Map(java.util.Map)

Example 3 with DeliveryState

use of org.apache.qpid.proton.amqp.transport.DeliveryState in project azure-iot-sdk-java by Azure.

the class AmqpReceiveHandlerTest method createProtonObjects.

private void createProtonObjects() {
    final String exceptionMessage = "Not expected function called";
    message = Proton.message();
    receiver = new Receiver() {

        @Override
        public void flow(int i) {
        }

        @Override
        public int recv(byte[] bytes, int i, int i1) {
            return 0;
        }

        @Override
        public int recv(WritableBuffer writableBuffer) {
            return 0;
        }

        @Override
        public void drain(int i) {
        }

        @Override
        public boolean advance() {
            return false;
        }

        @Override
        public boolean draining() {
            return false;
        }

        @Override
        public void setDrain(boolean b) {
        }

        @Override
        public String getName() {
            return RECEIVE_TAG;
        }

        @Override
        public Delivery delivery(byte[] bytes) {
            return null;
        }

        @Override
        public Delivery delivery(byte[] bytes, int i, int i1) {
            return null;
        }

        @Override
        public Delivery head() {
            return null;
        }

        @Override
        public Delivery current() {
            return delivery;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getTarget() {
            return null;
        }

        @Override
        public void setSource(org.apache.qpid.proton.amqp.transport.Source source) {
        }

        @Override
        public void setTarget(org.apache.qpid.proton.amqp.transport.Target target) {
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Source getRemoteSource() {
            return null;
        }

        @Override
        public org.apache.qpid.proton.amqp.transport.Target getRemoteTarget() {
            return null;
        }

        @Override
        public Link next(EnumSet<EndpointState> enumSet, EnumSet<EndpointState> enumSet1) {
            return null;
        }

        @Override
        public int getCredit() {
            return 0;
        }

        @Override
        public int getQueued() {
            return 0;
        }

        @Override
        public int getUnsettled() {
            return 0;
        }

        @Override
        public Session getSession() {
            return session;
        }

        @Override
        public SenderSettleMode getSenderSettleMode() {
            return null;
        }

        @Override
        public void setSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public SenderSettleMode getRemoteSenderSettleMode() {
            return null;
        }

        @Override
        public ReceiverSettleMode getReceiverSettleMode() {
            return null;
        }

        @Override
        public void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode) {
        }

        @Override
        public ReceiverSettleMode getRemoteReceiverSettleMode() {
            return null;
        }

        @Override
        public void setRemoteSenderSettleMode(SenderSettleMode senderSettleMode) {
        }

        @Override
        public Map<Symbol, Object> getProperties() {
            return null;
        }

        @Override
        public void setProperties(Map<Symbol, Object> map) {
        }

        @Override
        public Map<Symbol, Object> getRemoteProperties() {
            return null;
        }

        @Override
        public int drained() {
            return 0;
        }

        @Override
        public int getRemoteCredit() {
            return 0;
        }

        @Override
        public boolean getDrain() {
            return false;
        }

        @Override
        public void detach() {
        }

        @Override
        public boolean detached() {
            return false;
        }

        @Override
        public void setOfferedCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteOfferedCapabilities() {
            return new Symbol[0];
        }

        @Override
        public void setDesiredCapabilities(Symbol[] symbols) {
        }

        @Override
        public Symbol[] getDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public Symbol[] getRemoteDesiredCapabilities() {
            return new Symbol[0];
        }

        @Override
        public EndpointState getLocalState() {
            return null;
        }

        @Override
        public EndpointState getRemoteState() {
            return null;
        }

        @Override
        public ErrorCondition getCondition() {
            return null;
        }

        @Override
        public void setCondition(ErrorCondition errorCondition) {
        }

        @Override
        public ErrorCondition getRemoteCondition() {
            return null;
        }

        @Override
        public void free() {
        }

        @Override
        public void open() {
        }

        @Override
        public void close() {
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
    event = new Event() {

        @Override
        public EventType getEventType() {
            return null;
        }

        @Override
        public Event.Type getType() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Object getContext() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Handler getRootHandler() {
            return null;
        }

        @Override
        public void dispatch(Handler hndlr) throws HandlerException {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public void redispatch(EventType eventType, Handler handler) throws HandlerException {
        }

        @Override
        public void delegate() throws HandlerException {
        }

        @Override
        public Connection getConnection() {
            return connection;
        }

        @Override
        public Session getSession() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public Sender getSender() {
            return null;
        }

        @Override
        public Receiver getReceiver() {
            return null;
        }

        @Override
        public Delivery getDelivery() {
            return delivery;
        }

        @Override
        public Transport getTransport() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Reactor getReactor() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Selectable getSelectable() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Task getTask() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Event copy() {
            throw new UnsupportedOperationException(exceptionMessage);
        }

        @Override
        public Record attachments() {
            throw new UnsupportedOperationException(exceptionMessage);
        }
    };
    delivery = new Delivery() {

        @Override
        public byte[] getTag() {
            return new byte[0];
        }

        @Override
        public Link getLink() {
            return receiver;
        }

        @Override
        public DeliveryState getLocalState() {
            return null;
        }

        @Override
        public DeliveryState getRemoteState() {
            return null;
        }

        @Override
        public int getMessageFormat() {
            return 0;
        }

        @Override
        public int available() {
            return 0;
        }

        @Override
        public void disposition(DeliveryState deliveryState) {
        }

        @Override
        public void settle() {
        }

        @Override
        public boolean isSettled() {
            return false;
        }

        @Override
        public boolean remotelySettled() {
            return false;
        }

        @Override
        public void free() {
        }

        @Override
        public Delivery getWorkNext() {
            return null;
        }

        @Override
        public Delivery next() {
            return null;
        }

        @Override
        public boolean isWritable() {
            return false;
        }

        @Override
        public boolean isReadable() {
            return true;
        }

        @Override
        public void setContext(Object o) {
        }

        @Override
        public Object getContext() {
            return null;
        }

        @Override
        public boolean isUpdated() {
            return false;
        }

        @Override
        public void clear() {
        }

        @Override
        public boolean isPartial() {
            return false;
        }

        @Override
        public int pending() {
            return 0;
        }

        @Override
        public boolean isBuffered() {
            return false;
        }

        @Override
        public void setDefaultDeliveryState(DeliveryState deliveryState) {
        }

        @Override
        public DeliveryState getDefaultDeliveryState() {
            return null;
        }

        @Override
        public void setMessageFormat(int i) {
        }

        @Override
        public Record attachments() {
            return null;
        }
    };
}
Also used : Symbol(org.apache.qpid.proton.amqp.Symbol) Source(org.apache.qpid.proton.amqp.messaging.Source) ReceiverSettleMode(org.apache.qpid.proton.amqp.transport.ReceiverSettleMode) Target(org.apache.qpid.proton.amqp.messaging.Target) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) SenderSettleMode(org.apache.qpid.proton.amqp.transport.SenderSettleMode) WritableBuffer(org.apache.qpid.proton.codec.WritableBuffer) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) AmqpFeedbackReceivedEvent(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent) Map(java.util.Map)

Example 4 with DeliveryState

use of org.apache.qpid.proton.amqp.transport.DeliveryState in project azure-iot-sdk-java by Azure.

the class AmqpSendHandler method onDelivery.

@Override
public void onDelivery(Event event) {
    //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_023: [ The event handler shall get the Delivery from the event only if the event type is DELIVERY **]**
    if (event.getType() == Event.Type.DELIVERY) {
        // Codes_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.]
        Delivery d = event.getDelivery();
        //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_024: [ The event handler shall get the Delivery remote state from the delivery **]**
        DeliveryState remoteState = d.getRemoteState();
        //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_025: [ The event handler shall verify the Amqp response and add the response to a queue. **]**
        sendStatusQueue.add(new AmqpResponseVerification(remoteState));
        //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_026: [ The event handler shall settle the delivery. **]**
        d.settle();
        //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_027: [ The event handler shall get the Sender (Proton) object from the event **]**
        Sender snd = event.getSender();
        //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_028: [ The event handler shall close the Sender, Session and Connection **]**
        snd.close();
        snd.getSession().close();
        snd.getSession().getConnection().close();
        isConnected = false;
    }
}
Also used : DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState)

Aggregations

DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)4 AmqpFeedbackReceivedEvent (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedEvent)2 Map (java.util.Map)2 Symbol (org.apache.qpid.proton.amqp.Symbol)2 Source (org.apache.qpid.proton.amqp.messaging.Source)2 Target (org.apache.qpid.proton.amqp.messaging.Target)2 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)2 ReceiverSettleMode (org.apache.qpid.proton.amqp.transport.ReceiverSettleMode)2 SenderSettleMode (org.apache.qpid.proton.amqp.transport.SenderSettleMode)2 WritableBuffer (org.apache.qpid.proton.codec.WritableBuffer)2 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)1 AmqpFileUploadNotificationReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceivedHandler)1