Skip to content

Commit 0496a35

Browse files
author
翊名
committed
doc(api) add comment and version for APIs
1 parent 4503e1d commit 0496a35

29 files changed

Lines changed: 439 additions & 242 deletions

openmessaging-api/src/main/java/io/openmessaging/api/Constants.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,41 @@
1616
*/
1717
package io.openmessaging.api;
1818

19+
/**
20+
* Consumer interface.
21+
*
22+
* @version OMS 1.2.0
23+
* @since OMS 1.2.0
24+
*/
1925
public interface Consumer extends LifeCycle, Credentials {
2026

27+
/**
28+
* Subscribe message in order.
29+
*
30+
* @param topic message topic.
31+
* @param subExpression Subscribe to the filter expression string, which the broker filters based on this
32+
* expression. <br> eg: "tag1 || tag2 || tag3"<br>, if subExpression is equal to null or *, it means subscribe all
33+
* messages.
34+
* @param listener The message callback listener, the consumer receives the message and then passes it to the
35+
* message callback listener for consumption.
36+
*/
2137
void subscribe(final String topic, final String subExpression, final MessageListener listener);
2238

39+
/**
40+
* Subscribe to messages, which can be filtered using SQL expressions.
41+
*
42+
* @param topic
43+
* @param selector Subscribe to the message selector (can be empty, indicating no filtering), the ONS server filters
44+
* according to the expression in this selector. Currently supports two expression syntax: {@link
45+
* ExpressionType#TAG}, {@link ExpressionType#SQL92} Among them, the effect of TAG filtering is consistent with the
46+
* above interface.
47+
* @param listener Message callback listener
48+
*/
2349
void subscribe(final String topic, final MessageSelector selector, final MessageListener listener);
2450

51+
/**
52+
* Unsubscribe message
53+
* @param topic
54+
*/
2555
void unsubscribe(final String topic);
2656
}

openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@
1515
* limitations under the License.
1616
*/
1717
package io.openmessaging.api;
18+
1819
import java.util.Properties;
1920

21+
/**
22+
*
23+
* Used for update credentials.
24+
*
25+
* @version OMS 1.2.0
26+
* @since OMS 1.2.0
27+
*/
2028
public interface Credentials {
29+
/**
30+
* Update credentials for instance, properties can be found in {@link OMSBuiltinKeys}
31+
* @param credentialProperties
32+
*/
2133
void updateCredential(Properties credentialProperties);
2234
}

openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
*/
1717
package io.openmessaging.api;
1818

19+
/**
20+
* Message filter expression type.
21+
*
22+
* @version OMS 1.2.0
23+
* @since OMS 1.2.0
24+
*/
1925
public enum ExpressionType {
2026

2127
SQL92,

openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,42 @@
1616
*/
1717
package io.openmessaging.api;
1818

19+
/**
20+
* The {@code LifeCycle} defines a lifecycle interface for a OMS related service endpoint, like {@link Producer}, {@link
21+
* Consumer}, and so on.
22+
* <p>
23+
* If the service endpoint class implements the {@code ServiceLifecycle} interface, most of the containers can manage
24+
* the lifecycle of the corresponding service endpoint objects easily.
25+
* <p>
26+
* Any service endpoint should support repeated restart if it implements the {@code ServiceLifecycle} interface.
27+
*
28+
* @version OMS 1.2.0
29+
* @since OMS 1.2.0
30+
*/
1931
public interface LifeCycle {
32+
/**
33+
* Used to determine whether the current instance is started.
34+
*
35+
* @return if this instance has been started success, this method will return true, otherwise false.
36+
*/
2037
boolean isStarted();
2138

39+
/**
40+
* Used to determine whether the current instance is closed.
41+
*
42+
* @return if this instance has been stopped, this method will return true, otherwise false.
43+
*/
2244
boolean isClosed();
2345

46+
/**
47+
* Used for startup or initialization of a service endpoint. A service endpoint instance will be in a ready state
48+
* after this method has been completed.
49+
*/
2450
void start();
2551

52+
/**
53+
* Notify a service instance of the end of its life cycle. Once this method completes, the service endpoint could be
54+
* destroyed and eligible for garbage collection.
55+
*/
2656
void shutdown();
2757
}

openmessaging-api/src/main/java/io/openmessaging/api/Message.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,57 @@
1919
import java.io.Serializable;
2020
import java.util.Properties;
2121

22+
/**
23+
* The {@code Message} interface is the root interface of all OMS messages, and the most commonly used OMS message is
24+
* {@link Message}.
25+
* <p>
26+
* Most message-oriented middleware (MOM) products treat messages as lightweight entities that consist of header and
27+
* body and is used by separate applications to exchange a piece of information, like <a
28+
* href="http://rocketmq.apache.org/">Apache RocketMQ</a>.
29+
* <p>
30+
* The header contains fields used by the messaging system that describes the message's meta information, while the body
31+
* contains the application data being transmitted.
32+
* <p>
33+
* As for the message header, OMS defines two kinds types: userProperties and systemProperties with respect to
34+
* flexibility in vendor implementation and user usage.
35+
* <ul>
36+
* <li>
37+
* System Properties, OMS defines some standard attributes in {@link SystemPropKey} that represent the characteristics
38+
* of the message.
39+
* </li>
40+
* <li>
41+
* User properties, some OMS vendors may require enhanced extra attributes of the message or some users may want to
42+
* clarify some customized attributes to draw the body. OMS provides the improved scalability for these scenarios.
43+
* </li>
44+
* </ul>
45+
* The body contains the application data being transmitted, which is generally ignored by the messaging system and
46+
* simply transmitted to its destination.
47+
* <p>
48+
* In BytesMessage, the body is just a byte array, may be compressed and uncompressed in the transmitting process by the
49+
* messaging system. The application is responsible for explaining the concrete content and format of the message body,
50+
* OMS is never aware of that.
51+
*
52+
* The body part is placed in the implementation classes of {@code Message}.
53+
*
54+
* @version OMS 1.2.0
55+
* @since OMS 1.2.0
56+
*/
2257
public class Message implements Serializable {
2358

2459
private static final long serialVersionUID = -1385924226856188094L;
2560

26-
2761
protected Properties systemProperties;
2862

29-
3063
private String topic;
3164

32-
3365
private Properties userProperties;
3466

35-
3667
private byte[] body;
3768

38-
3969
public Message() {
4070
this(null, null, "", null);
4171
}
4272

43-
4473
public Message(String topic, String tag, String key, byte[] body) {
4574
this.topic = topic;
4675
this.body = body;
@@ -49,7 +78,6 @@ public Message(String topic, String tag, String key, byte[] body) {
4978
this.putSystemProperties(SystemPropKey.KEY, key);
5079
}
5180

52-
5381
public void putSystemProperties(final String key, final String value) {
5482
if (null == this.systemProperties) {
5583
this.systemProperties = new Properties();
@@ -60,12 +88,10 @@ public void putSystemProperties(final String key, final String value) {
6088
}
6189
}
6290

63-
6491
public Message(String topic, String tags, byte[] body) {
6592
this(topic, tags, "", body);
6693
}
6794

68-
6995
public void putUserProperties(final String key, final String value) {
7096
if (null == this.userProperties) {
7197
this.userProperties = new Properties();
@@ -76,7 +102,6 @@ public void putUserProperties(final String key, final String value) {
76102
}
77103
}
78104

79-
80105
public String getUserProperties(final String key) {
81106
if (null != this.userProperties) {
82107
return (String) this.userProperties.get(key);
@@ -85,22 +110,18 @@ public String getUserProperties(final String key) {
85110
return null;
86111
}
87112

88-
89113
public String getTopic() {
90114
return topic;
91115
}
92116

93-
94117
public void setTopic(String topic) {
95118
this.topic = topic;
96119
}
97120

98-
99121
public String getTag() {
100122
return this.getSystemProperties(SystemPropKey.TAG);
101123
}
102124

103-
104125
public String getSystemProperties(final String key) {
105126
if (null != this.systemProperties) {
106127
return this.systemProperties.getProperty(key);
@@ -109,27 +130,22 @@ public String getSystemProperties(final String key) {
109130
return null;
110131
}
111132

112-
113133
public void setTag(String tag) {
114134
this.putSystemProperties(SystemPropKey.TAG, tag);
115135
}
116136

117-
118137
public String getKey() {
119138
return this.getSystemProperties(SystemPropKey.KEY);
120139
}
121140

122-
123141
public void setKey(String key) {
124142
this.putSystemProperties(SystemPropKey.KEY, key);
125143
}
126144

127-
128145
public String getMsgID() {
129146
return this.getSystemProperties(SystemPropKey.MSGID);
130147
}
131148

132-
133149
public void setMsgID(String msgid) {
134150
this.putSystemProperties(SystemPropKey.MSGID, msgid);
135151
}
@@ -164,7 +180,6 @@ public void setBody(byte[] body) {
164180
this.body = body;
165181
}
166182

167-
168183
public int getReconsumeTimes() {
169184
String pro = this.getSystemProperties(SystemPropKey.RECONSUMETIMES);
170185
if (pro != null) {
@@ -174,12 +189,10 @@ public int getReconsumeTimes() {
174189
return 0;
175190
}
176191

177-
178192
public void setReconsumeTimes(final int value) {
179193
putSystemProperties(SystemPropKey.RECONSUMETIMES, String.valueOf(value));
180194
}
181195

182-
183196
public long getBornTimestamp() {
184197
String pro = this.getSystemProperties(SystemPropKey.BORNTIMESTAMP);
185198
if (pro != null) {
@@ -189,23 +202,19 @@ public long getBornTimestamp() {
189202
return 0L;
190203
}
191204

192-
193205
public void setBornTimestamp(final long value) {
194206
putSystemProperties(SystemPropKey.BORNTIMESTAMP, String.valueOf(value));
195207
}
196208

197-
198209
public String getBornHost() {
199210
String pro = this.getSystemProperties(SystemPropKey.BORNHOST);
200211
return pro == null ? "" : pro;
201212
}
202213

203-
204214
public void setBornHost(final String value) {
205215
putSystemProperties(SystemPropKey.BORNHOST, value);
206216
}
207217

208-
209218
public long getStartDeliverTime() {
210219
String pro = this.getSystemProperties(SystemPropKey.STARTDELIVERTIME);
211220
if (pro != null) {
@@ -224,7 +233,6 @@ public void setShardingKey(final String value) {
224233
putSystemProperties(SystemPropKey.SHARDINGKEY, value);
225234
}
226235

227-
228236
public void setStartDeliverTime(final long value) {
229237
putSystemProperties(SystemPropKey.STARTDELIVERTIME, String.valueOf(value));
230238
}
@@ -235,7 +243,6 @@ public String toString() {
235243
+ (body != null ? body.length : 0) + "]";
236244
}
237245

238-
239246
static public class SystemPropKey {
240247
public static final String TAG = "__TAG";
241248
public static final String KEY = "__KEY";

openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,50 @@
1818

1919
import java.util.Properties;
2020

21+
/**
22+
* Used for set or get the relevant properties of a message.
23+
*
24+
* @version OMS 1.2.0
25+
* @since OMS 1.2.0
26+
*/
2127
public class MessageAccessor {
28+
/**
29+
* Used for get all system properties.
30+
*
31+
* @param msg
32+
* @return system properties
33+
*/
2234
public static Properties getSystemProperties(final Message msg) {
2335
return msg.systemProperties;
2436
}
2537

26-
38+
/**
39+
* Used for set system properties, will used new systemProperties to override current systemProperties.
40+
*
41+
* @param msg
42+
* @return system properties
43+
*/
2744
public static void setSystemProperties(final Message msg, Properties systemProperties) {
2845
msg.systemProperties = systemProperties;
2946
}
3047

31-
48+
/**
49+
* Used for set system property for a specified key, will used new value to replace origin system property of a
50+
* specified key.
51+
*
52+
* @param msg
53+
* @return
54+
*/
3255
public static void putSystemProperties(final Message msg, final String key, final String value) {
3356
msg.putSystemProperties(key, value);
3457
}
3558

36-
59+
/**
60+
* Used for get a system property value for a specified key.
61+
*
62+
* @param msg
63+
* @return system property value of specified key
64+
*/
3765
public static String getSystemProperties(final Message msg, final String key) {
3866
return msg.getSystemProperties(key);
3967
}

0 commit comments

Comments
 (0)