|
| 1 | +package org.whispersystems.textsecuregcm.experiment; |
| 2 | + |
| 3 | +import org.whispersystems.textsecuregcm.storage.Account; |
| 4 | +import org.whispersystems.textsecuregcm.storage.Device; |
| 5 | +import javax.annotation.Nullable; |
| 6 | +import java.util.concurrent.CompletableFuture; |
| 7 | + |
| 8 | +/** |
| 9 | + * A push notification selects for eligible devices, applies a control or experimental treatment, and provides a |
| 10 | + * mechanism for comparing device states before and after receiving the treatment. |
| 11 | + * |
| 12 | + * @param <T> the type of state object stored for this experiment |
| 13 | + */ |
| 14 | +public interface PushNotificationExperiment<T> { |
| 15 | + |
| 16 | + /** |
| 17 | + * Returns the unique name of this experiment. |
| 18 | + * |
| 19 | + * @return the unique name of this experiment |
| 20 | + */ |
| 21 | + String getExperimentName(); |
| 22 | + |
| 23 | + /** |
| 24 | + * Tests whether a device is eligible for this experiment. An eligible device may be assigned to either the control |
| 25 | + * or experiment group within an experiment. Ineligible devices will not participate in the experiment in any way. |
| 26 | + * |
| 27 | + * @param account the account to which the device belongs |
| 28 | + * @param device the device to test for eligibility in this experiment |
| 29 | + * |
| 30 | + * @return a future that yields a boolean value indicating whether the target device is eligible for this experiment |
| 31 | + */ |
| 32 | + CompletableFuture<Boolean> isDeviceEligible(Account account, Device device); |
| 33 | + |
| 34 | + /** |
| 35 | + * Generates an experiment specific state "snapshot" of the given device. Experiment results are generally evaluated |
| 36 | + * by comparing a device's state before a treatment is applied and its state after the treatment is applied. |
| 37 | + * |
| 38 | + * @param account the account to which the device belongs |
| 39 | + * @param device the device for which to generate a state "snapshot" |
| 40 | + * |
| 41 | + * @return an experiment-specific state "snapshot" of the given device |
| 42 | + */ |
| 43 | + T getState(@Nullable Account account, @Nullable Device device); |
| 44 | + |
| 45 | + /** |
| 46 | + * Applies a control treatment to the given device. In many cases (and by default) no action is taken for devices in |
| 47 | + * the control group. |
| 48 | + * |
| 49 | + * @param account the account to which the device belongs |
| 50 | + * @param device the device to which to apply the control treatment for this experiment |
| 51 | + * |
| 52 | + * @return a future that completes when the control treatment has been applied for the given device |
| 53 | + */ |
| 54 | + default CompletableFuture<Void> applyControlTreatment(Account account, Device device) { |
| 55 | + return CompletableFuture.completedFuture(null); |
| 56 | + }; |
| 57 | + |
| 58 | + /** |
| 59 | + * Applies an experimental treatment to the given device. This generally involves sending or scheduling a specific |
| 60 | + * type of push notification for the given device. |
| 61 | + * |
| 62 | + * @param account the account to which the device belongs |
| 63 | + * @param device the device to which to apply the experimental treatment for this experiment |
| 64 | + * |
| 65 | + * @return a future that completes when the experimental treatment has been applied for the given device |
| 66 | + */ |
| 67 | + CompletableFuture<Void> applyExperimentTreatment(Account account, Device device); |
| 68 | +} |
0 commit comments