Skip to content

Commit

Permalink
fix for static translation specs cause a threading issue (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffz authored Jan 22, 2024
1 parent 60f42a6 commit 745eeb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<!-- Properties -->
<properties>
<!-- Version -->
<revision>3.1.1</revision>
<revision>3.1.2</revision>

<!-- basic project properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
* specs needed for converting to/from the Protobuf {@link Any} type.
*/
class PrimitiveTranslationSpecs {
private PrimitiveTranslationSpecs() {
PrimitiveTranslationSpecs() {
}

private final static BooleanTranslationSpec BOOLEAN_TRANSLATOR_SPEC = new BooleanTranslationSpec();
private final static IntegerTranslationSpec INT32_TRANSLATOR_SPEC = new IntegerTranslationSpec();
private final static UIntegerTranslationSpec UINT32_TRANSLATOR_SPEC = new UIntegerTranslationSpec();
private final static LongTranslationSpec INT64_TRANSLATOR_SPEC = new LongTranslationSpec();
private final static ULongTranslationSpec UINT64_TRANSLATOR_SPEC = new ULongTranslationSpec();
private final static StringTranslationSpec STRING_TRANSLATOR_SPEC = new StringTranslationSpec();
private final static FloatTranslationSpec FLOAT_TRANSLATOR_SPEC = new FloatTranslationSpec();
private final static DoubleTranslationSpec DOUBLE_TRANSLATOR_SPEC = new DoubleTranslationSpec();
private final static DateTranslationSpec DATE_TRANSLATOR_SPEC = new DateTranslationSpec();
private final static EnumTranslationSpec ENUM_TRANSLATOR_SPEC = new EnumTranslationSpec();
private final static AnyTranslationSpec ANY_TRANSLATOR_SPEC = new AnyTranslationSpec();
final BooleanTranslationSpec BOOLEAN_TRANSLATOR_SPEC = new BooleanTranslationSpec();
final IntegerTranslationSpec INT32_TRANSLATOR_SPEC = new IntegerTranslationSpec();
final UIntegerTranslationSpec UINT32_TRANSLATOR_SPEC = new UIntegerTranslationSpec();
final LongTranslationSpec INT64_TRANSLATOR_SPEC = new LongTranslationSpec();
final ULongTranslationSpec UINT64_TRANSLATOR_SPEC = new ULongTranslationSpec();
final StringTranslationSpec STRING_TRANSLATOR_SPEC = new StringTranslationSpec();
final FloatTranslationSpec FLOAT_TRANSLATOR_SPEC = new FloatTranslationSpec();
final DoubleTranslationSpec DOUBLE_TRANSLATOR_SPEC = new DoubleTranslationSpec();
final DateTranslationSpec DATE_TRANSLATOR_SPEC = new DateTranslationSpec();
final EnumTranslationSpec ENUM_TRANSLATOR_SPEC = new EnumTranslationSpec();
final AnyTranslationSpec ANY_TRANSLATOR_SPEC = new AnyTranslationSpec();

/**
* Returns a set of Protobuf Message {@link Descriptor}s for each of the
Expand All @@ -58,7 +58,7 @@ private PrimitiveTranslationSpecs() {
* and their Descriptors are exclusively used to falicitate converting to/from a
* Protobuf {@link Any} type
*/
static Set<Descriptor> getPrimitiveDescriptors() {
Set<Descriptor> getPrimitiveDescriptors() {
Set<Descriptor> set = new LinkedHashSet<>();

set.add(BoolValue.getDefaultInstance().getDescriptorForType());
Expand All @@ -82,7 +82,7 @@ static Set<Descriptor> getPrimitiveDescriptors() {
* are exclusively used to falicitate converting to/from a Protobuf {@link Any}
* type
*/
static Set<ProtobufTranslationSpec<?, ?>> getPrimitiveTranslatorSpecs() {
Set<ProtobufTranslationSpec<?, ?>> getPrimitiveTranslatorSpecs() {
Set<ProtobufTranslationSpec<?, ?>> set = new LinkedHashSet<>();

set.addAll(getPrimitiveInputTranslatorSpecMap().values());
Expand All @@ -98,7 +98,7 @@ static Set<Descriptor> getPrimitiveDescriptors() {
* and their typeUrls are exclusively used to falicitate converting to/from a
* Protobuf {@link Any} type
*/
static Map<String, Class<?>> getPrimitiveTypeUrlToClassMap() {
Map<String, Class<?>> getPrimitiveTypeUrlToClassMap() {
Map<String, Class<?>> map = new LinkedHashMap<>();

map.put(BoolValue.getDefaultInstance().getDescriptorForType().getFullName(),
Expand Down Expand Up @@ -133,7 +133,7 @@ static Map<String, Class<?>> getPrimitiveTypeUrlToClassMap() {
* and their inputObjectClasses are exclusively used to falicitate converting
* to/from a Protobuf {@link Any} type
*/
static Map<Class<?>, ProtobufTranslationSpec<?, ?>> getPrimitiveInputTranslatorSpecMap() {
Map<Class<?>, ProtobufTranslationSpec<?, ?>> getPrimitiveInputTranslatorSpecMap() {
Map<Class<?>, ProtobufTranslationSpec<?, ?>> map = new LinkedHashMap<>();

map.put(BOOLEAN_TRANSLATOR_SPEC.getInputObjectClass(), BOOLEAN_TRANSLATOR_SPEC);
Expand All @@ -159,7 +159,7 @@ static Map<String, Class<?>> getPrimitiveTypeUrlToClassMap() {
* and their appObjectClasses are exclusively used to falicitate converting
* to/from a Protobuf {@link Any} type
*/
static Map<Class<?>, ProtobufTranslationSpec<?, ?>> getPrimitiveObjectTranslatorSpecMap() {
Map<Class<?>, ProtobufTranslationSpec<?, ?>> getPrimitiveObjectTranslatorSpecMap() {
Map<Class<?>, ProtobufTranslationSpec<?, ?>> map = new LinkedHashMap<>();

// no java version of unsigned int nor unsigned long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ private Data() {
* Message is of type BoolValue, and so there is a translationSpec to convert
* from a BoolValue to a boolean and vice versa
*/
this.typeUrlToClassMap.putAll(PrimitiveTranslationSpecs.getPrimitiveTypeUrlToClassMap());
this.classToTranslationSpecMap.putAll(PrimitiveTranslationSpecs.getPrimitiveInputTranslatorSpecMap());
this.classToTranslationSpecMap.putAll(PrimitiveTranslationSpecs.getPrimitiveObjectTranslatorSpecMap());
this.translationSpecs.addAll(PrimitiveTranslationSpecs.getPrimitiveTranslatorSpecs());
PrimitiveTranslationSpecs primitiveTranslationSpecs = new PrimitiveTranslationSpecs();
this.typeUrlToClassMap.putAll(primitiveTranslationSpecs.getPrimitiveTypeUrlToClassMap());
this.classToTranslationSpecMap.putAll(primitiveTranslationSpecs.getPrimitiveInputTranslatorSpecMap());
this.classToTranslationSpecMap.putAll(primitiveTranslationSpecs.getPrimitiveObjectTranslatorSpecMap());
this.translationSpecs.addAll(primitiveTranslationSpecs.getPrimitiveTranslatorSpecs());
this.translationEngineType = TranslationEngineType.PROTOBUF;
}
}
Expand All @@ -95,7 +96,7 @@ public ProtobufTranslationEngine build() {
initTranslators();

TypeRegistry.Builder typeRegistryBuilder = TypeRegistry.newBuilder();
this.descriptorSet.addAll(PrimitiveTranslationSpecs.getPrimitiveDescriptors());
this.descriptorSet.addAll(new PrimitiveTranslationSpecs().getPrimitiveDescriptors());

this.descriptorSet.forEach((descriptor) -> {
typeRegistryBuilder.add(descriptor);
Expand Down

0 comments on commit 745eeb5

Please sign in to comment.