Skip to content

Commit bf612ad

Browse files
committed
Fix: handle null event, misc IDE warnings
Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
1 parent b17a722 commit bf612ad

File tree

11 files changed

+32
-19
lines changed

11 files changed

+32
-19
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,27 @@ $ mvn clean -Dmaven.test.skip=true -Dspotbugs.skip=true install
6666

6767
### Build and Run `bmq-examples` Producer Example
6868

69+
Prerequisites:
70+
- BlazingMQ backend is built and is available.
71+
- `bmq-sdk` JAR is installed locally.
72+
73+
Java SDK producers/consumers can be tested with the local BlazingMQ broker.
74+
For Linux build, first start the local broker:
75+
```sh
76+
cd $BLAZINGMQ_DIR/build/Linux/src/applications/bmqbrkr
77+
./run
78+
```
79+
80+
Secondly, start sample producer, that will connect to the local broker, open a queue, post messages and exits:
6981
```sh
7082
$ cd bmq-examples
7183
$ mvn clean compile
72-
$ mvn exec:java -Dexec.mainClass="com.bloomberg.bmq.examples.Producer"
84+
$ mvn exec:java -Dexec.mainClass="com.bloomberg.bmq.examples.SimpleProducer"
7385
```
7486

75-
Above command expects that `bmq-sdk` JAR is installed locally. Also note that
76-
BlazingMQ backend must be running for producer/consumer examples to run
77-
successfully.
78-
7987
### Building BlazingMQ Backend
8088

81-
Detailed instructions to build BlazingMQ backend (BlazingMQ message brokers,
89+
Detailed instructions on how to build BlazingMQ backend (BlazingMQ message brokers,
8290
etc) can be found [here](https://www.github.com/bloomberg/blazingmq).
8391

8492
### Supported JDKs
@@ -166,7 +174,7 @@ in the project, please contact us at opensource@bloomberg.net.
166174
## Security Vulnerability Reporting
167175

168176
If you believe you have identified a security vulnerability in this project,
169-
please send an email to the project team at opensource@bloomberg.net, detailing
177+
please email the project team at opensource@bloomberg.net, detailing
170178
the suspected issue and any methods you've found to reproduce it.
171179

172180
Please do NOT open an issue in the GitHub repository, as we'd prefer to keep

bmq-sdk/src/main/java/com/bloomberg/bmq/SubscriptionExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SubscriptionExpression(String expression) {
4242
Argument.expectNonNull(expression, "expression");
4343
this.expression = Optional.of(expression);
4444
this.version =
45-
Optional.of((expression.length() > 0) ? Version.e_VERSION_1 : Version.e_UNDEFINED);
45+
Optional.of((!expression.isEmpty()) ? Version.e_VERSION_1 : Version.e_UNDEFINED);
4646
}
4747

4848
public SubscriptionExpression() {

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/BrokerSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private CompletableFuture<Void> execQueueManagerCleanUp() {
598598
.collect(Collectors.toList());
599599
if (!activeStrategies.isEmpty()) {
600600
// If given list is not empty, then cancel all unfinished sequences
601-
// and set up clean up action as a continuation executed in scheduler.
601+
// and set up cleanup action as a continuation executed in scheduler.
602602
activeStrategies.forEach(QueueControlStrategy::cancelOnStop);
603603
activeStrategies.stream()
604604
.map(QueueControlStrategy::getResultFuture)

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/ProtocolEventTcpReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void read(
7979
data.length,
8080
completionStatus.numNeeded());
8181
try {
82-
EventHeader eventHeader = null;
82+
EventHeader eventHeader;
8383
for (ByteBuffer restData : data) {
8484
boolean done = false;
8585
while (!done) {

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/TcpBrokerConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ private boolean validateBrokerResponse(BrokerResponse resp) {
437437
private class EventHandler implements ProtocolEventTcpReader.EventHandler {
438438

439439
public void handleEvent(EventType eventType, ByteBuffer[] bbuf) {
440+
if (eventType == null) {
441+
logger.warn("Received null event type with buffer size: {}, skipping", bbuf.length);
442+
return;
443+
}
444+
440445
logger.debug("Handle EventImpl {} with size: {}", eventType, bbuf.length);
441446
EventImpl reportedEvent;
442447
switch (eventType) {

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/events/BrokerSessionEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void dispatch(BrokerSessionEventHandler handler, BrokerSessionEvent event
5252

5353
private static final int TYPE_ID = UniqId.getNumber();
5454

55-
public final void dispatch(BrokerSessionEventHandler handler) {
55+
public void dispatch(BrokerSessionEventHandler handler) {
5656
getEventType().dispatch(handler, this);
5757
}
5858

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/events/QueueControlEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public final void dispatch(QueueControlEventHandler handler) {
7878
getEventType().dispatch(handler, this);
7979
}
8080

81-
private QueueHandle queue;
81+
private final QueueHandle queue;
8282

8383
private QueueControlEvent(
8484
Type queueEventType, GenericCode result, String errorDescription, QueueHandle queue) {

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/net/NettyTcpConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public final class NettyTcpConnection extends ChannelInboundHandlerAdapter
8080
* <p>Other goals are to inject server responses and as well as to keep the threading model same
8181
* in the test code. The best candidate is {@link io.netty.channel.embedded.EmbeddedChannel}
8282
* class that lets us inject responses. The main problem with given class is the fact that it is
83-
* "threadless" and unfortunately does not allow us to inject custom eventloop. But we can
83+
* "threadless" and unfortunately does not allow us to inject custom event loop. But we can
8484
* inject it in our channel adapter and execute every embedded channel routine in IO thread. So,
8585
* it helps to achieve thread safety for plain embedded channel class and at the same time,
8686
* reproduce the threading model for tested class.
@@ -200,7 +200,7 @@ private enum ChannelState {
200200
private boolean wasOnceConnected;
201201
private int numRemainingInitialTries;
202202
private ConnectionOptions options;
203-
private NetResolver hostResolver;
203+
private final NetResolver hostResolver;
204204
private ReadCompletionStatus readBytesStatus;
205205
private EventLoopGroup eventLoop;
206206
private Bootstrap bootstrap;
@@ -210,7 +210,7 @@ private enum ChannelState {
210210
private DisconnectCallback disconnectCallback;
211211
private ChannelStatusHandler channelStatusHandler;
212212
private Semaphore channelWaterMarkSema;
213-
private ClientChannelAdapter clientChannelAdapter;
213+
private final ClientChannelAdapter clientChannelAdapter;
214214
private final long lingerTimeout;
215215

216216
static {
@@ -476,7 +476,7 @@ public int disconnect(DisconnectCallback disconnectCb) {
476476
disconnectCallback = disconnectCb;
477477

478478
// If the callback is not null, then we are going to do full
479-
// disconnect procedure. Otherwise we just drop the channel and
479+
// disconnect procedure. Otherwise, we just drop the channel and
480480
// schedule reconnecting (see 'channelCloseFutureComplete' method).
481481
if (disconnectCb != null) {
482482
state = ChannelState.DISCONNECTING;

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/proto/EventType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum EventType {
2323
PUSH(4),
2424
ACK(5);
2525

26-
private int id;
26+
private final int id;
2727

2828
EventType(int id) {
2929
this.id = id;

bmq-sdk/src/main/java/com/bloomberg/bmq/impl/infr/scm/VersionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static int getSdkVersion() {
7272
logger.info("BlazingMQ SDK Jar ImplementationVersion: [{}]", implVersion);
7373

7474
if (implVersion == null) {
75-
// When loaded outside of a JAR, just return a default value of
75+
// When loaded outside a JAR, just return a default value of
7676
// 999999 , which is what we return in C++ when program is built
7777
// from the master instead of using 'libbmq'.
7878
return DEFAULT_VERSION;

0 commit comments

Comments
 (0)