/
ReactQueueConfigurationSpec.java
76 lines (62 loc) · 2.57 KB
/
ReactQueueConfigurationSpec.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge.queue;
import android.os.Build;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
/**
* Spec for creating a ReactQueueConfiguration. This exists so that CatalystInstance is able to set
* Exception handlers on the MessageQueueThreads it uses and it would not be super clean if the
* threads were configured, then passed to CatalystInstance where they are configured more. These
* specs allows the Threads to be created fully configured.
*/
public class ReactQueueConfigurationSpec {
private final MessageQueueThreadSpec mNativeModulesQueueThreadSpec;
private final MessageQueueThreadSpec mJSQueueThreadSpec;
private ReactQueueConfigurationSpec(
MessageQueueThreadSpec nativeModulesQueueThreadSpec,
MessageQueueThreadSpec jsQueueThreadSpec) {
mNativeModulesQueueThreadSpec = nativeModulesQueueThreadSpec;
mJSQueueThreadSpec = jsQueueThreadSpec;
}
public MessageQueueThreadSpec getNativeModulesQueueThreadSpec() {
return mNativeModulesQueueThreadSpec;
}
public MessageQueueThreadSpec getJSQueueThreadSpec() {
return mJSQueueThreadSpec;
}
public static Builder builder() {
return new Builder();
}
public static ReactQueueConfigurationSpec createDefault() {
MessageQueueThreadSpec spec = MessageQueueThreadSpec.newBackgroundThreadSpec("native_modules");
return builder()
.setJSQueueThreadSpec(MessageQueueThreadSpec.newBackgroundThreadSpec("js"))
.setNativeModulesQueueThreadSpec(spec)
.build();
}
public static class Builder {
private @Nullable MessageQueueThreadSpec mNativeModulesQueueSpec;
private @Nullable MessageQueueThreadSpec mJSQueueSpec;
public Builder setNativeModulesQueueThreadSpec(MessageQueueThreadSpec spec) {
Assertions.assertCondition(
mNativeModulesQueueSpec == null, "Setting native modules queue spec multiple times!");
mNativeModulesQueueSpec = spec;
return this;
}
public Builder setJSQueueThreadSpec(MessageQueueThreadSpec spec) {
Assertions.assertCondition(mJSQueueSpec == null, "Setting JS queue multiple times!");
mJSQueueSpec = spec;
return this;
}
public ReactQueueConfigurationSpec build() {
return new ReactQueueConfigurationSpec(
Assertions.assertNotNull(mNativeModulesQueueSpec),
Assertions.assertNotNull(mJSQueueSpec));
}
}
}