Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also merge TrivialProxyService into ProxyService
- Loading branch information
1 parent
b24bcb4
commit 5abd97d
Showing
18 changed files
with
272 additions
and
79 deletions.
There are no files selected for viewing
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
45 changes: 45 additions & 0 deletions
45
...e-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/MoreApiFutures.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,45 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 com.google.cloud.pubsublite.internal; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.core.ApiFutureCallback; | ||
import com.google.api.core.ApiFutures; | ||
import com.google.api.core.SettableApiFuture; | ||
import com.google.cloud.pubsublite.internal.wire.SystemExecutors; | ||
|
||
public final class MoreApiFutures { | ||
private MoreApiFutures() {} | ||
|
||
public static <T> void connectFutures( | ||
ApiFuture<T> source, SettableApiFuture<? super T> toConnect) { | ||
ApiFutures.addCallback( | ||
source, | ||
new ApiFutureCallback<T>() { | ||
@Override | ||
public void onFailure(Throwable throwable) { | ||
toConnect.setException(throwable); | ||
} | ||
|
||
@Override | ||
public void onSuccess(T t) { | ||
toConnect.set(t); | ||
} | ||
}, | ||
SystemExecutors.getFuturesExecutor()); | ||
} | ||
} |
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
43 changes: 0 additions & 43 deletions
43
...ud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/TrivialProxyService.java
This file was deleted.
Oops, something went wrong.
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
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
72 changes: 72 additions & 0 deletions
72
...pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/BatchingCommitter.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,72 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 com.google.cloud.pubsublite.internal.wire; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.core.SettableApiFuture; | ||
import com.google.cloud.pubsublite.Offset; | ||
import com.google.cloud.pubsublite.internal.AlarmFactory; | ||
import com.google.cloud.pubsublite.internal.CheckedApiException; | ||
import com.google.cloud.pubsublite.internal.MoreApiFutures; | ||
import com.google.cloud.pubsublite.internal.ProxyService; | ||
import com.google.errorprone.annotations.concurrent.GuardedBy; | ||
import java.util.Optional; | ||
import java.util.concurrent.Future; | ||
|
||
public class BatchingCommitter extends ProxyService implements Committer { | ||
private final Committer underlying; | ||
|
||
@GuardedBy("this") | ||
private SettableApiFuture<Void> currentFuture = SettableApiFuture.create(); | ||
|
||
@GuardedBy("this") | ||
private Optional<Offset> currentOffset = Optional.empty(); | ||
|
||
BatchingCommitter(Committer underlying, AlarmFactory alarmFactory) { | ||
super(underlying); | ||
this.underlying = underlying; | ||
Future<?> alarm = alarmFactory.newAlarm(this::flush); | ||
addServices(ApiServiceUtils.autoCloseableAsApiService(() -> alarm.cancel(false))); | ||
} | ||
|
||
@Override | ||
public synchronized ApiFuture<Void> commitOffset(Offset offset) { | ||
currentOffset = Optional.of(offset); | ||
return currentFuture; | ||
} | ||
|
||
@Override | ||
public void waitUntilEmpty() throws CheckedApiException { | ||
flush(); | ||
underlying.waitUntilEmpty(); | ||
} | ||
|
||
@Override | ||
protected void stop() { | ||
flush(); | ||
} | ||
|
||
private synchronized void flush() { | ||
if (!currentOffset.isPresent()) { | ||
return; | ||
} | ||
ApiFuture<Void> underlyingFuture = underlying.commitOffset(currentOffset.get()); | ||
MoreApiFutures.connectFutures(underlyingFuture, currentFuture); | ||
currentOffset = Optional.empty(); | ||
currentFuture = SettableApiFuture.create(); | ||
} | ||
} |
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
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
Oops, something went wrong.