New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pulsar-broker] Handle multiple topic creation for same topic-name in broker #10847
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ | |
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -162,4 +164,33 @@ public synchronized Throwable fillInStackTrace() { | |
return this; | ||
} | ||
} | ||
|
||
public static <T> CompletableFuture<T> futureWithDeadline(ScheduledExecutorService executor, Long delay, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between this and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is an existing method just moved to |
||
TimeUnit unit, Exception exp) { | ||
CompletableFuture<T> future = new CompletableFuture<T>(); | ||
executor.schedule(() -> { | ||
if (!future.isDone()) { | ||
future.completeExceptionally(exp); | ||
} | ||
}, delay, unit); | ||
return future; | ||
} | ||
|
||
public static <T> CompletableFuture<T> futureWithDeadline(ScheduledExecutorService executor) { | ||
return futureWithDeadline(executor, 60000L, TimeUnit.MILLISECONDS, | ||
new TimeoutException("Future didn't finish within deadline")); | ||
} | ||
|
||
public static <T> Optional<Throwable> getException(CompletableFuture<T> future) { | ||
if (future != null && future.isCompletedExceptionally()) { | ||
try { | ||
future.get(); | ||
} catch (InterruptedException e) { | ||
return Optional.ofNullable(e); | ||
} catch (ExecutionException e) { | ||
return Optional.ofNullable(e.getCause()); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need change
futureWithDeadline()
toFutureUtil.futureWithDeadline(executor())
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a utility method for Future so, it should be part of
FutureUtil