Skip to content

Commit

Permalink
more sonar smells fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshnsears committed Jan 23, 2019
1 parent 9230c5a commit f55ca16
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/java/xqa/InserterThread.java
Expand Up @@ -66,14 +66,16 @@ public void run() {
logger.debug("++++++++++++");
}

private synchronized void sendEventToMessageBroker(final String state) throws JMSException, MessageBrokerException {
final Message message = MessageMaker.createMessage(inserterThreadMessageBroker.getSession(),
inserterThreadMessageBroker.getSession().createQueue(ingestBalancer.destinationEvent),
UUID.randomUUID().toString(),
new Gson().toJson(new IngestBalancerEvent(ingestBalancer.serviceId, ingestMessage.getJMSCorrelationID(),
ingestBalancer.poolSize, DigestUtils.sha256Hex(MessageMaker.getBody(ingestMessage)), state)));
private void sendEventToMessageBroker(final String state) throws JMSException, MessageBrokerException {
synchronized (this) {
final Message message = MessageMaker.createMessage(inserterThreadMessageBroker.getSession(),
inserterThreadMessageBroker.getSession().createQueue(ingestBalancer.destinationEvent),
UUID.randomUUID().toString(),
new Gson().toJson(new IngestBalancerEvent(ingestBalancer.serviceId, ingestMessage.getJMSCorrelationID(),
ingestBalancer.poolSize, DigestUtils.sha256Hex(MessageMaker.getBody(ingestMessage)), state)));

inserterThreadMessageBroker.sendMessage(message);
inserterThreadMessageBroker.sendMessage(message);
}
}

private synchronized List<Message> askShardsForSize() throws Exception {
Expand All @@ -92,20 +94,20 @@ private synchronized List<Message> getSizeResponses(final MessageBroker shardSiz

logger.debug(MessageFormat.format("{0}: START", ingestMessage.getJMSCorrelationID()));

final List<Message> shardSizeResponses = shardSizeMessageBroker.receiveMessagesTemporaryQueue(sizeReplyTo,
final List<Message> sizeResponses = shardSizeMessageBroker.receiveMessagesTemporaryQueue(sizeReplyTo,
ingestBalancer.insertThreadWait, ingestBalancer.insertThreadSecondaryWait);

if (shardSizeResponses.isEmpty()) {
if (sizeResponses.isEmpty()) {
logger.warn(MessageFormat.format("{0}: END: shardSizeResponses=None; subject={1}",
ingestMessage.getJMSCorrelationID(), ingestMessage.getJMSType()));

placeMessageBackOnOriginatingDestination();
} else {
logger.debug(MessageFormat.format("{0}: END: shardSizeResponses={1}", ingestMessage.getJMSCorrelationID(),
shardSizeResponses.size()));
sizeResponses.size()));
}

return shardSizeResponses;
return sizeResponses;
}

private void placeMessageBackOnOriginatingDestination() throws JMSException, MessageBroker.MessageBrokerException {
Expand All @@ -125,13 +127,13 @@ private void placeMessageBackOnOriginatingDestination() throws JMSException, Mes
}
}

public Message findSmallestShard(final List<Message> shardSizeResponses) throws JMSException {
public Message findSmallestShard(final List<Message> sizeResponses) throws JMSException {
Message smallestShard = null;

if (!shardSizeResponses.isEmpty()) {
smallestShard = shardSizeResponses.get(0);
if (!sizeResponses.isEmpty()) {
smallestShard = sizeResponses.get(0);

for (final Message currentShard : shardSizeResponses) {
for (final Message currentShard : sizeResponses) {
if (Integer.valueOf(MessageMaker.getBody(smallestShard)) > Integer
.valueOf(MessageMaker.getBody(currentShard))) {
smallestShard = currentShard;
Expand Down

0 comments on commit f55ca16

Please sign in to comment.