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