@DoNotStrip @Override public <T> Future<T> callOnQueue(final Callable<T> callable) { final SimpleSettableFuture<T> future = new SimpleSettableFuture<>(); runOnQueue( new Runnable() { @Override public void run() { try { future.set(callable.call()); } catch (Exception e) { future.setException(e); } } }); return future; }
@DoNotStrip public NativeArray getConstants() { BaseJavaModule baseJavaModule = getModule(); ReactMarker.logMarker(GET_CONSTANTS_START, getName()); SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants") .arg("moduleName", getName()) .flush(); Map<String, Object> map = baseJavaModule.getConstants(); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants") .arg("moduleName", getName()) .flush(); ReactMarker.logMarker(CONVERT_CONSTANTS_START, getName()); WritableNativeMap writableNativeMap; try { writableNativeMap = Arguments.makeNativeMap(map); } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } WritableNativeArray array = new WritableNativeArray(); array.pushMap(writableNativeMap); ReactMarker.logMarker(CONVERT_CONSTANTS_END); ReactMarker.logMarker(GET_CONSTANTS_END); return array; }
@DoNotStrip public List<MethodDescriptor> getMethodDescriptors() { ArrayList<MethodDescriptor> descs = new ArrayList<>(); for (Map.Entry<String, NativeModule.NativeMethod> entry : getModule().getMethods().entrySet()) { MethodDescriptor md = new MethodDescriptor(); md.name = entry.getKey(); md.type = entry.getValue().getType(); BaseJavaModule.JavaMethod method = (BaseJavaModule.JavaMethod) entry.getValue(); if (md.type == BaseJavaModule.METHOD_TYPE_SYNC) { md.signature = method.getSignature(); md.method = method.getMethod(); } mMethods.add(method); descs.add(md); } return descs; }
/** * Moves the helper to the next entry in the map, if any. Returns true iff * there is an entry to read. */ @DoNotStrip boolean hasNext() { if (mIterator.hasNext()) { Map.Entry entry = mIterator.next(); mKey = entry.getKey(); mValue = entry.getValue(); return true; } else { mKey = null; mValue = null; return false; } }
/** * Return a value created by YogaMeasureOutput.make(width, height); */ @DoNotStrip long measure( YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode);
@DoNotStrip public final long measure(float width, int widthMode, float height, int heightMode) { if (!isMeasureDefined()) { throw new RuntimeException("Measure function isn't defined!"); } return mMeasureFunction.measure( this, width, YogaMeasureMode.fromInt(widthMode), height, YogaMeasureMode.fromInt(heightMode)); }
/** * @return the MessageQueueThread that owns the current Thread. */ @DoNotStrip public static MessageQueueThread myMessageQueueThread() { return Assertions.assertNotNull( sMyMessageQueueThread.get(), "This thread doesn't have a MessageQueueThread registered to it!"); }
/** * Runs the given Runnable on this Thread. It will be submitted to the end of the event queue even * if it is being submitted from the same queue Thread. */ @DoNotStrip @Override public void runOnQueue(Runnable runnable) { if (mIsFinished) { FLog.w( ReactConstants.TAG, "Tried to enqueue runnable on already finished thread: '" + getName() + "... dropping Runnable."); } mHandler.post(runnable); }
/** * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an * {@link AssertionError}) if the assertion fails. */ @DoNotStrip @Override public void assertIsOnThread(String message) { SoftAssertions.assertCondition( isOnThread(), new StringBuilder().append(mAssertionErrorMessage).append(" ").append(message).toString()); }
/** * Quits this queue's Looper. If that Looper was running on a different Thread than the current * Thread, also waits for the last message being processed to finish and the Thread to die. */ @DoNotStrip @Override public void quitSynchronous() { mIsFinished = true; mLooper.quit(); if (mLooper.getThread() != Thread.currentThread()) { try { mLooper.getThread().join(); } catch (InterruptedException e) { throw new RuntimeException("Got interrupted waiting to join thread " + mName); } } }
@DoNotStrip private void findMethods() { Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "findMethods"); Set<String> methodNames = new HashSet<>(); Method[] targetMethods = mModuleClass.getDeclaredMethods(); for (Method targetMethod : targetMethods) { ReactMethod annotation = targetMethod.getAnnotation(ReactMethod.class); if (annotation != null) { String methodName = targetMethod.getName(); if (methodNames.contains(methodName)) { // We do not support method overloading since js sees a function as an object regardless // of number of params. throw new IllegalArgumentException( "Java Module " + getName() + " method name already registered: " + methodName); } MethodDescriptor md = new MethodDescriptor(); JavaMethodWrapper method = new JavaMethodWrapper(this, targetMethod, annotation.isBlockingSynchronousMethod()); md.name = methodName; md.type = method.getType(); if (md.type == BaseJavaModule.METHOD_TYPE_SYNC) { md.signature = method.getSignature(); md.method = targetMethod; } mMethods.add(method); mDescs.add(md); } } Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); }
@DoNotStrip public @Nullable NativeArray getConstants() { if (!mModuleHolder.getHasConstants()) { return null; } BaseJavaModule baseJavaModule = getModule(); ReactMarker.logMarker(GET_CONSTANTS_START, getName()); SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants") .arg("moduleName", getName()) .flush(); Map<String, Object> map = baseJavaModule.getConstants(); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants") .arg("moduleName", getName()) .flush(); ReactMarker.logMarker(CONVERT_CONSTANTS_START, getName()); WritableNativeMap writableNativeMap; try { writableNativeMap = Arguments.makeNativeMap(map); } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } WritableNativeArray array = new WritableNativeArray(); array.pushMap(writableNativeMap); ReactMarker.logMarker(CONVERT_CONSTANTS_END); ReactMarker.logMarker(GET_CONSTANTS_END); return array; }
@DoNotStrip public void invoke(ExecutorToken token, int methodId, ReadableNativeArray parameters) { if (mMethods == null || methodId >= mMethods.size()) { return; } mMethods.get(methodId).invoke(mJSInstance, token, parameters); }
/** * Return a value created by YogaMeasureOutput.make(width, height); */ @DoNotStrip long measure( YogaNodeAPI node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode);
@DoNotStrip public synchronized NativeModule getModule() { if (mModule == null) { mModule = create(); } return mModule; }
@DoNotStrip public CppSystemErrorException(String message, int errorCode) { super(message); this.errorCode = errorCode; }
@DoNotStrip public UnknownCppException() { super("Unknown"); }
@DoNotStrip public UnknownCppException(String message) { super(message); }
@DoNotStrip public CppException(String message) { super(message); }
@DoNotStrip public IteratorHelper(Iterator iterator) { mIterator = iterator; }
@DoNotStrip public IteratorHelper(Iterable iterable) { mIterator = iterable.iterator(); }
@DoNotStrip public boolean supportsWebWorkers() { return getModule().supportsWebWorkers(); }
@DoNotStrip public MapIteratorHelper(Map map) { mIterator = map.entrySet().iterator(); }
/** * @return whether the current Thread is also the Thread associated with this MessageQueueThread. */ @DoNotStrip @Override public boolean isOnThread() { return mLooper.getThread() == Thread.currentThread(); }
@DoNotStrip YogaValue(float value, int unit) { this(value, YogaUnit.fromInt(unit)); }
@DoNotStrip public final float baseline(float width, float height) { return mBaselineFunction.baseline(this, width, height); }
@DoNotStrip void setEnabled(boolean enabled);
@DoNotStrip void setGlobalVariable(String propertyName, String jsonEncodedValue);
@DoNotStrip public UnexpectedNativeTypeException(String msg) { super(msg); }
@DoNotStrip private ExecutorToken(HybridData hybridData) { mHybridData = hybridData; }
@Override @DoNotStrip void invokeCallback( ExecutorToken executorToken, int callbackID, NativeArray arguments);