use of android.util.MutableBoolean in project android_frameworks_base by crdroidandroid.
the class EventBus method registerSubscriber.
/**
* Registers a new subscriber.
*/
private void registerSubscriber(Object subscriber, int priority, MutableBoolean hasInterprocessEventsChangedOut) {
// Fail immediately if we are being called from the non-main thread
long callingThreadId = Thread.currentThread().getId();
if (callingThreadId != mHandler.getLooper().getThread().getId()) {
throw new RuntimeException("Can not register() a subscriber from a non-main thread.");
}
// Return immediately if this exact subscriber is already registered
if (findRegisteredSubscriber(subscriber, false)) {
return;
}
long t1 = 0;
if (DEBUG_TRACE_ALL) {
t1 = SystemClock.currentTimeMicro();
logWithPid("registerSubscriber(" + subscriber.getClass().getSimpleName() + ")");
}
Subscriber sub = new Subscriber(subscriber, SystemClock.uptimeMillis());
Class<?> subscriberType = subscriber.getClass();
ArrayList<EventHandlerMethod> subscriberMethods = mSubscriberTypeMap.get(subscriberType);
if (subscriberMethods != null) {
if (DEBUG_TRACE_ALL) {
logWithPid("Subscriber class type already registered");
}
// events
for (EventHandlerMethod method : subscriberMethods) {
ArrayList<EventHandler> eventTypeHandlers = mEventTypeMap.get(method.eventType);
eventTypeHandlers.add(new EventHandler(sub, method, priority));
sortEventHandlersByPriority(eventTypeHandlers);
}
mSubscribers.add(sub);
return;
} else {
if (DEBUG_TRACE_ALL) {
logWithPid("Subscriber class type requires registration");
}
// If we are parsing this type from scratch, ensure we add it to the subscriber type
// map, and pull out he handler methods below
subscriberMethods = new ArrayList<>();
mSubscriberTypeMap.put(subscriberType, subscriberMethods);
mSubscribers.add(sub);
}
// Find all the valid event bus handler methods of the subscriber
MutableBoolean isInterprocessEvent = new MutableBoolean(false);
Method[] methods = subscriberType.getDeclaredMethods();
for (Method m : methods) {
Class<?>[] parameterTypes = m.getParameterTypes();
isInterprocessEvent.value = false;
if (isValidEventBusHandlerMethod(m, parameterTypes, isInterprocessEvent)) {
Class<? extends Event> eventType = (Class<? extends Event>) parameterTypes[0];
ArrayList<EventHandler> eventTypeHandlers = mEventTypeMap.get(eventType);
if (eventTypeHandlers == null) {
eventTypeHandlers = new ArrayList<>();
mEventTypeMap.put(eventType, eventTypeHandlers);
}
if (isInterprocessEvent.value) {
try {
// Enforce that the event must have a Bundle constructor
eventType.getConstructor(Bundle.class);
mInterprocessEventNameMap.put(eventType.getName(), (Class<? extends InterprocessEvent>) eventType);
if (hasInterprocessEventsChangedOut != null) {
hasInterprocessEventsChangedOut.value = true;
}
} catch (NoSuchMethodException e) {
throw new RuntimeException("Expected InterprocessEvent to have a Bundle constructor");
}
}
EventHandlerMethod method = new EventHandlerMethod(m, eventType);
EventHandler handler = new EventHandler(sub, method, priority);
eventTypeHandlers.add(handler);
subscriberMethods.add(method);
sortEventHandlersByPriority(eventTypeHandlers);
if (DEBUG_TRACE_ALL) {
logWithPid(" * Method: " + m.getName() + " event: " + parameterTypes[0].getSimpleName() + " interprocess? " + isInterprocessEvent.value);
}
}
}
if (DEBUG_TRACE_ALL) {
logWithPid("Registered " + subscriber.getClass().getSimpleName() + " in " + (SystemClock.currentTimeMicro() - t1) + " microseconds");
}
}
use of android.util.MutableBoolean in project android_frameworks_base by crdroidandroid.
the class SQLiteConnection method collectDbStats.
/**
* Collects statistics about database connection memory usage.
*
* @param dbStatsList The list to populate.
*/
void collectDbStats(ArrayList<DbStats> dbStatsList) {
// Get information about the main database.
int lookaside = nativeGetDbLookaside(mConnectionPtr);
long pageCount = 0;
long pageSize = 0;
try {
pageCount = executeForLong("PRAGMA page_count;", null, null);
pageSize = executeForLong("PRAGMA page_size;", null, null);
} catch (SQLiteException ex) {
// Ignore.
}
dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
// Get information about attached databases.
// We ignore the first row in the database list because it corresponds to
// the main database which we have already described.
CursorWindow window = new CursorWindow("collectDbStats");
MutableBoolean exh = new MutableBoolean(false);
MutableInt seen = new MutableInt(0);
try {
executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null, exh, seen, null);
for (int i = 1; i < window.getNumRows(); i++) {
String name = window.getString(i, 1);
String path = window.getString(i, 2);
pageCount = 0;
pageSize = 0;
try {
pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
} catch (SQLiteException ex) {
// Ignore.
}
String label = " (attached) " + name;
if (!path.isEmpty()) {
label += ": " + path;
}
dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
}
} catch (SQLiteException ex) {
// Ignore.
} finally {
window.close();
}
}
use of android.util.MutableBoolean in project android_frameworks_base by crdroidandroid.
the class SQLiteCursor method traverseQuery.
private void traverseQuery(int startPos, int requiredPos, CursorWindow w, boolean countAll) {
try {
MutableBoolean exhausted = mTmpBoolean;
exhausted.value = false;
final int found = mQuery.traverse(w, startPos, requiredPos, countAll, exhausted);
if (w != null && mCursorWindowCapacity == 0) {
mCursorWindowCapacity = w.getNumRows();
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "received count(*) from native_fill_window: " + mCount);
}
}
if (exhausted.value) {
// we exhausted the whole result set, so we know the count.
mCount = mFound = found;
} else {
mFound = Math.max(mFound, found);
}
} catch (RuntimeException ex) {
// Close the cursor window if the query failed and therefore will
// not produce any results. This helps to avoid accidentally leaking
// the cursor window if the client does not correctly handle exceptions
// and fails to close the cursor.
closeWindow();
throw ex;
}
}
Aggregations