Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,41 @@
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;
}
}

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@
* @see <a href="http://go.microsoft.com/fwlink/?LinkId=761101">http://go.microsoft.com/fwlink/?LinkId=761101</a>
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> references = new HashSet<String>();
private static final Object syncReferences = new Object();
private static final HashSet<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

package com.microsoft.azure.servicebus.primitives;

public enum TimerType
{
public enum TimerType {
OneTimeRun,
RepeatRun
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
class UpdateStateWorkItem extends WorkItem<Void> {
final DeliveryState deliveryState;

public UpdateStateWorkItem(final CompletableFuture<Void> completableFuture, DeliveryState expectedOutcome, Duration timeout) {
UpdateStateWorkItem(final CompletableFuture<Void> completableFuture, DeliveryState expectedOutcome, Duration timeout) {
super(completableFuture, new TimeoutTracker(timeout, true));
this.deliveryState = expectedOutcome;
}

public UpdateStateWorkItem(final CompletableFuture<Void> completableFuture, DeliveryState expectedOutcome, final TimeoutTracker tracker) {
UpdateStateWorkItem(final CompletableFuture<Void> completableFuture, DeliveryState expectedOutcome, final TimeoutTracker tracker) {
super(completableFuture, tracker);
this.deliveryState = expectedOutcome;
}
Expand Down
Loading