1 /* 2 * hunt-proton: AMQP Protocol library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.proton.engine.Delivery; 13 14 import hunt.proton.amqp.transport.DeliveryState; 15 import hunt.proton.engine.Link; 16 import hunt.proton.engine.Extendable; 17 /** 18 * A delivery of a message on a particular link. 19 * 20 * Whilst a message is logically a long-lived object, a delivery is short-lived - it 21 * is only intended to be used by the application until it is settled and all its data has been read. 22 */ 23 interface Delivery : Extendable 24 { 25 26 public byte[] getTag(); 27 28 public Link getLink(); 29 30 public DeliveryState getLocalState(); 31 32 public DeliveryState getRemoteState(); 33 34 /** 35 * updates the state of the delivery 36 * 37 * The new state may have no on-the-wire effect, if delivery settlement was already communicated to/from the peer. 38 * 39 * @param state the new delivery state 40 */ 41 public void disposition(DeliveryState state); 42 43 /** 44 * Settles this delivery. 45 * 46 * Causes the delivery to be removed from the connection's work list (see {@link Connection#getWorkHead()}). 47 * If this delivery is its link's current delivery, the link's current delivery pointer is advanced. 48 */ 49 public void settle(); 50 51 /** 52 * Returns whether this delivery has been settled. 53 * 54 * TODO proton-j and proton-c return the local and remote statuses respectively. Resolve this ambiguity. 55 * 56 * @see #settle() 57 */ 58 public bool isSettled(); 59 60 public bool remotelySettled(); 61 62 /** 63 * TODO When does an application call this method? Do we really need this? 64 */ 65 public void free(); 66 67 /** 68 * @see Connection#getWorkHead() 69 */ 70 public Delivery getWorkNext(); 71 72 public Delivery next(); 73 74 public bool isWritable(); 75 76 /** 77 * Returns whether this delivery has data ready to be received. 78 * 79 * @see Receiver#recv(byte[], int, int) 80 */ 81 public bool isReadable(); 82 83 public void setContext(Object o); 84 85 public Object getContext(); 86 87 /** 88 * Returns whether this delivery's state or settled flag has ever remotely changed. 89 * 90 * TODO what is the main intended use case for calling this method? 91 */ 92 public bool isUpdated(); 93 94 public void clear(); 95 96 /** 97 * Check for whether the delivery is still partial. 98 * 99 * For a receiving Delivery, this means the delivery does not hold 100 * a complete message payload as all the content hasn't been 101 * received yet. Note that an {@link #isAborted() aborted} delivery 102 * will also be considered partial and the full payload won't 103 * be received. 104 * 105 * For a sending Delivery, this means the sender link has not been 106 * {@link Sender#advance() advanced} to complete the delivery yet. 107 * 108 * @return true if the delivery is partial 109 * @see #isAborted() 110 */ 111 public bool isPartial(); 112 113 /** 114 * Check for whether the delivery was aborted. 115 * 116 * @return true if the delivery was aborted. 117 */ 118 bool isAborted(); 119 120 public int pending(); 121 122 public bool isBuffered(); 123 124 /** 125 * Configures a default DeliveryState to be used if a 126 * received delivery is settled/freed without any disposition 127 * state having been previously applied. 128 * 129 * @param state the default delivery state 130 */ 131 public void setDefaultDeliveryState(DeliveryState state); 132 133 public DeliveryState getDefaultDeliveryState(); 134 135 /** 136 * Sets the message-format for this Delivery, representing the 32bit value using an int. 137 * 138 * The default value is 0 as per the message format defined in the core AMQP 1.0 specification.<p> 139 * 140 * See the following for more details:<br> 141 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-transfer"> 142 * http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-transfer</a><br> 143 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-message-format"> 144 * http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-message-format</a><br> 145 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format"> 146 * http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-message-format</a><br> 147 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#definition-MESSAGE-FORMAT"> 148 * http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#definition-MESSAGE-FORMAT</a><br> 149 * 150 * @param messageFormat the message format 151 */ 152 public void setMessageFormat(int messageFormat); 153 154 /** 155 * Gets the message-format for this Delivery, representing the 32bit value using an int. 156 * 157 * @return the message-format 158 * @see #setMessageFormat(int) 159 */ 160 public int getMessageFormat(); 161 162 /** 163 * Returns the number of bytes currently available for this delivery, which may not be complete yet, that are still 164 * to either be received by the application or sent by the transport. 165 * 166 * Note that this value will change as bytes are received/sent, and is in general not equal to the total length of 167 * a delivery, except the point where {@link #isPartial()} returns false and no content has yet been received by the 168 * application or sent by the transport. 169 * 170 * @return the number of bytes currently available for the delivery 171 * 172 * @see Receiver#recv(byte[], int, int) 173 * @see Receiver#recv(hunt.proton.codec.WritableBuffer) 174 * @see Sender#send(byte[], int, int) 175 * @see Sender#send(hunt.proton.codec.ReadableBuffer) 176 */ 177 int available(); 178 }