use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by ResurrectionRemix.
the class CaptureCollector method previewCaptured.
/**
* Called to alert the {@link CaptureCollector} that the preview capture has begun.
*
* @param timestamp the time of the preview capture.
* @return a pair containing the {@link RequestHolder} and the timestamp of the capture.
*/
public Pair<RequestHolder, Long> previewCaptured(long timestamp) {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mPreviewCaptureQueue.poll();
if (h == null) {
if (DEBUG) {
Log.d(TAG, "previewCaptured called with no preview request on queue!");
}
return null;
}
h.setPreviewTimestamp(timestamp);
return new Pair<>(h.mRequest, h.mTimestamp);
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project ACS by ACS-Community.
the class ManagerImpl method initialize.
/**
* Initializes Manager.
* @param prevayler implementation of prevayler system
* @param context remote directory implementation
*/
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
this.prevayler = prevayler;
this.remoteDirectory = context;
this.logger = logger;
// needs to be done here, since deserialization is used
initializeDefaultConfiguration();
if (cdbAccess != null)
setCDBAccess(cdbAccess);
readManagerConfiguration();
componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
random = new Random();
heartbeatTask = new Timer(true);
delayedDeactivationTask = new Timer(true);
containerLoggedInMonitor = new Object();
activationSynchronization = new HashMap<String, ReferenceCountingLock>();
activationPendingRWLock = new ReaderPreferenceReadWriteLock();
shutdown = new AtomicBoolean(false);
threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
managerCache = new HashMap<String, Manager>();
pendingActivations = new HashMap<String, ComponentInfo>();
pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
threadsUsedPercentage = new AtomicInteger(0);
// create threads
threadPool.prestartAllCoreThreads();
// read CDB startup
try {
String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
if (componentSpec != null) {
cdbActivation = new ComponentSpec(componentSpec);
logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
}
// check load balancing strategy
checkLoadBalancingStrategy();
// establish connect to the alarm system
try {
alarmSource = new AlarmSourceImpl(managerContainerServices);
alarmSource.start();
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
alarmSource = null;
}
// register ping tasks
initializePingTasks();
// handle monitoring removal task
final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
heartbeatTask.schedule(new TimerTask() {
@Override
public void run() {
try {
logHandleCleanup(timeInMs);
} catch (Throwable th) {
logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
}
}
}, 0, timeInMs);
}
// start topology sort manager
topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
if (prevayler == null)
statePersitenceFlag.set(false);
String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
logger.info("Manager initialized with state persistence " + enDis + ".");
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
the class CaptureCollector method failNextPreview.
/**
* Called to alert the {@link CaptureCollector} that the next pending preview capture has failed.
*/
public void failNextPreview() {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h1 = mPreviewCaptureQueue.peek();
CaptureHolder h2 = mPreviewProduceQueue.peek();
// Find the request with the lowest frame number.
CaptureHolder h = (h1 == null) ? h2 : ((h2 == null) ? h1 : ((h1.compareTo(h2) <= 0) ? h1 : h2));
if (h != null) {
mPreviewCaptureQueue.remove(h);
mPreviewProduceQueue.remove(h);
mActiveRequests.remove(h);
h.setPreviewFailed();
}
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
the class CaptureCollector method jpegProduced.
/**
* Called to alert the {@link CaptureCollector} that the jpeg capture has completed.
*
* @return a pair containing the {@link RequestHolder} and the timestamp of the capture.
*/
public Pair<RequestHolder, Long> jpegProduced() {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mJpegProduceQueue.poll();
if (h == null) {
Log.w(TAG, "jpegProduced called with no jpeg request on queue!");
return null;
}
h.setJpegProduced();
return new Pair<>(h.mRequest, h.mTimestamp);
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project android_frameworks_base by DirtyUnicorns.
the class CaptureCollector method previewProduced.
/**
* Called to alert the {@link CaptureCollector} that the preview capture has completed.
*
* @return the {@link RequestHolder} for the request associated with this capture.
*/
public RequestHolder previewProduced() {
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mPreviewProduceQueue.poll();
if (h == null) {
Log.w(TAG, "previewProduced called with no preview request on queue!");
return null;
}
h.setPreviewProduced();
return h.mRequest;
} finally {
lock.unlock();
}
}
Aggregations