@@ -93,107 +93,143 @@ public static BrokerInterceptor load(ServiceConfiguration conf) throws IOExcepti
93
93
}
94
94
}
95
95
96
+ @ Override
97
+ public void onMessagePublish (Producer producer ,
98
+ ByteBuf headersAndPayload ,
99
+ Topic .PublishContext publishContext ) {
100
+ if (interceptorsEnabled ()) {
101
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
102
+ value .onMessagePublish (producer , headersAndPayload , publishContext );
103
+ }
104
+ }
105
+ }
106
+
96
107
@ Override
97
108
public void beforeSendMessage (Subscription subscription ,
98
109
Entry entry ,
99
110
long [] ackSet ,
100
111
MessageMetadata msgMetadata ) {
101
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
102
- value .beforeSendMessage (
103
- subscription ,
104
- entry ,
105
- ackSet ,
106
- msgMetadata );
112
+ if (interceptorsEnabled ()) {
113
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
114
+ value .beforeSendMessage (subscription , entry , ackSet , msgMetadata );
115
+ }
116
+ }
117
+ }
118
+
119
+ @ Override
120
+ public void beforeSendMessage (Subscription subscription ,
121
+ Entry entry ,
122
+ long [] ackSet ,
123
+ MessageMetadata msgMetadata ,
124
+ Consumer consumer ) {
125
+ if (interceptorsEnabled ()) {
126
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
127
+ value .beforeSendMessage (subscription , entry , ackSet , msgMetadata , consumer );
128
+ }
107
129
}
108
130
}
109
131
110
132
@ Override
111
133
public void consumerCreated (ServerCnx cnx ,
112
134
Consumer consumer ,
113
135
Map <String , String > metadata ) {
114
- if (interceptors == null || interceptors .isEmpty ()) {
115
- return ;
136
+ if (interceptorsEnabled ()) {
137
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
138
+ value .consumerCreated (
139
+ cnx ,
140
+ consumer ,
141
+ metadata );
142
+ }
116
143
}
117
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
118
- value .consumerCreated (
119
- cnx ,
120
- consumer ,
121
- metadata );
144
+ }
145
+
146
+ @ Override
147
+ public void consumerClosed (ServerCnx cnx ,
148
+ Consumer consumer ,
149
+ Map <String , String > metadata ) {
150
+ if (interceptorsEnabled ()) {
151
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
152
+ value .consumerClosed (cnx , consumer , metadata );
153
+ }
122
154
}
123
155
}
124
156
125
157
@ Override
126
158
public void producerCreated (ServerCnx cnx , Producer producer ,
127
159
Map <String , String > metadata ){
128
- if (interceptors == null || interceptors .isEmpty ()) {
129
- return ;
160
+ if (interceptorsEnabled ()) {
161
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
162
+ value .producerCreated (cnx , producer , metadata );
163
+ }
130
164
}
131
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
132
- value .producerCreated (cnx , producer , metadata );
165
+ }
166
+
167
+ @ Override
168
+ public void producerClosed (ServerCnx cnx ,
169
+ Producer producer ,
170
+ Map <String , String > metadata ) {
171
+ if (interceptorsEnabled ()) {
172
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
173
+ value .producerClosed (cnx , producer , metadata );
174
+ }
133
175
}
134
176
}
135
177
136
178
@ Override
137
179
public void messageProduced (ServerCnx cnx , Producer producer , long startTimeNs , long ledgerId ,
138
180
long entryId , Topic .PublishContext publishContext ) {
139
- if (interceptors == null || interceptors .isEmpty ()) {
140
- return ;
141
- }
142
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
143
- value .messageProduced (cnx , producer , startTimeNs , ledgerId , entryId , publishContext );
181
+ if (interceptorsEnabled ()) {
182
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
183
+ value .messageProduced (cnx , producer , startTimeNs , ledgerId , entryId , publishContext );
184
+ }
144
185
}
145
186
}
146
187
147
188
@ Override
148
189
public void messageDispatched (ServerCnx cnx , Consumer consumer , long ledgerId ,
149
190
long entryId , ByteBuf headersAndPayload ) {
150
- if (interceptors == null || interceptors .isEmpty ()) {
151
- return ;
152
- }
153
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
154
- value .messageDispatched (cnx , consumer , ledgerId , entryId , headersAndPayload );
191
+ if (interceptorsEnabled ()) {
192
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
193
+ value .messageDispatched (cnx , consumer , ledgerId , entryId , headersAndPayload );
194
+ }
155
195
}
156
196
}
157
197
158
198
@ Override
159
199
public void messageAcked (ServerCnx cnx , Consumer consumer ,
160
200
CommandAck ackCmd ) {
161
- if (interceptors == null || interceptors .isEmpty ()) {
162
- return ;
163
- }
164
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
165
- value .messageAcked (cnx , consumer , ackCmd );
201
+ if (interceptorsEnabled ()) {
202
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
203
+ value .messageAcked (cnx , consumer , ackCmd );
204
+ }
166
205
}
167
206
}
168
207
169
208
@ Override
170
209
public void txnOpened (long tcId , String txnID ) {
171
- if (interceptors == null || interceptors .isEmpty ()) {
172
- return ;
173
- }
174
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
175
- value .txnOpened (tcId , txnID );
210
+ if (interceptorsEnabled ()) {
211
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
212
+ value .txnOpened (tcId , txnID );
213
+ }
176
214
}
177
215
}
178
216
179
217
@ Override
180
218
public void txnEnded (String txnID , long txnAction ) {
181
- if (interceptors == null || interceptors .isEmpty ()) {
182
- return ;
183
- }
184
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
185
- value .txnEnded (txnID , txnAction );
219
+ if (interceptorsEnabled ()) {
220
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
221
+ value .txnEnded (txnID , txnAction );
222
+ }
186
223
}
187
224
}
188
225
189
226
190
227
@ Override
191
228
public void onConnectionCreated (ServerCnx cnx ) {
192
- if (interceptors == null || interceptors .isEmpty ()) {
193
- return ;
194
- }
195
- for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
196
- value .onConnectionCreated (cnx );
229
+ if (interceptorsEnabled ()) {
230
+ for (BrokerInterceptorWithClassLoader value : interceptors .values ()) {
231
+ value .onConnectionCreated (cnx );
232
+ }
197
233
}
198
234
}
199
235
@@ -237,4 +273,8 @@ public void initialize(PulsarService pulsarService) throws Exception {
237
273
public void close () {
238
274
interceptors .values ().forEach (BrokerInterceptorWithClassLoader ::close );
239
275
}
276
+
277
+ private boolean interceptorsEnabled () {
278
+ return interceptors != null && !interceptors .isEmpty ();
279
+ }
240
280
}
0 commit comments