Change class names to modules names in packages

Reviewed By: achen1

Differential Revision: D9508095

fbshipit-source-id: e3973ea417c803110eb8612c854a6374a849474b
This commit is contained in:
Ram N
2018-09-05 18:14:59 -07:00
committed by Facebook Github Bot
parent 5eaa2d29c0
commit 48169b28e2
12 changed files with 110 additions and 276 deletions

View File

@@ -24,11 +24,12 @@ import javax.inject.Provider;
/**
* Holder to enable us to lazy create native modules.
*
* This works by taking a provider instead of an instance, when it is first required we'll create
* <p>This works by taking a provider instead of an instance, when it is first required we'll create
* and initialize it. Initialization currently always happens on the UI thread but this is due to
* change for performance reasons.
*
* Lifecycle events via a {@link LifecycleEventListener} will still always happen on the UI thread.
* <p>Lifecycle events via a {@link LifecycleEventListener} will still always happen on the UI
* thread.
*/
@DoNotStrip
public class ModuleHolder {
@@ -38,9 +39,7 @@ public class ModuleHolder {
private final int mInstanceKey = sInstanceKeyCounter.getAndIncrement();
private final String mName;
private final boolean mCanOverrideExistingModule;
private final boolean mHasConstants;
private final boolean mIsCxxModule;
private final ReactModuleInfo mReactModuleInfo;
private @Nullable Provider<? extends NativeModule> mProvider;
// Outside of the constructur, these should only be checked or set when synchronized on this
@@ -53,10 +52,8 @@ public class ModuleHolder {
public ModuleHolder(ReactModuleInfo moduleInfo, Provider<? extends NativeModule> provider) {
mName = moduleInfo.name();
mCanOverrideExistingModule = moduleInfo.canOverrideExistingModule();
mHasConstants = moduleInfo.hasConstants();
mProvider = provider;
mIsCxxModule = moduleInfo.isCxxModule();
mReactModuleInfo = moduleInfo;
if (moduleInfo.needsEagerInit()) {
mModule = create();
}
@@ -64,19 +61,25 @@ public class ModuleHolder {
public ModuleHolder(NativeModule nativeModule) {
mName = nativeModule.getName();
mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
mHasConstants = true;
mIsCxxModule = CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass());
mReactModuleInfo =
new ReactModuleInfo(
nativeModule.getName(),
nativeModule.getClass().getSimpleName(),
nativeModule.canOverrideExistingModule(),
true,
true,
CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass()));
mModule = nativeModule;
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
}
/*
* Checks if mModule has been created, and if so tries to initialize the module unless another
* thread is already doing the initialization.
* If mModule has not been created, records that initialization is needed
*/
* Checks if mModule has been created, and if so tries to initialize the module unless another
* thread is already doing the initialization.
* If mModule has not been created, records that initialization is needed
*/
/* package */ void markInitializable() {
boolean shouldInitializeNow = false;
NativeModule module = null;
@@ -109,14 +112,20 @@ public class ModuleHolder {
}
public boolean getCanOverrideExistingModule() {
return mCanOverrideExistingModule;
return mReactModuleInfo.canOverrideExistingModule();
}
public boolean getHasConstants() {
return mHasConstants;
return mReactModuleInfo.hasConstants();
}
public boolean isCxxModule() {return mIsCxxModule; }
public boolean isCxxModule() {
return mReactModuleInfo.isCxxModule();
}
public String getClassName() {
return mReactModuleInfo.className();
}
@DoNotStrip
public NativeModule getModule() {
@@ -125,11 +134,12 @@ public class ModuleHolder {
synchronized (this) {
if (mModule != null) {
return mModule;
// if mModule has not been set, and no one is creating it. Then this thread should call create
// if mModule has not been set, and no one is creating it. Then this thread should call
// create
} else if (!mIsCreating) {
shouldCreate = true;
mIsCreating = true;
} else {
} else {
// Wait for mModule to be created by another thread
}
}
@@ -163,8 +173,8 @@ public class ModuleHolder {
SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
ReactMarker.logMarker(CREATE_MODULE_START, mName, mInstanceKey);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.createModule")
.arg("name", mName)
.flush();
.arg("name", mName)
.flush();
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
NativeModule module;
@@ -172,7 +182,7 @@ public class ModuleHolder {
module = assertNotNull(mProvider).get();
mProvider = null;
boolean shouldInitializeNow = false;
synchronized(this) {
synchronized (this) {
mModule = module;
if (mInitializable && !mIsInitializing) {
shouldInitializeNow = true;
@@ -190,8 +200,8 @@ public class ModuleHolder {
private void doInitialize(NativeModule module) {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.initialize")
.arg("name", mName)
.flush();
.arg("name", mName)
.flush();
ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName, mInstanceKey);
try {
boolean shouldInitialize = false;
@@ -204,7 +214,8 @@ public class ModuleHolder {
}
if (shouldInitialize) {
module.initialize();
// Once finished, set flags accordingly, but we don't expect anyone to wait for this to finish
// Once finished, set flags accordingly, but we don't expect anyone to wait for this to
// finish
// So no need to notify other threads
synchronized (this) {
mIsInitializing = false;