This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a50af46
commit 9c88929
Showing
4 changed files
with
176 additions
and
44 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/DelayedProduceAndFetch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.streamnative.pulsar.handlers.kop; | ||
|
||
import io.streamnative.pulsar.handlers.kop.utils.delayed.DelayedOperation; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* A delayed create topic operation that is stored in the topic purgatory. | ||
*/ | ||
class DelayedProduceAndFetch extends DelayedOperation { | ||
|
||
private final AtomicInteger topicPartitionNum; | ||
private final Runnable callback; | ||
|
||
DelayedProduceAndFetch(long delayMs, AtomicInteger topicPartitionNum, Runnable callback) { | ||
super(delayMs, Optional.empty()); | ||
this.topicPartitionNum = topicPartitionNum; | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void onExpiration() { | ||
callback.run(); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
callback.run(); | ||
} | ||
|
||
@Override | ||
public boolean tryComplete() { | ||
if (topicPartitionNum.get() <= 0) { | ||
forceComplete(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters