Skip to content

Commit 4599563

Browse files
committed
More Javadoc
1 parent 7711063 commit 4599563

File tree

7 files changed

+217
-32
lines changed

7 files changed

+217
-32
lines changed

src/main/java/com/rabbitmq/client/amqp/Consumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @see Connection#consumerBuilder()
2626
* @see ConsumerBuilder
2727
*/
28-
public interface Consumer extends AutoCloseable {
28+
public interface Consumer extends AutoCloseable, Resource {
2929

3030
/** Pause the consumer to stop receiving messages. */
3131
void pause();

src/main/java/com/rabbitmq/client/amqp/Resource.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,83 @@
1717
// info@rabbitmq.com.
1818
package com.rabbitmq.client.amqp;
1919

20+
/**
21+
* Marker interface for {@link Resource}-like classes.
22+
*
23+
* <p>Instances of these classes have different states during their lifecycle: open, recovering,
24+
* closed, etc. Application can be interested in taking some actions for a given state (e.g.
25+
* stopping publishing when a {@link Publisher} is recovering after a connection problem and
26+
* resuming publishing when it is open again).
27+
*
28+
* @see Connection
29+
* @see Publisher
30+
* @see Consumer
31+
*/
2032
public interface Resource {
2133

34+
/**
35+
* Application listener for a {@link Resource}.
36+
*
37+
* <p>They are usually registered at creation time.
38+
*
39+
* @see ConnectionBuilder#listeners(StateListener...)
40+
* @see PublisherBuilder#listeners(StateListener...)
41+
* @see ConsumerBuilder#listeners(StateListener...)
42+
*/
2243
@FunctionalInterface
2344
interface StateListener {
2445

46+
/**
47+
* Handle state change.
48+
*
49+
* @param context state change context
50+
*/
2551
void handle(Context context);
2652
}
2753

54+
/** Context of a resource state change. */
2855
interface Context {
2956

57+
/**
58+
* The resource instance.
59+
*
60+
* @return resource instance
61+
*/
3062
Resource resource();
3163

64+
/**
65+
* The failure cause, can be null.
66+
*
67+
* @return failure cause, null if no cause for failure
68+
*/
3269
Throwable failureCause();
3370

71+
/**
72+
* The previous state of the resource.
73+
*
74+
* @return previous state
75+
*/
3476
State previousState();
3577

78+
/**
79+
* The current (new) state of the resource.
80+
*
81+
* @return current state
82+
*/
3683
State currentState();
3784
}
3885

86+
/** Resource state. */
3987
enum State {
88+
/** The resource is currently opening. */
4089
OPENING,
90+
/** The resource is open and functional. */
4191
OPEN,
92+
/** The resource is recovering. */
4293
RECOVERING,
94+
/** The resource is closing. */
4395
CLOSING,
96+
/** The resource is closed. */
4497
CLOSED
4598
}
4699
}

src/main/java/com/rabbitmq/client/amqp/RpcClient.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,43 @@
1919

2020
import java.util.concurrent.CompletableFuture;
2121

22+
/**
23+
* Client support class for RPC.
24+
*
25+
* @see RpcClientBuilder
26+
*/
2227
public interface RpcClient extends AutoCloseable {
2328

29+
/**
30+
* Create a message meant to be published by the underlying publisher instance.
31+
*
32+
* <p>Once published with the {@link #publish(Message)} the message instance should be not be
33+
* modified or even reused.
34+
*
35+
* @return a message
36+
*/
2437
Message message();
2538

39+
/**
40+
* Create a message meant to be published by the underlying publisher instance.
41+
*
42+
* <p>Once published with the {@link #publish(Message)} the message instance should be not be
43+
* modified or even reused.
44+
*
45+
* @param body message body
46+
* @return a message with the provided body
47+
*/
2648
Message message(byte[] body);
2749

50+
/**
51+
* Publish a request message and expect a response.
52+
*
53+
* @param message message request
54+
* @return the response as {@link CompletableFuture}
55+
*/
2856
CompletableFuture<Message> publish(Message message);
2957

58+
/** Close the RPC client and its resources. */
3059
@Override
3160
void close();
3261
}

src/main/java/com/rabbitmq/client/amqp/RpcClientBuilder.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,89 @@
2222
import java.util.function.Function;
2323
import java.util.function.Supplier;
2424

25+
/** API to configure and create a {@link RpcClient}. */
2526
public interface RpcClientBuilder {
2627

28+
/**
29+
* Builder for the request address.
30+
*
31+
* @return the request address builder
32+
*/
2733
RpcClientAddressBuilder requestAddress();
2834

35+
/**
36+
* The queue the client expects responses on.
37+
*
38+
* <p>The queue <b>must</b> exist if it is set.
39+
*
40+
* <p>The RPC client will create an exclusive, auto-delete queue if it is not set.
41+
*
42+
* @param replyToQueue reply queue
43+
* @return this builder instance
44+
*/
2945
RpcClientBuilder replyToQueue(String replyToQueue);
3046

47+
/**
48+
* The generator for correlation ID.
49+
*
50+
* <p>The default generator uses a fixed random UUID prefix and a strictly monotonic increasing
51+
* sequence suffix.
52+
*
53+
* @param correlationIdSupplier correlation ID generator
54+
* @return the this builder instance
55+
*/
3156
RpcClientBuilder correlationIdSupplier(Supplier<Object> correlationIdSupplier);
3257

58+
/**
59+
* A callback before sending a request message.
60+
*
61+
* <p>The callback accepts the request message and the correlation ID as parameters. It must
62+
* return the message that will be sent as request, after having potentially modified it.
63+
*
64+
* <p>The default post-processor sets the reply-to field and assigns the correlation ID to the
65+
* message ID field.
66+
*
67+
* @param requestPostProcessor logic to post-process request message
68+
* @return this builder instance
69+
*/
3370
RpcClientBuilder requestPostProcessor(BiFunction<Message, Object, Message> requestPostProcessor);
3471

72+
/**
73+
* Callback to extract the correlation ID from a reply message.
74+
*
75+
* <p>The correlation ID is then used to correlate the reply message to an outstanding request
76+
* message.
77+
*
78+
* <p>The default implementation uses the correlation ID field.
79+
*
80+
* @param correlationIdExtractor correlation ID extractor
81+
* @return this builder instance
82+
*/
3583
RpcClientBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
3684

85+
/**
86+
* Timeout before failing outstanding requests.
87+
*
88+
* @param timeout timeout
89+
* @return the builder instance
90+
*/
3791
RpcClientBuilder requestTimeout(Duration timeout);
3892

93+
/**
94+
* Build the configured instance.
95+
*
96+
* @return the configured instance
97+
*/
3998
RpcClient build();
4099

100+
/** Builder for the request address. */
41101
interface RpcClientAddressBuilder extends AddressBuilder<RpcClientAddressBuilder> {
42102

103+
/**
104+
* Go back to the RPC client builder.
105+
*
106+
* @return the RPC client builder
107+
*/
43108
RpcClientBuilder rpcClient();
44109
}
45110
}

src/main/java/com/rabbitmq/client/amqp/RpcServer.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,53 @@
1717
// info@rabbitmq.com.
1818
package com.rabbitmq.client.amqp;
1919

20+
/**
21+
* Client server class for RPC.
22+
*
23+
* @see RpcServerBuilder
24+
*/
2025
public interface RpcServer extends AutoCloseable {
2126

27+
/** Contract to process a request message and return a reply message. */
2228
@FunctionalInterface
2329
interface Handler {
2430

31+
/**
32+
* Process request message.
33+
*
34+
* @param ctx context
35+
* @param request request message
36+
* @return the reply message
37+
*/
2538
Message handle(Context ctx, Message request);
2639
}
2740

41+
/** Request processing context. */
2842
interface Context {
2943

44+
/**
45+
* Create a message meant to be published by the underlying publisher instance.
46+
*
47+
* <p>Once returned in the {@link Handler#handle(Context, Message)} the message instance should
48+
* be not be modified or even reused.
49+
*
50+
* @return a message
51+
*/
3052
Message message();
3153

54+
/**
55+
* Create a message meant to be published by the underlying publisher instance.
56+
*
57+
* <p>Once returned in the {@link Handler#handle(Context, Message)} the message instance should
58+
* be not be modified or even reused.
59+
*
60+
* @param body message body
61+
* @return a message with the provided body
62+
*/
3263
Message message(byte[] body);
3364
}
3465

66+
/** Close the RPC server and its resources. */
3567
@Override
3668
void close();
3769
}

src/main/java/com/rabbitmq/client/amqp/RpcServerBuilder.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,52 @@
2020
import java.util.function.BiFunction;
2121
import java.util.function.Function;
2222

23+
/** API to configure and create a {@link RpcServer}. */
2324
public interface RpcServerBuilder {
2425

26+
/**
27+
* The queue to wait for requests on.
28+
*
29+
* @param requestQueue request queue
30+
* @return this builder instance
31+
*/
2532
RpcServerBuilder requestQueue(String requestQueue);
2633

34+
/**
35+
* The logic to process requests and issue replies.
36+
*
37+
* @param handler handler
38+
* @return this builder instance
39+
*/
2740
RpcServerBuilder handler(RpcServer.Handler handler);
2841

29-
RpcServerAddressBuilder replyToAddress();
30-
42+
/**
43+
* Logic to extract the correlation ID from a request message.
44+
*
45+
* <p>The default implementation uses the message ID.
46+
*
47+
* @param correlationIdExtractor logic to extract the correlation ID
48+
* @return this builder instance
49+
*/
3150
RpcServerBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
3251

52+
/**
53+
* A callback called after request processing but before sending the reply message.
54+
*
55+
* <p>The callback accepts the request message and the correlation ID as parameters. It must
56+
* return the message that will be sent as the reply, after having potentially modified it.
57+
*
58+
* <p>The default implementation set the correlation ID field and returns the updated message.
59+
*
60+
* @param replyPostProcessor logic to post-process reply message
61+
* @return this builder instance
62+
*/
3363
RpcServerBuilder replyPostProcessor(BiFunction<Message, Object, Message> replyPostProcessor);
3464

65+
/**
66+
* Create the configured instance.
67+
*
68+
* @return the configured instance
69+
*/
3570
RpcServer build();
36-
37-
interface RpcServerAddressBuilder extends AddressBuilder<RpcServerAddressBuilder> {
38-
39-
RpcServerBuilder rpcServer();
40-
}
4171
}

src/main/java/com/rabbitmq/client/amqp/impl/RpcSupport.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ static class AmqpRpcServerBuilder implements RpcServerBuilder {
147147

148148
private String requestQueue;
149149
private RpcServer.Handler handler;
150-
private final DefaultRpcServerAddressBuilder replyToAddressBuilder =
151-
new DefaultRpcServerAddressBuilder(this);
152150
private Function<Message, Object> correlationIdExtractor;
153151
private BiFunction<Message, Object, Message> replyPostProcessor;
154152

@@ -168,11 +166,6 @@ public RpcServerBuilder handler(RpcServer.Handler handler) {
168166
return this;
169167
}
170168

171-
@Override
172-
public RpcServerAddressBuilder replyToAddress() {
173-
return this.replyToAddressBuilder;
174-
}
175-
176169
@Override
177170
public RpcServerBuilder correlationIdExtractor(
178171
Function<Message, Object> correlationIdExtractor) {
@@ -212,21 +205,4 @@ BiFunction<Message, Object, Message> replyPostProcessor() {
212205
return this.replyPostProcessor;
213206
}
214207
}
215-
216-
private static class DefaultRpcServerAddressBuilder
217-
extends DefaultAddressBuilder<RpcServerBuilder.RpcServerAddressBuilder>
218-
implements RpcServerBuilder.RpcServerAddressBuilder {
219-
220-
private final AmqpRpcServerBuilder builder;
221-
222-
private DefaultRpcServerAddressBuilder(AmqpRpcServerBuilder builder) {
223-
super(null);
224-
this.builder = builder;
225-
}
226-
227-
@Override
228-
public RpcServerBuilder rpcServer() {
229-
return this.builder;
230-
}
231-
}
232208
}

0 commit comments

Comments
 (0)