Debian Codegraph @

proton-j/src/main/java/org/apache/qpid/proton/message/Message.java

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.proton.message;
22
23 import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
24 import org.apache.qpid.proton.amqp.messaging.DeliveryAnnotations;
25 import org.apache.qpid.proton.amqp.messaging.Footer;
26 import org.apache.qpid.proton.amqp.messaging.Header;
27 import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
28 import org.apache.qpid.proton.amqp.messaging.Properties;
29 import org.apache.qpid.proton.amqp.messaging.Section;
30 import org.apache.qpid.proton.codec.ReadableBuffer;
31 import org.apache.qpid.proton.codec.WritableBuffer;
32 import org.apache.qpid.proton.message.impl.MessageImpl;
33
34 /**
35 * Represents a Message within Proton.
36 *
37 * Create instances of Message using {@link Message.Factory}.
38 *
39 */
40 public interface Message
41 {
42
43 public static final class Factory
44 {
45 public static Message create() {
46 return new MessageImpl();
47 }
48
49 public static Message create(Header header,
50 DeliveryAnnotations deliveryAnnotations,
51 MessageAnnotations messageAnnotations,
52 Properties properties,
53 ApplicationProperties applicationProperties,
54 Section body,
55 Footer footer) {
56 return new MessageImpl(header, deliveryAnnotations,
57 messageAnnotations, properties,
58 applicationProperties, body, footer);
59 }
60 }
61
62
63 short DEFAULT_PRIORITY = 4;
64
65 boolean isDurable();
66
67 long getDeliveryCount();
68
69 short getPriority();
70
71 boolean isFirstAcquirer();
72
73 long getTtl();
74
75 void setDurable(boolean durable);
76
77 void setTtl(long ttl);
78
79 void setDeliveryCount(long deliveryCount);
80
81 void setFirstAcquirer(boolean firstAcquirer);
82
83 void setPriority(short priority);
84
85 Object getMessageId();
86
87 long getGroupSequence();
88
89 String getReplyToGroupId();
90
91
92 long getCreationTime();
93
94 String getAddress();
95
96 byte[] getUserId();
97
98 String getReplyTo();
99
100 String getGroupId();
101
102 String getContentType();
103
104 long getExpiryTime();
105
106 Object getCorrelationId();
107
108 String getContentEncoding();
109
110 String getSubject();
111
112 void setGroupSequence(long groupSequence);
113
114 void setUserId(byte[] userId);
115
116 void setCreationTime(long creationTime);
117
118 void setSubject(String subject);
119
120 void setGroupId(String groupId);
121
122 void setAddress(String to);
123
124 void setExpiryTime(long absoluteExpiryTime);
125
126 void setReplyToGroupId(String replyToGroupId);
127
128 void setContentEncoding(String contentEncoding);
129
130 void setContentType(String contentType);
131
132 void setReplyTo(String replyTo);
133
134 void setCorrelationId(Object correlationId);
135
136 void setMessageId(Object messageId);
137
138 Header getHeader();
139
140 DeliveryAnnotations getDeliveryAnnotations();
141
142 MessageAnnotations getMessageAnnotations();
143
144 Properties getProperties();
145
146 ApplicationProperties getApplicationProperties();
147
148 Section getBody();
149
150 Footer getFooter();
151
152 void setHeader(Header header);
153
154 void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations);
155
156 void setMessageAnnotations(MessageAnnotations messageAnnotations);
157
158 void setProperties(Properties properties);
159
160 void setApplicationProperties(ApplicationProperties applicationProperties);
161
162 void setBody(Section body);
163
164 void setFooter(Footer footer);
165
166 /**
167 * TODO describe what happens if the data does not represent a complete message.
168 * Currently this appears to leave the message in an unknown state.
169 */
170 int decode(byte[] data, int offset, int length);
171
172 /**
173 * Decodes the Message from the given {@link ReadableBuffer}.
174 * <p>
175 * If the buffer given does not contain the fully encoded Message bytes for decode
176 * this method will throw an exception to indicate the buffer underflow condition and
177 * the message object will be left in an undefined state.
178 *
179 * @param buffer
180 * A {@link ReadableBuffer} that contains the complete message bytes.
181 */
182 void decode(ReadableBuffer buffer);
183
184 /**
185 * Encodes up to {@code length} bytes of the message into the provided byte array,
186 * starting at position {@code offset}.
187 *
188 * TODO describe what happens if length is smaller than the encoded form, Currently
189 * Proton-J throws an exception. What does Proton-C do?
190 *
191 * @return the number of bytes written to the byte array
192 */
193 int encode(byte[] data, int offset, int length);
194
195 /**
196 * Encodes the current Message contents into the given {@link WritableBuffer} instance.
197 * <p>
198 * This method attempts to encode all message data into the {@link WritableBuffer} and
199 * if the buffer has insufficient space it will throw an exception to indicate the buffer
200 * overflow condition. If successful the method returns the number of bytes written to
201 * the provided buffer to fully encode the message.
202 *
203 * @param buffer
204 * The {@link WritableBuffer} instance to encode the message contents into.
205 *
206 * @return the number of bytes written to fully encode the message.
207 */
208 int encode(WritableBuffer buffer);
209
210 void clear();
211
212 MessageError getError();
213 }