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 javax.annotation.Nonnull; 20 import javax.annotation.concurrent.ThreadSafe; 21 22 /** 23 * A thread-safe callback. 24 * <p> 25 * Depending on how consumers need to access updates, the following 26 * implementations may be used (and already guarantee thread-safety): 27 * <ul> 28 * <li>Synchronous access to every update: {@link ConcurrentBufferQueue}</li> 29 * <li>Synchronous access to a single update: {@link UpdatableCountDownLatch}</li> 30 * <li>Access to the latest value: {@link ConcurrentState}</li> 31 * <li>Callbacks: {@link ConcurrentState}</li> 32 * </ul> 33 * </p> 34 */ 35 @ThreadSafe 36 public interface Updatable<T> { 37 /** 38 * Implementations MUST ALWAYS satisfy the following constraints: 39 * <ul> 40 * <li>Return quickly, without performing any expensive work.</li> 41 * <li>Execute in a predictable, stable, amount of time.</li> 42 * <li>Never block.</li> 43 * <li>Be thread-safe.</li> 44 * <li>Never leak control of the thread on which they are invoked. (e.g. 45 * invoke callbacks which may violate the above constraints)</li> 46 * </ul> 47 */ update(@onnull T t)48 public void update(@Nonnull T t); 49 } 50