Skip to content

Commit fc31675

Browse files
committed
Rename ErrorCode
1 parent caad18f commit fc31675

6 files changed

Lines changed: 155 additions & 149 deletions

File tree

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

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

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@
1818
package io.openmessaging;
1919

2020
/**
21+
* <p>
2122
* A {@code Future} represents the result of an asynchronous computation. Methods are provided to check if the
2223
* computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can
2324
* only be retrieved using method {@code get} when the computation has completed, blocking if necessary until it is
2425
* ready. Additional methods are provided to determine if the task completed normally or was cancelled.
26+
* </p>
27+
* <p>
28+
* The reason for adding this future is mainly to satisfy the old version of jdk, such as jdk 1.6.
29+
* </p>
2530
*
2631
* @version OMS 1.0.0
2732
* @since OMS 1.0.0
2833
*/
2934
public interface Future<V> {
3035
/**
31-
* Returns {@code true} if this task was cancelled before it completed
32-
* normally.
36+
* Returns {@code true} if this task was cancelled before it completed normally.
3337
*
3438
* @return {@code true} if this task was cancelled before it completed
3539
*/
@@ -38,34 +42,32 @@ public interface Future<V> {
3842
/**
3943
* Returns {@code true} if this task completed.
4044
* <p>
41-
* Completion may be due to normal termination, an exception, or
42-
* cancellation -- in all of these cases, this method will return
43-
* {@code true}.
45+
* Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method
46+
* will return {@code true}.
4447
*
4548
* @return {@code true} if this task completed
4649
*/
4750
boolean isDone();
4851

4952
/**
50-
* Waits if necessary for the computation to complete, and then
51-
* retrieves its result.
53+
* Waits if necessary for the computation to complete, and then retrieves its result.
5254
*
5355
* @return the computed result
5456
*/
5557
V get();
5658

5759
/**
58-
* Waits if necessary for at most the given time for the computation
59-
* to complete, and then retrieves its result, if available.
60+
* Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if
61+
* available.
6062
*
6163
* @param timeout the maximum time to wait
6264
* @return the computed result <p> if the computation was cancelled
6365
*/
6466
V get(long timeout);
6567

6668
/**
67-
* Adds the specified listener to this future. The specified listener is notified when this future is done. If
68-
* this future is already completed, the specified listener will be notified immediately.
69+
* Adds the specified listener to this future. The specified listener is notified when this future is done. If this
70+
* future is already completed, the specified listener will be notified immediately.
6971
*
7072
* @param listener FutureListener
7173
*/
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package io.openmessaging;
2+
3+
import io.openmessaging.exception.OMSRuntimeException;
4+
5+
/**
6+
* This class defined OpenMessaging response status code:
7+
* <p>
8+
* 110x: The request was received, continuing process
9+
* </p>
10+
* <p>
11+
* 120x: The request was successfully received, understood, and accepted
12+
* </p>
13+
* <p>
14+
* 130x: Further action needs to be taken in order to complete the request
15+
* </p>
16+
* <p>
17+
* 140x: The request contains bad syntax or cannot be fulfilled
18+
* </p>
19+
* <p>
20+
* 150x: The server failed to fulfill an apparently valid request
21+
* </p>
22+
* <p>
23+
* 1000x: OpenMessaging internal status code for create {@link MessagingAccessPoint}
24+
* </p>
25+
*/
26+
public enum OMSResponseStatus {
27+
STATUS_1101(1101, "Unsupported Version"),
28+
29+
STATUS_1200(1200, "Success"),
30+
31+
STATUS_1400(1400, "Bad Request"),
32+
33+
STATUS_1401(1401, "Unauthorized"),
34+
35+
STATUS_1402(1402, "Message body Required"),
36+
37+
STATUS_1403(1403, "Forbidden"),
38+
39+
STATUS_1404(1404, "Destination Not Found"),
40+
41+
STATUS_1405(1405, "Namespace Not Found"),
42+
43+
STATUS_1406(1406, "Destination Already Exists"),
44+
45+
STATUS_1407(1407, "Namespace Already Exists"),
46+
47+
STATUS_1408(1408, "ConsumerId Already Exists"),
48+
49+
STATUS_1409(1409, "ProducerId Already Exists"),
50+
51+
STATUS_1410(1410, "Request Timeout"),
52+
53+
STATUS_1411(1411, "Message Attributes Too Large"),
54+
55+
STATUS_1412(1412, "Message Header Too Large"),
56+
57+
STATUS_1413(1413, "Message Body Too Large"),
58+
59+
STATUS_1414(1414, "No New Message Found"),
60+
61+
STATUS_1415(1415, "Max Topics Reached"),
62+
63+
STATUS_1416(1416, "Max Queues Reached"),
64+
65+
STATUS_1417(1417, "Max Namespaces Reached"),
66+
67+
STATUS_1418(1418, "Bad Parameter"),
68+
69+
STATUS_1500(1500, "Server STATUS"),
70+
71+
STATUS_1501(1501, "Storage Service STATUS"),
72+
73+
STATUS_1502(1502, "Storage Service Busy"),
74+
75+
STATUS_1503(1503, "Service Not Available"),
76+
77+
STATUS_1504(1504, "Flush Disk Timeout"),
78+
79+
STATUS_10000(10000, "Can't construct a MessagingAccessPoint instance from the given OMS driver URL [%s]."),
80+
81+
STATUS_10001(10001, "The OMS driver URL [%s] is illegal."),
82+
83+
STATUS_10002(10002, "The implementation version [%s] is illegal."),
84+
85+
STATUS_10003(10003, "The implementation version [%s] isn't compatible with the specification version [%s].");
86+
87+
private int statusCode;
88+
89+
private String reasonPhrase;
90+
91+
private String reasonLocation;
92+
93+
private static final String refBase = "http://openmessaging.cloud/internal/code";
94+
95+
OMSResponseStatus(int statusCode, String reasonPhrase) {
96+
this.statusCode = statusCode;
97+
98+
this.reasonPhrase = reasonPhrase;
99+
100+
this.reasonLocation = generateReasonLocation(statusCode, reasonPhrase);
101+
}
102+
103+
public int getStatusCode() {
104+
return statusCode;
105+
}
106+
107+
public String getReasonLocation() {
108+
return reasonLocation;
109+
}
110+
111+
public String getReasonPhrase() {
112+
return reasonPhrase;
113+
}
114+
115+
public static OMSRuntimeException generateException(OMSResponseStatus status, String... messageArgs) {
116+
return new OMSRuntimeException(status.getStatusCode(), String.format(status.getReasonLocation(), (Object[]) messageArgs));
117+
}
118+
119+
public static OMSRuntimeException generateException(OMSResponseStatus status) {
120+
return new OMSRuntimeException(status.getStatusCode(), status.getReasonLocation());
121+
}
122+
123+
public static OMSRuntimeException generateException(int statusCode, String reasonPhrase) {
124+
return new OMSRuntimeException(statusCode, reasonPhrase);
125+
}
126+
127+
public static String generateReasonLocation(int statusCode, String reasonPhrase) {
128+
return reasonPhrase + "\nFor more information, please visit the URL, " + refBase + "#" + statusCode;
129+
}
130+
}

openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package io.openmessaging.internal;
1919

20-
import io.openmessaging.Error;
20+
import io.openmessaging.OMSResponseStatus;
2121

22-
import static io.openmessaging.Error.generateException;
22+
import static io.openmessaging.OMSResponseStatus.generateException;
2323

2424
/**
2525
* Represents a <a href="https://github.com/openmessaging/specification/blob/master/oms_access_point_schema.md">AccessPoint String</a>.
@@ -95,7 +95,7 @@ public String getRegion() {
9595

9696
private void validateAccessPointString(String accessPointString) {
9797
if (!accessPointString.matches(PATTERN)) {
98-
throw generateException(Error.ERROR_10001, accessPointString);
98+
throw generateException(OMSResponseStatus.STATUS_10001, accessPointString);
9999
}
100100
}
101101
}

openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import io.openmessaging.MessagingAccessPoint;
2222
import io.openmessaging.OMS;
2323
import io.openmessaging.OMSBuiltinKeys;
24-
import io.openmessaging.Error;
24+
import io.openmessaging.OMSResponseStatus;
2525
import io.openmessaging.exception.OMSRuntimeException;
2626
import java.lang.reflect.Constructor;
2727

28-
import static io.openmessaging.Error.generateException;
28+
import static io.openmessaging.OMSResponseStatus.generateException;
2929

3030
/**
3131
* The {@code MessagingAccessPointAdapter} provides a common implementation to create a specified {@code
@@ -59,7 +59,7 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue
5959
checkSpecVersion(OMS.specVersion, vendorImpl.version());
6060
return vendorImpl;
6161
} catch (Throwable e) {
62-
throw generateException(Error.ERROR_10000, url);
62+
throw generateException(OMSResponseStatus.STATUS_10000, url);
6363
}
6464
}
6565

@@ -76,10 +76,10 @@ private static void checkSpecVersion(final String specVersion, final String impl
7676
try {
7777
majorVerOfImpl = implVersion.substring(0, implVersion.indexOf('.', implVersion.indexOf('.') + 1));
7878
} catch (Throwable e) {
79-
throw generateException(Error.ERROR_10002, implVersion);
79+
throw generateException(OMSResponseStatus.STATUS_10002, implVersion);
8080
}
8181
if (!majorVerOfSpec.equals(majorVerOfImpl)) {
82-
throw generateException(Error.ERROR_10003, implVersion, specVersion);
82+
throw generateException(OMSResponseStatus.STATUS_10003, implVersion, specVersion);
8383
}
8484
}
8585
}

0 commit comments

Comments
 (0)