diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionCannotBeLockedException.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionCannotBeLockedException.java
index 510dc6a0944f..d5d347191321 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionCannotBeLockedException.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionCannotBeLockedException.java
@@ -12,23 +12,19 @@ public class SessionCannotBeLockedException extends ServiceBusException {
private static final long serialVersionUID = -421016051252808254L;
- public SessionCannotBeLockedException()
- {
+ public SessionCannotBeLockedException() {
super(false);
}
- public SessionCannotBeLockedException(String message)
- {
+ public SessionCannotBeLockedException(String message) {
super(false, message);
}
- public SessionCannotBeLockedException(Throwable cause)
- {
+ public SessionCannotBeLockedException(Throwable cause) {
super(false, cause);
}
- public SessionCannotBeLockedException(String message, Throwable cause)
- {
+ public SessionCannotBeLockedException(String message, Throwable cause) {
super(false, message, cause);
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionLockLostException.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionLockLostException.java
index e8013dad1b72..1280ef509af2 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionLockLostException.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SessionLockLostException.java
@@ -14,23 +14,19 @@ public class SessionLockLostException extends ServiceBusException {
private static final long serialVersionUID = -5861754850637792928L;
- public SessionLockLostException()
- {
+ public SessionLockLostException() {
super(false);
}
- public SessionLockLostException(String message)
- {
+ public SessionLockLostException(String message) {
super(false, message);
}
- public SessionLockLostException(Throwable cause)
- {
+ public SessionLockLostException(Throwable cause) {
super(false, cause);
}
- public SessionLockLostException(String message, Throwable cause)
- {
+ public SessionLockLostException(String message, Throwable cause) {
super(false, message, cause);
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SettleModePair.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SettleModePair.java
index 299730fcd8ec..19daa3c1575d 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SettleModePair.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/SettleModePair.java
@@ -10,8 +10,7 @@ public class SettleModePair {
private final SenderSettleMode senderSettleMode;
private final ReceiverSettleMode receiverSettleMode;
- public SettleModePair(SenderSettleMode senderSettleMode, ReceiverSettleMode receiverSettleMode)
- {
+ public SettleModePair(SenderSettleMode senderSettleMode, ReceiverSettleMode receiverSettleMode) {
this.senderSettleMode = senderSettleMode;
this.receiverSettleMode = receiverSettleMode;
}
@@ -25,8 +24,7 @@ public ReceiverSettleMode getReceiverSettleMode() {
}
@Override
- public String toString()
- {
+ public String toString() {
return String.format("sender settle mode: %s, receiver settle mode: %s", this.senderSettleMode, this.receiverSettleMode);
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/StringUtil.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/StringUtil.java
index 5fd4f819e32d..d77e3e767b55 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/StringUtil.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/StringUtil.java
@@ -7,25 +7,21 @@
import java.nio.charset.StandardCharsets;
import java.util.UUID;
-public final class StringUtil
-{
- public final static String EMPTY = "";
- private final static Charset UTF8CharSet = StandardCharsets.UTF_8;
+public final class StringUtil {
+ public static final String EMPTY = "";
+ private static final Charset UTF8_CHAR_SET = StandardCharsets.UTF_8;
- public static boolean isNullOrEmpty(String string)
- {
+ public static boolean isNullOrEmpty(String string) {
return (string == null || string.isEmpty());
}
- public static boolean isNullOrWhiteSpace(String string)
- {
- if (string == null)
+ public static boolean isNullOrWhiteSpace(String string) {
+ if (string == null) {
return true;
+ }
- for (int index=0; index < string.length(); index++)
- {
- if (!Character.isWhitespace(string.charAt(index)))
- {
+ for (int index = 0; index < string.length(); index++) {
+ if (!Character.isWhitespace(string.charAt(index))) {
return false;
}
}
@@ -33,23 +29,19 @@ public static boolean isNullOrWhiteSpace(String string)
return true;
}
- public static String getShortRandomString()
- {
+ public static String getShortRandomString() {
return getRandomString().substring(0, 6);
}
- public static String getRandomString()
- {
+ public static String getRandomString() {
return UUID.randomUUID().toString();
}
- static String convertBytesToString(byte[] bytes)
- {
- return new String(bytes, UTF8CharSet);
+ static String convertBytesToString(byte[] bytes) {
+ return new String(bytes, UTF8_CHAR_SET);
}
- static byte[] convertStringToBytes(String string)
- {
- return string.getBytes(UTF8CharSet);
+ static byte[] convertStringToBytes(String string) {
+ return string.getBytes(UTF8_CHAR_SET);
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutException.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutException.java
index 78519f9a3f76..6164bf18cec3 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutException.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutException.java
@@ -9,30 +9,25 @@
* @see http://go.microsoft.com/fwlink/?LinkId=761101
* @since 1.0
*/
-public class TimeoutException extends ServiceBusException
-{
+public class TimeoutException extends ServiceBusException {
private static final long serialVersionUID = -3505469991851121512L;
/**
* Default constructor for exception type.
*/
- public TimeoutException()
- {
+ public TimeoutException() {
super(true);
}
- public TimeoutException(final String message)
- {
+ public TimeoutException(final String message) {
super(true, message);
}
- public TimeoutException(final Throwable cause)
- {
+ public TimeoutException(final Throwable cause) {
super(true, cause);
}
- public TimeoutException(final String message, final Throwable cause)
- {
+ public TimeoutException(final String message, final Throwable cause) {
super(true, message, cause);
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutTracker.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutTracker.java
index 455bce0c09e5..e493fe320825 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutTracker.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimeoutTracker.java
@@ -3,10 +3,11 @@
package com.microsoft.azure.servicebus.primitives;
-import java.time.*;
-public class TimeoutTracker
-{
+import java.time.Duration;
+import java.time.Instant;
+
+public class TimeoutTracker {
private final Duration originalTimeout;
private boolean isTimerStarted;
private Instant startTime;
@@ -15,37 +16,30 @@ public class TimeoutTracker
* @param timeout original operationTimeout
* @param startTrackingTimeout whether/not to start the timeout tracking - right now. if not started now, timer tracking will start upon the first call to {@link TimeoutTracker#elapsed()}/{@link TimeoutTracker#remaining()}
*/
- public TimeoutTracker(Duration timeout, boolean startTrackingTimeout)
- {
- if (timeout.compareTo(Duration.ZERO) < 0)
- {
+ public TimeoutTracker(Duration timeout, boolean startTrackingTimeout) {
+ if (timeout.compareTo(Duration.ZERO) < 0) {
throw new IllegalArgumentException("timeout should be non-negative");
}
this.originalTimeout = timeout;
- if (startTrackingTimeout)
- {
+ if (startTrackingTimeout) {
this.startTime = Instant.now();
}
this.isTimerStarted = startTrackingTimeout;
}
- public static TimeoutTracker create(Duration timeout)
- {
+ public static TimeoutTracker create(Duration timeout) {
return new TimeoutTracker(timeout, true);
}
- public Duration remaining()
- {
+ public Duration remaining() {
return this.originalTimeout.minus(this.elapsed());
}
- public Duration elapsed()
- {
- if (!this.isTimerStarted)
- {
+ public Duration elapsed() {
+ if (!this.isTimerStarted) {
this.startTime = Instant.now();
this.isTimerStarted = true;
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Timer.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Timer.java
index bb49a338aeec..58efa7440803 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Timer.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Timer.java
@@ -17,57 +17,45 @@
/**
* An abstraction for a Scheduler functionality - which can later be replaced by a light-weight Thread
*/
-final public class Timer
-{
+public final class Timer {
private static ScheduledExecutorService executor = null;
private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(Timer.class);
- private static final HashSet references = new HashSet();
- private static final Object syncReferences = new Object();
+ private static final HashSet REFERENCES = new HashSet<>();
+ private static final Object SYNC_REFERENCES = new Object();
- private Timer()
- {
+ private Timer() {
}
// runFrequency implemented only for TimeUnit granularity - Seconds
- public static ScheduledFuture> schedule(Runnable runnable, Duration runFrequency, TimerType timerType)
- {
- switch (timerType)
- {
- case OneTimeRun:
- return executor.schedule(runnable, runFrequency.toMillis(), TimeUnit.MILLISECONDS);
-
- case RepeatRun:
- return executor.scheduleWithFixedDelay(runnable, runFrequency.toMillis(), runFrequency.toMillis(), TimeUnit.MILLISECONDS);
-
- default:
- throw new UnsupportedOperationException("Unsupported timer pattern.");
+ public static ScheduledFuture> schedule(Runnable runnable, Duration runFrequency, TimerType timerType) {
+ switch (timerType) {
+ case OneTimeRun:
+ return executor.schedule(runnable, runFrequency.toMillis(), TimeUnit.MILLISECONDS);
+ case RepeatRun:
+ return executor.scheduleWithFixedDelay(runnable, runFrequency.toMillis(), runFrequency.toMillis(), TimeUnit.MILLISECONDS);
+ default:
+ throw new UnsupportedOperationException("Unsupported timer pattern.");
}
}
- static void register(final String clientId)
- {
- synchronized (syncReferences)
- {
- if (references.size() == 0 && (executor == null || executor.isShutdown()))
- {
+ static void register(final String clientId) {
+ synchronized (SYNC_REFERENCES) {
+ if (REFERENCES.size() == 0 && (executor == null || executor.isShutdown())) {
final int corePoolSize = Math.max(Runtime.getRuntime().availableProcessors(), 4);
TRACE_LOGGER.debug("Starting ScheduledThreadPoolExecutor with coreThreadPoolSize:{}", corePoolSize);
executor = Executors.newScheduledThreadPool(corePoolSize);
}
- references.add(clientId);
+ REFERENCES.add(clientId);
}
}
- static void unregister(final String clientId)
- {
- synchronized (syncReferences)
- {
- if (references.remove(clientId) && references.size() == 0 && executor != null)
- {
+ static void unregister(final String clientId) {
+ synchronized (SYNC_REFERENCES) {
+ if (REFERENCES.remove(clientId) && REFERENCES.size() == 0 && executor != null) {
TRACE_LOGGER.debug("Shuting down ScheduledThreadPoolExecutor");
executor.shutdownNow();
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimerType.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimerType.java
index 4af542ed223f..414447c5c44f 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimerType.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TimerType.java
@@ -3,8 +3,7 @@
package com.microsoft.azure.servicebus.primitives;
-public enum TimerType
-{
+public enum TimerType {
OneTimeRun,
RepeatRun
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TrackingUtil.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TrackingUtil.java
index 6cf5dbc58866..fa09a30effd4 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TrackingUtil.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TrackingUtil.java
@@ -3,22 +3,18 @@
package com.microsoft.azure.servicebus.primitives;
-public final class TrackingUtil
-{
+public final class TrackingUtil {
public static final String TRACKING_ID_TOKEN_SEPARATOR = "_";
- private TrackingUtil()
- {
+ private TrackingUtil() {
}
/**
* parses ServiceBus role identifiers from trackingId
* @return null if no roleIdentifier found
*/
- static String parseRoleIdentifier(final String trackingId)
- {
- if (StringUtil.isNullOrWhiteSpace(trackingId) || !trackingId.contains(TRACKING_ID_TOKEN_SEPARATOR))
- {
+ static String parseRoleIdentifier(final String trackingId) {
+ if (StringUtil.isNullOrWhiteSpace(trackingId) || !trackingId.contains(TRACKING_ID_TOKEN_SEPARATOR)) {
return null;
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TransportType.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TransportType.java
index 64621924f880..31b1c7740419 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TransportType.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/TransportType.java
@@ -19,23 +19,18 @@ public enum TransportType {
private final String value;
- TransportType(final String value)
- {
+ TransportType(final String value) {
this.value = value;
}
@Override
- public String toString()
- {
+ public String toString() {
return this.value;
}
- static TransportType fromString(final String value)
- {
- for (TransportType transportType : values())
- {
- if (transportType.value.equalsIgnoreCase(value))
- {
+ static TransportType fromString(final String value) {
+ for (TransportType transportType : values()) {
+ if (transportType.value.equalsIgnoreCase(value)) {
return transportType;
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/UpdateStateWorkItem.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/UpdateStateWorkItem.java
index 3a4e63b2b5c4..34357c176164 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/UpdateStateWorkItem.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/UpdateStateWorkItem.java
@@ -11,12 +11,12 @@
class UpdateStateWorkItem extends WorkItem {
final DeliveryState deliveryState;
- public UpdateStateWorkItem(final CompletableFuture completableFuture, DeliveryState expectedOutcome, Duration timeout) {
+ UpdateStateWorkItem(final CompletableFuture completableFuture, DeliveryState expectedOutcome, Duration timeout) {
super(completableFuture, new TimeoutTracker(timeout, true));
this.deliveryState = expectedOutcome;
}
- public UpdateStateWorkItem(final CompletableFuture completableFuture, DeliveryState expectedOutcome, final TimeoutTracker tracker) {
+ UpdateStateWorkItem(final CompletableFuture completableFuture, DeliveryState expectedOutcome, final TimeoutTracker tracker) {
super(completableFuture, tracker);
this.deliveryState = expectedOutcome;
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Util.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Util.java
index ba687c60721f..fbbff9bb092e 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Util.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/Util.java
@@ -43,148 +43,120 @@
import com.microsoft.azure.servicebus.security.SharedAccessSignatureTokenProvider;
import com.microsoft.azure.servicebus.security.TokenProvider;
-public class Util
-{
- private static final long EPOCHINDOTNETTICKS = 621355968000000000l;
+public class Util {
+ private static final long EPOCHINDOTNETTICKS = 621355968000000000L;
private static final int GUIDSIZE = 16;
- private Util()
- {
+ private Util() {
}
- static int sizeof(Object obj)
- {
- if(obj == null)
- {
+ static int sizeof(Object obj) {
+ if (obj == null) {
return 0;
}
- if (obj instanceof String)
- {
+ if (obj instanceof String) {
return obj.toString().length() << 1;
}
- if (obj instanceof Symbol)
- {
+ if (obj instanceof Symbol) {
return ((Symbol) obj).length() << 1;
}
- if (obj instanceof Byte || obj instanceof UnsignedByte)
- {
+ if (obj instanceof Byte || obj instanceof UnsignedByte) {
return Byte.BYTES;
}
- if (obj instanceof Integer || obj instanceof UnsignedInteger)
- {
+ if (obj instanceof Integer || obj instanceof UnsignedInteger) {
return Integer.BYTES;
}
- if (obj instanceof Long || obj instanceof UnsignedLong || obj instanceof Date)
- {
+ if (obj instanceof Long || obj instanceof UnsignedLong || obj instanceof Date) {
return Long.BYTES;
}
- if (obj instanceof Short || obj instanceof UnsignedShort)
- {
+ if (obj instanceof Short || obj instanceof UnsignedShort) {
return Short.BYTES;
}
- if (obj instanceof Boolean)
- {
+ if (obj instanceof Boolean) {
return 1;
}
- if (obj instanceof Character)
- {
+ if (obj instanceof Character) {
return 4;
}
- if (obj instanceof Float)
- {
+ if (obj instanceof Float) {
return Float.BYTES;
}
- if (obj instanceof Double)
- {
+ if (obj instanceof Double) {
return Double.BYTES;
}
- if (obj instanceof UUID)
- {
+ if (obj instanceof UUID) {
// UUID is internally represented as 16 bytes. But how does ProtonJ encode it? To be safe..we can treat it as a string of 36 chars = 72 bytes.
//return 72;
return 16;
}
- if(obj instanceof Decimal32)
- {
+ if (obj instanceof Decimal32) {
return 4;
}
- if(obj instanceof Decimal64)
- {
+ if (obj instanceof Decimal64) {
return 8;
}
- if(obj instanceof Decimal128)
- {
+ if (obj instanceof Decimal128) {
return 16;
}
- if (obj instanceof Binary)
- {
- return ((Binary)obj).getLength();
+ if (obj instanceof Binary) {
+ return ((Binary) obj).getLength();
}
- if (obj instanceof Declare)
- {
+ if (obj instanceof Declare) {
// Empty declare command takes up 7 bytes.
return 7;
}
- if (obj instanceof Discharge)
- {
+ if (obj instanceof Discharge) {
Discharge discharge = (Discharge) obj;
return 12 + discharge.getTxnId().getLength();
}
- if (obj instanceof Map)
- {
+ if (obj instanceof Map) {
// Size and Count each take a max of 4 bytes
int size = 8;
Map map = (Map) obj;
- for(Object value: map.keySet())
- {
+ for (Object value : map.keySet()) {
size += Util.sizeof(value);
}
- for(Object value: map.values())
- {
+ for (Object value : map.values()) {
size += Util.sizeof(value);
}
return size;
}
- if (obj instanceof Iterable)
- {
+ if (obj instanceof Iterable) {
// Size and Count each take a max of 4 bytes
int size = 8;
- for(Object innerObject : (Iterable)obj)
- {
+ for (Object innerObject : (Iterable) obj) {
size += Util.sizeof(innerObject);
}
return size;
}
- if(obj.getClass().isArray())
- {
+ if (obj.getClass().isArray()) {
// Size and Count each take a max of 4 bytes
int size = 8;
int length = Array.getLength(obj);
- for(int i=0; i encodeMessageToOptimalSizeArray(Message message, int maxMessageSize) throws PayloadSizeExceededException
- {
+ static Pair encodeMessageToOptimalSizeArray(Message message, int maxMessageSize) throws PayloadSizeExceededException {
int payloadSize = Util.getDataSerializedSize(message);
int allocationSize = Math.min(payloadSize + ClientConstants.MAX_MESSAGING_AMQP_HEADER_SIZE_BYTES, maxMessageSize);
byte[] encodedBytes = new byte[allocationSize];
int encodedSize = encodeMessageToCustomArray(message, encodedBytes, 0, allocationSize);
- return new Pair(encodedBytes, encodedSize);
+ return new Pair<>(encodedBytes, encodedSize);
}
- static Pair encodeMessageToMaxSizeArray(Message message, int maxMessageSize) throws PayloadSizeExceededException
- {
+ static Pair encodeMessageToMaxSizeArray(Message message, int maxMessageSize) throws PayloadSizeExceededException {
// May be we should reduce memory allocations. Use a pool of byte arrays or something
byte[] encodedBytes = new byte[maxMessageSize];
int encodedSize = encodeMessageToCustomArray(message, encodedBytes, 0, maxMessageSize);
- return new Pair(encodedBytes, encodedSize);
+ return new Pair<>(encodedBytes, encodedSize);
}
- static int encodeMessageToCustomArray(Message message, byte[] encodedBytes, int offset, int length) throws PayloadSizeExceededException
- {
- try
- {
+ static int encodeMessageToCustomArray(Message message, byte[] encodedBytes, int offset, int length) throws PayloadSizeExceededException {
+ try {
return message.encode(encodedBytes, offset, length);
- }
- catch(BufferOverflowException exception)
- {
+ } catch (BufferOverflowException exception) {
throw new PayloadSizeExceededException(String.format("Size of the payload exceeded Maximum message size: %s KB", length / 1024), exception);
}
}
// Pass little less than client timeout to the server so client doesn't time out before server times out
- public static Duration adjustServerTimeout(Duration clientTimeout)
- {
+ public static Duration adjustServerTimeout(Duration clientTimeout) {
return clientTimeout.minusMillis(100);
}
// This is not super stable for some reason
- static Message readMessageFromDelivery(Receiver receiveLink, Delivery delivery)
- {
+ static Message readMessageFromDelivery(Receiver receiveLink, Delivery delivery) {
int msgSize = delivery.pending();
byte[] buffer = new byte[msgSize];
@@ -418,14 +359,10 @@ static Message readMessageFromDelivery(Receiver receiveLink, Delivery delivery)
return message;
}
- public static URI convertNamespaceToEndPointURI(String namespaceName)
- {
- try
- {
+ public static URI convertNamespaceToEndPointURI(String namespaceName) {
+ try {
return new URI(String.format(Locale.US, ClientConstants.END_POINT_FORMAT, namespaceName));
- }
- catch(URISyntaxException exception)
- {
+ } catch (URISyntaxException exception) {
throw new IllegalConnectionStringFormatException(
String.format(Locale.US, "Invalid namespace name: %s", namespaceName),
exception);
@@ -433,46 +370,33 @@ public static URI convertNamespaceToEndPointURI(String namespaceName)
}
@SuppressWarnings("deprecation")
- public static ClientSettings getClientSettingsFromConnectionStringBuilder(ConnectionStringBuilder builder)
- {
+ public static ClientSettings getClientSettingsFromConnectionStringBuilder(ConnectionStringBuilder builder) {
TokenProvider tokenProvider;
- if(builder.getSharedAccessSignatureToken() == null)
- {
+ if (builder.getSharedAccessSignatureToken() == null) {
tokenProvider = new SharedAccessSignatureTokenProvider(builder.getSasKeyName(), builder.getSasKey(), SecurityConstants.DEFAULT_SAS_TOKEN_VALIDITY_IN_SECONDS);
- }
- else
- {
+ } else {
tokenProvider = new SharedAccessSignatureTokenProvider(builder.getSharedAccessSignatureToken(), Instant.MAX); // Max validity as we will not generate another token
}
return new ClientSettings(tokenProvider, builder.getRetryPolicy(), builder.getOperationTimeout(), builder.getTransportType());
}
- static int getTokenRenewIntervalInSeconds(int tokenValidityInSeconds)
- {
- if(tokenValidityInSeconds >= 300)
- {
+ static int getTokenRenewIntervalInSeconds(int tokenValidityInSeconds) {
+ if (tokenValidityInSeconds >= 300) {
return tokenValidityInSeconds - 30;
- }
- else if(tokenValidityInSeconds >= 60)
- {
+ } else if (tokenValidityInSeconds >= 60) {
return tokenValidityInSeconds - 10;
- }
- else
- {
+ } else {
return (tokenValidityInSeconds - 1) > 0 ? tokenValidityInSeconds - 1 : 0;
}
}
- static int getMaxMessageSizeFromLink(Link link)
- {
+ static int getMaxMessageSizeFromLink(Link link) {
UnsignedLong maxMessageSize = link.getRemoteMaxMessageSize();
- if(maxMessageSize != null)
- {
+ if (maxMessageSize != null) {
int maxMessageSizeAsInt = maxMessageSize.intValue();
// A value of 0 means no limit. Treating no limit as 1024 KB thus putting a cap on max message size
- if(maxMessageSizeAsInt > 0)
- {
+ if (maxMessageSizeAsInt > 0) {
return maxMessageSizeAsInt;
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/WorkItem.java b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/WorkItem.java
index e1b38e4b041b..6b64e51c3a75 100644
--- a/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/WorkItem.java
+++ b/servicebus/data-plane/azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/WorkItem.java
@@ -3,66 +3,56 @@
package com.microsoft.azure.servicebus.primitives;
-import java.time.*;
-import java.util.concurrent.*;
+import java.time.Duration;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledFuture;
-class WorkItem
-{
+class WorkItem {
private final TimeoutTracker tracker;
private final CompletableFuture work;
private ScheduledFuture> timeoutTask;
private Exception lastKnownException;
- public WorkItem(final CompletableFuture completableFuture, final Duration timeout)
- {
+ WorkItem(final CompletableFuture completableFuture, final Duration timeout) {
this(completableFuture, TimeoutTracker.create(timeout));
}
- public WorkItem(final CompletableFuture completableFuture, final TimeoutTracker tracker)
- {
+ WorkItem(final CompletableFuture completableFuture, final TimeoutTracker tracker) {
this.work = completableFuture;
this.tracker = tracker;
}
- public TimeoutTracker getTimeoutTracker()
- {
+ public TimeoutTracker getTimeoutTracker() {
return this.tracker;
}
// TODO; remove this method. Synchronize calls to complete on the future so two different threads don't attempt to complete at the same time.
// Also group complete and canceling timeout task in one method so calling code doesn't have to call both of them one after the other.
- public CompletableFuture getWork()
- {
+ public CompletableFuture getWork() {
return this.work;
}
- public ScheduledFuture> getTimeoutTask()
- {
+ public ScheduledFuture> getTimeoutTask() {
return this.timeoutTask;
}
- public void setTimeoutTask(final ScheduledFuture> timeoutTask)
- {
+ public void setTimeoutTask(final ScheduledFuture> timeoutTask) {
this.timeoutTask = timeoutTask;
}
- public boolean cancelTimeoutTask(boolean mayInterruptIfRunning)
- {
- if(this.timeoutTask != null)
- {
+ public boolean cancelTimeoutTask(boolean mayInterruptIfRunning) {
+ if (this.timeoutTask != null) {
return this.timeoutTask.cancel(mayInterruptIfRunning);
}
return false;
}
- public Exception getLastKnownException()
- {
+ public Exception getLastKnownException() {
return this.lastKnownException;
}
- public void setLastKnownException(Exception exception)
- {
+ public void setLastKnownException(Exception exception) {
this.lastKnownException = exception;
}
}
diff --git a/servicebus/data-plane/azure-servicebus/src/test/java/com/microsoft/azure/servicebus/primitives/UtilsTests.java b/servicebus/data-plane/azure-servicebus/src/test/java/com/microsoft/azure/servicebus/primitives/UtilsTests.java
index fd1d0298021c..6c574a8e3b65 100644
--- a/servicebus/data-plane/azure-servicebus/src/test/java/com/microsoft/azure/servicebus/primitives/UtilsTests.java
+++ b/servicebus/data-plane/azure-servicebus/src/test/java/com/microsoft/azure/servicebus/primitives/UtilsTests.java
@@ -8,8 +8,6 @@
import org.junit.Test;
-import com.microsoft.azure.servicebus.primitives.Util;
-
import org.junit.Assert;
public class UtilsTests {
@@ -18,7 +16,7 @@ public void testGuidConversionFromDotNetToJava() {
String guidString = "b5dc4a70-ac5d-43b3-b132-ec8fcdac3a9d";
// Java bytes are signed where as dotNet bytes are unsigned. No problem type casting larger than 127 unsigned bytes to java signed bytes
// as we are interested only in the individual bits for UUID conversion.
- byte[] dotNetGuidBytes = {112, 74, (byte)220, (byte)181, 93, (byte)172, (byte)179, 67, (byte)177, 50, (byte)236, (byte)143, (byte)205, (byte)172, 58, (byte)157};
+ byte[] dotNetGuidBytes = {112, 74, (byte) 220, (byte) 181, 93, (byte) 172, (byte) 179, 67, (byte) 177, 50, (byte) 236, (byte) 143, (byte) 205, (byte) 172, 58, (byte) 157};
UUID convertedGuid = Util.convertDotNetBytesToUUID(dotNetGuidBytes);
Assert.assertEquals("UUID conversion from DotNet to Java failed", guidString, convertedGuid.toString());
}
@@ -27,7 +25,7 @@ public void testGuidConversionFromDotNetToJava() {
public void testGuidConversionFromJavaToDotNet() {
String guidString = "b5dc4a70-ac5d-43b3-b132-ec8fcdac3a9d";
UUID javaGuid = UUID.fromString(guidString);
- byte[] dotNetGuidBytes = {112, 74, (byte)220, (byte)181, 93, (byte)172, (byte)179, 67, (byte)177, 50, (byte)236, (byte)143, (byte)205, (byte)172, 58, (byte)157};
+ byte[] dotNetGuidBytes = {112, 74, (byte) 220, (byte) 181, 93, (byte) 172, (byte) 179, 67, (byte) 177, 50, (byte) 236, (byte) 143, (byte) 205, (byte) 172, 58, (byte) 157};
byte[] convertedBytes = Util.convertUUIDToDotNetBytes(javaGuid);
Assert.assertArrayEquals("UUID conversion from Java to DotNet failed", dotNetGuidBytes, convertedBytes);
}
@@ -35,7 +33,7 @@ public void testGuidConversionFromJavaToDotNet() {
@Test
public void testDateTimeConversionFromDotNetToJava() {
String dotNetDateTimeString = "2016-11-30T20:57:01.4638052Z";
- long dotNetTicks = 636161362214638052l;
+ long dotNetTicks = 636161362214638052L;
Instant convertedInstant = Util.convertDotNetTicksToInstant(dotNetTicks);
Instant expectedInstant = Instant.parse(dotNetDateTimeString);
Assert.assertEquals("DateTime conversion from DotNet to Java failed", expectedInstant, convertedInstant);
@@ -44,7 +42,7 @@ public void testDateTimeConversionFromDotNetToJava() {
@Test
public void testDateTimeConversionFromJavaToDotNet() {
String dotNetDateTimeString = "2016-11-30T20:57:01.4638052Z";
- long dotNetTicks = 636161362214638052l;
+ long dotNetTicks = 636161362214638052L;
Instant javaInstant = Instant.parse(dotNetDateTimeString);
Assert.assertEquals("DateTime conversion from Java to DotNet failed", dotNetTicks, Util.convertInstantToDotNetTicks(javaInstant));
}