@@ -23,11 +23,10 @@ public class Registry {
2323 private final Map <String , StateDef > workflowStateStore = new HashMap <>(); // TODO refactor to use Map<String, Map<String, StateDef>> to be more clear
2424
2525 private final Map <String , StateDef > workflowStartStateStore = new HashMap <>();
26- private final Map <String , Map <String , Class <?>>> signalTypeStore = new HashMap <>();
2726
28- private final Map <String , Map < String , Class <?>>> internalChannelTypeStore = new HashMap <>();
29- private final Map <String , Map < String , Class <?>>> dataAttributeKeyToTypeStore = new HashMap <>();
30- private final Map <String , Map < String , Class <?>>> dataAttributePrefixToTypeStore = new HashMap <>();
27+ private final Map <String , TypeStore > signalTypeStore = new HashMap <>();
28+ private final Map <String , TypeStore > internalChannelTypeStore = new HashMap <>();
29+ private final Map <String , TypeStore > dataAttributeTypeStore = new HashMap <>();
3130
3231 private final Map <String , Map <String , SearchAttributeValueType >> searchAttributeTypeStore = new HashMap <>();
3332
@@ -113,81 +112,53 @@ private void registerWorkflowRPCs(final ObjectWorkflow wf) {
113112 }
114113
115114 private void registerWorkflowSignal (final ObjectWorkflow wf ) {
116- String workflowType = getWorkflowType (wf );
115+ final String workflowType = getWorkflowType (wf );
117116 final List <SignalChannelDef > channels = getSignalChannels (wf );
117+
118+ final TypeStore typeStore = signalTypeStore .computeIfAbsent (workflowType ,
119+ s -> TypeStore .defaultBuilder (TypeStore .Type .SIGNAL_CHANNEL ));
120+
118121 if (channels == null || channels .isEmpty ()) {
119- signalTypeStore .put (workflowType , new HashMap <>());
120122 return ;
121123 }
122124
123- for (SignalChannelDef signalChannelDef : channels ) {
124- Map <String , Class <?>> signalNameToTypeMap =
125- signalTypeStore .computeIfAbsent (workflowType , s -> new HashMap <>());
126- if (signalNameToTypeMap .containsKey (signalChannelDef .getSignalChannelName ())) {
127- throw new WorkflowDefinitionException (
128- String .format ("Signal channel name %s already exists" , signalChannelDef .getSignalChannelName ()));
129- }
130- signalNameToTypeMap .put (signalChannelDef .getSignalChannelName (), signalChannelDef .getSignalValueType ());
125+ for (final SignalChannelDef signalChannelDef : channels ) {
126+ typeStore .addToStore (signalChannelDef );
131127 }
132128 }
133129
134130 private void registerWorkflowInternalChannel (final ObjectWorkflow wf ) {
135- String workflowType = getWorkflowType (wf );
131+ final String workflowType = getWorkflowType (wf );
136132 final List <InternalChannelDef > channels = getInternalChannels (wf );
133+
134+ final TypeStore typeStore = internalChannelTypeStore .computeIfAbsent (workflowType ,
135+ s -> TypeStore .defaultBuilder (TypeStore .Type .INTERNAL_CHANNEL ));
136+
137137 if (channels == null || channels .isEmpty ()) {
138- internalChannelTypeStore .put (workflowType , new HashMap <>());
139138 return ;
140139 }
141140
142- for (InternalChannelDef internalChannelDef : channels ) {
143- Map <String , Class <?>> nameToTypeMap =
144- internalChannelTypeStore .computeIfAbsent (workflowType , s -> new HashMap <>());
145- if (nameToTypeMap .containsKey (internalChannelDef .getChannelName ())) {
146- throw new WorkflowDefinitionException (
147- String .format ("InternalChannel name %s already exists" , internalChannelDef .getChannelName ()));
148- }
149- nameToTypeMap .put (internalChannelDef .getChannelName (), internalChannelDef .getValueType ());
141+ for (final InternalChannelDef internalChannelDef : channels ) {
142+ typeStore .addToStore (internalChannelDef );
150143 }
151144 }
152145
153146 private void registerWorkflowDataAttributes (final ObjectWorkflow wf ) {
154147 final String workflowType = getWorkflowType (wf );
155148 final List <DataAttributeDef > fields = getDataAttributeFields (wf );
156149
157- dataAttributeKeyToTypeStore . put (workflowType , new HashMap <>());
158- dataAttributePrefixToTypeStore . put ( workflowType , new HashMap <>( ));
150+ final TypeStore typeStore = dataAttributeTypeStore . computeIfAbsent (workflowType ,
151+ s -> TypeStore . defaultBuilder ( TypeStore . Type . DATA_ATTRIBUTE ));
159152
160153 if (fields == null || fields .isEmpty ()) {
161154 return ;
162155 }
163156
164157 for (final DataAttributeDef dataAttributeField : fields ) {
165- if (dataAttributeField .isPrefix ()) {
166- addDataAttributeToStore (dataAttributeField , workflowType , dataAttributePrefixToTypeStore );
167- } else {
168- addDataAttributeToStore (dataAttributeField , workflowType , dataAttributeKeyToTypeStore );
169- }
158+ typeStore .addToStore (dataAttributeField );
170159 }
171160 }
172161
173- private void addDataAttributeToStore (
174- final DataAttributeDef dataAttributeField ,
175- final String workflowType ,
176- final Map <String , Map <String , Class <?>>> dataAttributeStore ) {
177- final Map <String , Class <?>> dataAttributeMap =
178- dataAttributeStore .computeIfAbsent (workflowType , s -> new HashMap <>());
179- if (dataAttributeMap .containsKey (dataAttributeField .getKey ())) {
180- throw new WorkflowDefinitionException (
181- String .format (
182- "data attribute key/prefix %s already exists" ,
183- dataAttributeField .getDataAttributeType ())
184- );
185- }
186- dataAttributeMap .put (
187- dataAttributeField .getKey (),
188- dataAttributeField .getDataAttributeType ()
189- );
190- }
191162
192163 private void registerPersistenceOptions (final ObjectWorkflow wf ) {
193164 String workflowType = getWorkflowType (wf );
@@ -270,20 +241,16 @@ public Optional<StateDef> getWorkflowStartingState(final String workflowType) {
270241 return Optional .ofNullable (state );
271242 }
272243
273- public Map < String , Class <?>> getSignalChannelNameToSignalTypeMap (final String workflowType ) {
244+ public TypeStore getSignalChannelTypeStore (final String workflowType ) {
274245 return signalTypeStore .get (workflowType );
275246 }
276247
277- public Map < String , Class <?>> getInternalChannelNameToTypeMap (final String workflowType ) {
248+ public TypeStore getInternalChannelTypeStore (final String workflowType ) {
278249 return internalChannelTypeStore .get (workflowType );
279250 }
280251
281- public Map <String , Class <?>> getDataAttributeKeyToTypeMap (final String workflowType ) {
282- return dataAttributeKeyToTypeStore .get (workflowType );
283- }
284-
285- public Map <String , Class <?>> getDataAttributePrefixToTypeMap (final String workflowType ) {
286- return dataAttributePrefixToTypeStore .get (workflowType );
252+ public TypeStore getDataAttributeTypeStore (final String workflowType ) {
253+ return dataAttributeTypeStore .get (workflowType );
287254 }
288255
289256 public Map <String , SearchAttributeValueType > getSearchAttributeKeyToTypeMap (final String workflowType ) {
0 commit comments