1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.async; 18 19 import com.google.common.base.Supplier; 20 21 import java.util.concurrent.Executor; 22 23 import javax.annotation.CheckReturnValue; 24 import javax.annotation.Nonnull; 25 import javax.annotation.ParametersAreNonnullByDefault; 26 import javax.annotation.concurrent.ThreadSafe; 27 28 /** 29 * An interface for thread-safe observable objects. 30 */ 31 @ThreadSafe 32 @ParametersAreNonnullByDefault 33 public interface Observable<T> extends Supplier<T> { 34 /** 35 * Adds the given callback to be invoked upon changes, returning a handle to 36 * be closed when the callback must be deregistered. 37 * <p> 38 * Note that the callback may be invoked multiple times even if the value 39 * has not actually changed. 40 * 41 * @param callback The callback to add. 42 * @param executor The executor on which the callback will be invoked. 43 * @return A handle to be closed when the callback must be removed. 44 */ 45 @Nonnull 46 @CheckReturnValue 47 public SafeCloseable addCallback(Runnable callback, Executor executor); 48 49 /** 50 * @return The current/latest value. 51 */ 52 @Nonnull 53 @Override 54 public T get(); 55 } 56