@@ -203,7 +203,7 @@ private byte[] readAssemblyScriptUint8Array(int address)
203203 return bufferData ;
204204 }
205205
206- public void storeConfig (String sdkKey , String config ) {
206+ public synchronized void storeConfig (String sdkKey , String config ) {
207207 unpinAll ();
208208 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
209209 int configAddress = newUint8ArrayParameter (config .getBytes (StandardCharsets .UTF_8 ));
@@ -213,15 +213,15 @@ public void storeConfig(String sdkKey, String config) {
213213 fn .accept (sdkKeyAddress , configAddress );
214214 }
215215
216- public void setPlatformData (String platformData ) {
216+ public synchronized void setPlatformData (String platformData ) {
217217 unpinAll ();
218218 int platformDataAddress = newUint8ArrayParameter (platformData .getBytes (StandardCharsets .UTF_8 ));
219219 Func setPlatformDataPtr = linker .get (store , "" , "setPlatformDataUTF8" ).get ().func ();
220220 WasmFunctions .Consumer1 <Integer > fn = WasmFunctions .consumer (store , setPlatformDataPtr , I32 );
221221 fn .accept (platformDataAddress );
222222 }
223223
224- public void setClientCustomData (String sdkKey , String customData ) {
224+ public synchronized void setClientCustomData (String sdkKey , String customData ) {
225225 unpinAll ();
226226 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
227227 int customDataAddress = newUint8ArrayParameter (customData .getBytes (StandardCharsets .UTF_8 ));;
@@ -230,7 +230,7 @@ public void setClientCustomData(String sdkKey, String customData) {
230230 fn .accept (sdkKeyAddress , customDataAddress );
231231 }
232232
233- public BucketedUserConfig generateBucketedConfig (String sdkKey , User user ) throws JsonProcessingException {
233+ public synchronized BucketedUserConfig generateBucketedConfig (String sdkKey , User user ) throws JsonProcessingException {
234234 unpinAll ();
235235 String userString = OBJECT_MAPPER .writeValueAsString (user );
236236
@@ -249,30 +249,7 @@ public BucketedUserConfig generateBucketedConfig(String sdkKey, User user) throw
249249 return config ;
250250 }
251251
252- public String getVariable (String sdkKey , User user , String key , Variable .TypeEnum variableTypeEnum , boolean shouldTrackEvent ) throws JsonProcessingException {
253- // need some kind of mutex?
254- String userString = OBJECT_MAPPER .writeValueAsString (user );
255-
256- int wasmVariableType = this .variableTypeMap .get (variableTypeEnum );
257-
258- unpinAll ();
259- int sdkKeyAddress = getSDKKeyAddress (sdkKey );
260- int userAddress = newWasmString (userString );
261- int keyAddress = newWasmString (key );
262-
263- Func getVariablePtr = linker .get (store , "" , "variableForUser" ).get ().func ();
264- WasmFunctions .Function5 <Integer , Integer , Integer , Integer , Integer , Integer > variableForUser = WasmFunctions .func (
265- store , getVariablePtr , I32 , I32 , I32 , I32 , I32 , I32 );
266-
267- int resultAddress = variableForUser .call (sdkKeyAddress , userAddress , keyAddress , wasmVariableType , shouldTrackEvent ? 1 : 0 );
268- if (resultAddress == 0 ){
269- return null ;
270- }
271- String variableString = readWasmString (resultAddress );
272- return variableString ;
273- }
274-
275- public byte [] getVariableForUserProtobuf (byte [] serializedParams ){
252+ public synchronized byte [] getVariableForUserProtobuf (byte [] serializedParams ){
276253 int paramsAddr = newUint8ArrayParameter (serializedParams );
277254
278255 Func getVariablePtr = linker .get (store , "" , "variableForUser_PB" ).get ().func ();
@@ -290,7 +267,7 @@ public byte[] getVariableForUserProtobuf(byte[] serializedParams){
290267 return varBytes ;
291268 }
292269
293- public void initEventQueue (String sdkKey , String options ) {
270+ public synchronized void initEventQueue (String sdkKey , String options ) {
294271 unpinAll ();
295272 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
296273 int optionsAddress = newWasmString (options );
@@ -300,7 +277,7 @@ public void initEventQueue(String sdkKey, String options) {
300277 fn .accept (sdkKeyAddress , optionsAddress );
301278 }
302279
303- public void queueEvent (String sdkKey , String user , String event ) {
280+ public synchronized void queueEvent (String sdkKey , String user , String event ) {
304281 unpinAll ();
305282 int sdkKeyAddress = newWasmString (sdkKey );
306283 int userAddress = getPinnedParameter (user );
@@ -311,7 +288,7 @@ public void queueEvent(String sdkKey, String user, String event) {
311288 fn .accept (sdkKeyAddress , userAddress , eventAddress );
312289 }
313290
314- public void queueAggregateEvent (String sdkKey , String event , String variableVariationMap ) {
291+ public synchronized void queueAggregateEvent (String sdkKey , String event , String variableVariationMap ) {
315292 unpinAll ();
316293 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
317294 int eventAddress = getPinnedParameter (event );
@@ -322,7 +299,7 @@ public void queueAggregateEvent(String sdkKey, String event, String variableVari
322299 fn .accept (sdkKeyAddress , eventAddress , variableVariationMapAddress );
323300 }
324301
325- public FlushPayload [] flushEventQueue (String sdkKey ) throws JsonProcessingException {
302+ public synchronized FlushPayload [] flushEventQueue (String sdkKey ) throws JsonProcessingException {
326303 unpinAll ();
327304 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
328305
@@ -345,7 +322,7 @@ public FlushPayload[] flushEventQueue(String sdkKey) throws JsonProcessingExcept
345322 return payloads ;
346323 }
347324
348- public void onPayloadFailure (String sdkKey , String payloadId , boolean retryable ) {
325+ public synchronized void onPayloadFailure (String sdkKey , String payloadId , boolean retryable ) {
349326 unpinAll ();
350327 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
351328 int payloadIdAddress = newWasmString (payloadId );
@@ -355,7 +332,7 @@ public void onPayloadFailure(String sdkKey, String payloadId, boolean retryable)
355332 fn .accept (sdkKeyAddress , payloadIdAddress , retryable ? 1 : 0 );
356333 }
357334
358- public void onPayloadSuccess (String sdkKey , String payloadId ) {
335+ public synchronized void onPayloadSuccess (String sdkKey , String payloadId ) {
359336 unpinAll ();
360337 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
361338 int payloadIdAddress = newWasmString (payloadId );
@@ -365,7 +342,7 @@ public void onPayloadSuccess(String sdkKey, String payloadId) {
365342 fn .accept (sdkKeyAddress , payloadIdAddress );
366343 }
367344
368- public int getEventQueueSize (String sdkKey ) {
345+ public synchronized int getEventQueueSize (String sdkKey ) {
369346 unpinAll ();
370347 int sdkKeyAddress = getSDKKeyAddress (sdkKey );
371348
0 commit comments