All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.servicebus.primitives.WorkItem Maven / Gradle / Ivy

Go to download

Java library for Azure Service Bus. Please note, a newer package com.azure:azure-messaging-servicebus for Azure Service Bus is available as of December 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide at https://aka.ms/azsdk/java/migrate/sb for more details.

There is a newer version: 3.6.7
Show newest version
/*
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */
package com.microsoft.azure.servicebus.primitives;

import java.time.*;
import java.util.concurrent.*;

class WorkItem
{
	private final TimeoutTracker tracker;
	private final CompletableFuture work;
	private ScheduledFuture timeoutTask;
	private Exception lastKnownException;

	public WorkItem(final CompletableFuture completableFuture, final Duration timeout)
	{
		this(completableFuture, TimeoutTracker.create(timeout));
	}

	public WorkItem(final CompletableFuture completableFuture, final TimeoutTracker tracker)
	{
		this.work = completableFuture;
		this.tracker = tracker;
	}

	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()
	{
		return this.work;
	}
	
	public ScheduledFuture getTimeoutTask()
	{
		return this.timeoutTask;
	}
	
	public void setTimeoutTask(final ScheduledFuture timeoutTask)
	{
		this.timeoutTask = timeoutTask;
	}
	
	public boolean cancelTimeoutTask(boolean mayInterruptIfRunning)
	{
		if(this.timeoutTask != null)
		{
		    return this.timeoutTask.cancel(mayInterruptIfRunning);
		}
		
		return false;
	}
	
	public Exception getLastKnownException()
	{
		return this.lastKnownException;
	}

	public void setLastKnownException(Exception exception)
	{
		this.lastKnownException = exception;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy