forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request googleapis#29 from garrettjonesgoogle/master
Adding a blocking call count threshold
- Loading branch information
Showing
20 changed files
with
700 additions
and
85 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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/google/api/gax/bundling/ExternalThreshold.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,41 @@ | ||
package com.google.api.gax.bundling; | ||
|
||
/** | ||
* The interface representing an external threshold to be used in ThresholdBundler. | ||
* | ||
* An external threshold is a threshold which depends on events external to the | ||
* ThresholdBundler. | ||
* | ||
* Thresholds do not need to be thread-safe if they are only used inside | ||
* ThresholdBundler. | ||
*/ | ||
public interface ExternalThreshold<E> { | ||
|
||
/** | ||
* Called from ThresholdBundler when the first item in a bundle has been added. | ||
* | ||
* Any calls into this function from ThresholdBundler will be under a lock. | ||
*/ | ||
void startBundle(); | ||
|
||
/** | ||
* Called from ThresholdBundler.BundleHandle when externalThresholdEvent is called. | ||
* | ||
* Any calls into this function from ThresholdBundler will be under a lock. | ||
* | ||
* @param bundleHandle if the threshold has been reached, the external threshold | ||
* should call BundleHandle.flushIfNotFlushedYet(). | ||
* @param event the event for the external threshold to handle. If not recognized, | ||
* this external threshold should ignore it. | ||
*/ | ||
void handleEvent(ThresholdBundleHandle bundleHandle, Object event); | ||
|
||
|
||
/** | ||
* Make a copy of this threshold but with the accumulated value zeroed. | ||
* | ||
* Any calls into this function from ThresholdBundler will be under a lock. | ||
*/ | ||
ExternalThreshold<E> copyWithZeroedValue(); | ||
|
||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/google/api/gax/bundling/ThresholdBundleHandle.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,19 @@ | ||
package com.google.api.gax.bundling; | ||
|
||
/** | ||
* A handle to a bundle in a ThresholdBundler. Using this handle, code external | ||
* to a ThresholdBundler can safely ensure that a particular bundle has been | ||
* flushed without accidentally flushing a following bundle. | ||
*/ | ||
public interface ThresholdBundleHandle { | ||
/** | ||
* Notifies the ThresholdBundler of an event for this threshold bundle, which | ||
* is targeted at a particular ExternalThreshold. | ||
*/ | ||
void externalThresholdEvent(Object event); | ||
|
||
/** | ||
* Flush this bundle if it hasn't been flushed yet. | ||
*/ | ||
void flush(); | ||
} |
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.