2020import com .google .cloud .Page ;
2121import com .google .cloud .Service ;
2222
23- import java .io .Serializable ;
2423import java .util .Iterator ;
2524import java .util .List ;
25+ import java .util .Map ;
2626import java .util .concurrent .Future ;
2727import java .util .concurrent .TimeUnit ;
2828
3333 */
3434public interface PubSub extends Service <PubSubOptions > {
3535
36- final class ListOption implements Serializable {
36+ /**
37+ * Class for specifying options for listing topics and subscriptions.
38+ */
39+ final class ListOption extends Option {
3740
3841 private static final long serialVersionUID = 6517442127283383124L ;
3942
40- private final Option option ;
41- private final Object value ;
43+ enum OptionType implements Option . OptionType {
44+ PAGE_SIZE , PAGE_TOKEN ;
4245
43- enum Option {
44- PAGE_SIZE , PAGE_TOKEN
45- }
46+ @ SuppressWarnings ("unchecked" )
47+ <T > T get (Map <Option .OptionType , ?> options ) {
48+ return (T ) options .get (this );
49+ }
4650
47- private ListOption (Option option , Object value ) {
48- this .option = option ;
49- this .value = value ;
50- }
51+ String getString (Map <Option .OptionType , ?> options ) {
52+ return get (options );
53+ }
5154
52- Option option () {
53- return option ;
55+ Integer getInteger (Map <Option .OptionType , ?> options ) {
56+ return get (options );
57+ }
5458 }
5559
56- Object value ( ) {
57- return value ;
60+ private ListOption ( OptionType option , Object value ) {
61+ super ( option , value ) ;
5862 }
5963
64+ /**
65+ * Returns an option to specify the maximum number of resources returned per page.
66+ */
6067 public static ListOption pageSize (int pageSize ) {
61- return new ListOption (Option .PAGE_SIZE , pageSize );
68+ return new ListOption (OptionType .PAGE_SIZE , pageSize );
6269 }
6370
71+ /**
72+ * Returns an option to specify the page token from which to start listing resources.
73+ */
6474 public static ListOption pageToken (String pageToken ) {
65- return new ListOption (Option .PAGE_TOKEN , pageToken );
75+ return new ListOption (OptionType .PAGE_TOKEN , pageToken );
6676 }
6777 }
6878
69- final class PullOption implements Serializable {
70-
71- private static final long serialVersionUID = -5220474819637439937L ;
79+ /**
80+ * Class for specifying options for pulling messages.
81+ */
82+ final class PullOption extends Option {
7283
73- private final Option option ;
74- private final Object value ;
84+ private static final long serialVersionUID = 4792164134340316582L ;
7585
76- enum Option {
77- MAX_MESSAGES
78- }
86+ enum OptionType implements Option .OptionType {
87+ MAX_CONCURRENT_CALLBACKS ;
7988
80- private PullOption ( Option option , Object value ) {
81- this . option = option ;
82- this . value = value ;
83- }
89+ @ SuppressWarnings ( "unchecked" )
90+ < T > T get ( Map < Option . OptionType , ?> options ) {
91+ return ( T ) options . get ( this ) ;
92+ }
8493
85- Option option () {
86- return option ;
94+ Integer getInteger (Map <Option .OptionType , ?> options ) {
95+ return get (options );
96+ }
8797 }
8898
89- Object value ( ) {
90- return value ;
99+ private PullOption ( Option . OptionType option , Object value ) {
100+ super ( option , value ) ;
91101 }
92102
93- public static PullOption maxMessages (int maxMessages ) {
94- return new PullOption (Option .MAX_MESSAGES , maxMessages );
103+ /**
104+ * Returns an option to specify the maximum number of messages that can be executed
105+ * concurrently at any time.
106+ */
107+ public static PullOption maxConcurrentCallbacks (int maxConcurrency ) {
108+ return new PullOption (OptionType .MAX_CONCURRENT_CALLBACKS , maxConcurrency );
95109 }
96110 }
97111
@@ -108,38 +122,6 @@ interface MessageProcessor {
108122 */
109123 interface MessageConsumer extends AutoCloseable {
110124
111- final class PullOption implements Serializable {
112-
113- private static final long serialVersionUID = 4792164134340316582L ;
114-
115- private final Option option ;
116- private final Object value ;
117-
118- enum Option {
119- MAX_CONCURRENT_CALLBACKS
120- }
121-
122- private PullOption (Option option , Object value ) {
123- this .option = option ;
124- this .value = value ;
125- }
126-
127- Option option () {
128- return option ;
129- }
130-
131- Object value () {
132- return value ;
133- }
134-
135- public static PullOption maxConcurrentCallbacks (int maxConcurrency ) {
136- return new PullOption (Option .MAX_CONCURRENT_CALLBACKS , maxConcurrency );
137- }
138- }
139-
140- void start (MessageConsumer .PullOption ... options );
141-
142- void stop ();
143125 }
144126
145127 Topic create (TopicInfo topic );
@@ -198,11 +180,11 @@ public static PullOption maxConcurrentCallbacks(int maxConcurrency) {
198180
199181 Future <AsyncPage <SubscriptionId >> listSubscriptionsAsync (String topic , ListOption ... options );
200182
201- Iterator <ReceivedMessage > pull (String subscription , PullOption ... options );
183+ Iterator <ReceivedMessage > pull (String subscription , int maxMessages );
202184
203- Future <Iterator <ReceivedMessage >> pullAsync (String subscription , PullOption ... options );
185+ Future <Iterator <ReceivedMessage >> pullAsync (String subscription , int maxMessages );
204186
205- MessageConsumer pullAsync (String subscription , MessageProcessor callback );
187+ MessageConsumer pullAsync (String subscription , MessageProcessor callback , PullOption ... options );
206188
207189 void ack (String subscription , String ackId , String ... ackIds );
208190
0 commit comments