2929import java .text .ParseException ;
3030import java .text .SimpleDateFormat ;
3131import java .util .*;
32- import java .util .concurrent .locks .ReadWriteLock ;
33- import java .util .concurrent .locks .ReentrantReadWriteLock ;
3432
3533
3634/**
3735 * The PsiCash library interface. It provides a wrapper around the C++ core.
3836 */
3937public class PsiCashLib {
40- ReadWriteLock lock = new ReentrantReadWriteLock ();
41-
4238 /**
4339 * The library user must implement this interface. It provides HTTP request
4440 * functionality to the library.
@@ -290,9 +286,7 @@ public PsiCashLib() {
290286 */
291287 @ Nullable
292288 public Error init (String fileStoreRoot , HTTPRequester httpRequester ) {
293- this .lock .writeLock ().lock ();
294289 Error res = init (fileStoreRoot , httpRequester , false );
295- this .lock .writeLock ().unlock ();
296290 return res ;
297291 }
298292
@@ -303,10 +297,8 @@ public Error init(String fileStoreRoot, HTTPRequester httpRequester) {
303297 */
304298 @ Nullable
305299 protected Error init (String fileStoreRoot , HTTPRequester httpRequester , boolean test ) {
306- this .lock .writeLock ().lock ();
307300 this .httpRequester = httpRequester ;
308301 String jsonStr = this .NativeObjectInit (fileStoreRoot , test );
309- this .lock .writeLock ().unlock ();
310302 JNI .Result .ErrorOnly res = new JNI .Result .ErrorOnly (jsonStr );
311303 return res .error ;
312304 }
@@ -318,9 +310,7 @@ protected Error init(String fileStoreRoot, HTTPRequester httpRequester, boolean
318310 */
319311 @ Nullable
320312 public Error setRequestMetadataItem (String key , String value ) {
321- this .lock .writeLock ().lock ();
322313 String jsonStr = this .NativeSetRequestMetadataItem (key , value );
323- this .lock .writeLock ().unlock ();
324314 JNI .Result .ErrorOnly res = new JNI .Result .ErrorOnly (jsonStr );
325315 return res .error ;
326316 }
@@ -335,9 +325,7 @@ public Error setRequestMetadataItem(String key, String value) {
335325 */
336326 @ NonNull
337327 public ValidTokenTypesResult validTokenTypes () {
338- this .lock .readLock ().lock ();
339328 String jsonStr = this .NativeValidTokenTypes ();
340- this .lock .readLock ().unlock ();
341329 JNI .Result .ValidTokenTypes res = new JNI .Result .ValidTokenTypes (jsonStr );
342330 return new ValidTokenTypesResult (res );
343331 }
@@ -364,9 +352,7 @@ public static class ValidTokenTypesResult {
364352 */
365353 @ NonNull
366354 public IsAccountResult isAccount () {
367- this .lock .readLock ().lock ();
368355 String jsonStr = this .NativeIsAccount ();
369- this .lock .readLock ().unlock ();
370356 JNI .Result .IsAccount res = new JNI .Result .IsAccount (jsonStr );
371357 return new IsAccountResult (res );
372358 }
@@ -390,9 +376,7 @@ public static class IsAccountResult {
390376 */
391377 @ NonNull
392378 public BalanceResult balance () {
393- this .lock .readLock ().lock ();
394379 String jsonStr = this .NativeBalance ();
395- this .lock .readLock ().unlock ();
396380 JNI .Result .Balance res = new JNI .Result .Balance (jsonStr );
397381 return new BalanceResult (res );
398382 }
@@ -417,9 +401,7 @@ public static class BalanceResult {
417401 */
418402 @ NonNull
419403 public GetPurchasePricesResult getPurchasePrices () {
420- this .lock .readLock ().lock ();
421404 String jsonStr = this .NativeGetPurchasePrices ();
422- this .lock .readLock ().unlock ();
423405 JNI .Result .GetPurchasePrices res = new JNI .Result .GetPurchasePrices (jsonStr );
424406 return new GetPurchasePricesResult (res );
425407 }
@@ -445,9 +427,7 @@ public static class GetPurchasePricesResult {
445427 */
446428 @ NonNull
447429 public GetPurchasesResult getPurchases () {
448- this .lock .readLock ().lock ();
449430 String jsonStr = this .NativeGetPurchases ();
450- this .lock .readLock ().unlock ();
451431 JNI .Result .GetPurchases res = new JNI .Result .GetPurchases (jsonStr );
452432 return new GetPurchasesResult (res );
453433 }
@@ -473,9 +453,7 @@ public static class GetPurchasesResult {
473453 */
474454 @ NonNull
475455 public ActivePurchasesResult activePurchases () {
476- this .lock .readLock ().lock ();
477456 String jsonStr = this .NativeActivePurchases ();
478- this .lock .readLock ().unlock ();
479457 JNI .Result .ActivePurchases res = new JNI .Result .ActivePurchases (jsonStr );
480458 return new ActivePurchasesResult (res );
481459 }
@@ -502,9 +480,7 @@ public static class ActivePurchasesResult {
502480 */
503481 @ NonNull
504482 public GetAuthorizationsResult getAuthorizations (boolean activeOnly ) {
505- this .lock .readLock ().lock ();
506483 String jsonStr = this .NativeGetAuthorizations (activeOnly );
507- this .lock .readLock ().unlock ();
508484 JNI .Result .GetAuthorizations res = new JNI .Result .GetAuthorizations (jsonStr );
509485 return new GetAuthorizationsResult (res );
510486 }
@@ -536,9 +512,7 @@ public GetPurchasesByAuthorizationIDResult getPurchasesByAuthorizationID(List<St
536512 if (authorizationIDs != null ) {
537513 idsArray = authorizationIDs .toArray (new String [0 ]);
538514 }
539- this .lock .readLock ().lock ();
540515 String jsonStr = this .NativeGetPurchasesByAuthorizationID (idsArray );
541- this .lock .readLock ().unlock ();
542516 JNI .Result .GetPurchasesByAuthorizationID res = new JNI .Result .GetPurchasesByAuthorizationID (jsonStr );
543517 return new GetPurchasesByAuthorizationIDResult (res );
544518
@@ -565,7 +539,6 @@ public static class GetPurchasesByAuthorizationIDResult {
565539 */
566540 @ NonNull
567541 public static DecodeAuthorizationResult decodeAuthorization (String encodedAuthorization ) {
568- // No lock, as no state is accessed or modified
569542 String jsonStr = NativeDecodeAuthorization (encodedAuthorization );
570543 JNI .Result .DecodeAuthorization res = new JNI .Result .DecodeAuthorization (jsonStr );
571544 return new DecodeAuthorizationResult (res );
@@ -593,9 +566,7 @@ public static class DecodeAuthorizationResult {
593566 */
594567 @ NonNull
595568 public NextExpiringPurchaseResult nextExpiringPurchase () {
596- this .lock .readLock ().lock ();
597569 String jsonStr = this .NativeNextExpiringPurchase ();
598- this .lock .readLock ().unlock ();
599570 JNI .Result .NextExpiringPurchase res = new JNI .Result .NextExpiringPurchase (jsonStr );
600571 return new NextExpiringPurchaseResult (res );
601572 }
@@ -621,9 +592,7 @@ public static class NextExpiringPurchaseResult {
621592 */
622593 @ NonNull
623594 public ExpirePurchasesResult expirePurchases () {
624- this .lock .writeLock ().lock ();
625595 String jsonStr = this .NativeExpirePurchases ();
626- this .lock .writeLock ().unlock ();
627596 JNI .Result .ExpirePurchases res = new JNI .Result .ExpirePurchases (jsonStr );
628597 return new ExpirePurchasesResult (res );
629598 }
@@ -658,9 +627,7 @@ public RemovePurchasesResult removePurchases(List<String> transactionIDs) {
658627 if (transactionIDs != null ) {
659628 idsArray = transactionIDs .toArray (new String [0 ]);
660629 }
661- this .lock .writeLock ().lock ();
662630 String jsonStr = this .NativeRemovePurchases (idsArray );
663- this .lock .writeLock ().unlock ();
664631 JNI .Result .RemovePurchases res = new JNI .Result .RemovePurchases (jsonStr );
665632 return new RemovePurchasesResult (res );
666633
@@ -690,9 +657,7 @@ public static class RemovePurchasesResult {
690657 */
691658 @ NonNull
692659 public ModifyLandingPageResult modifyLandingPage (String url ) {
693- this .lock .readLock ().lock ();
694660 String jsonStr = this .NativeModifyLandingPage (url );
695- this .lock .readLock ().unlock ();
696661 JNI .Result .ModifyLandingPage res = new JNI .Result .ModifyLandingPage (jsonStr );
697662 return new ModifyLandingPageResult (res );
698663 }
@@ -726,9 +691,7 @@ public static class ModifyLandingPageResult {
726691 */
727692 @ NonNull
728693 public GetRewardedActivityDataResult getRewardedActivityData () {
729- this .lock .readLock ().lock ();
730694 String jsonStr = this .NativeGetRewardedActivityData ();
731- this .lock .readLock ().unlock ();
732695 JNI .Result .GetRewardedActivityData res = new JNI .Result .GetRewardedActivityData (jsonStr );
733696 return new GetRewardedActivityDataResult (res );
734697 }
@@ -753,9 +716,7 @@ public static class GetRewardedActivityDataResult {
753716 */
754717 @ NonNull
755718 public GetDiagnosticInfoResult getDiagnosticInfo () {
756- this .lock .readLock ().lock ();
757719 String jsonStr = this .NativeGetDiagnosticInfo ();
758- this .lock .readLock ().unlock ();
759720 JNI .Result .GetDiagnosticInfo res = new JNI .Result .GetDiagnosticInfo (jsonStr );
760721 return new GetDiagnosticInfoResult (res );
761722 }
@@ -788,9 +749,7 @@ public RefreshStateResult refreshState(List<String> purchaseClasses) {
788749 if (purchaseClasses == null ) {
789750 purchaseClasses = new ArrayList <>();
790751 }
791- this .lock .writeLock ().lock ();
792752 String jsonStr = this .NativeRefreshState (purchaseClasses .toArray (new String [0 ]));
793- this .lock .writeLock ().unlock ();
794753 JNI .Result .RefreshState res = new JNI .Result .RefreshState (jsonStr );
795754 return new RefreshStateResult (res );
796755 }
@@ -824,9 +783,7 @@ public static class RefreshStateResult {
824783 @ NonNull
825784 public NewExpiringPurchaseResult newExpiringPurchase (
826785 String transactionClass , String distinguisher , long expectedPrice ) {
827- this .lock .writeLock ().lock ();
828786 String jsonStr = this .NativeNewExpiringPurchase (transactionClass , distinguisher , expectedPrice );
829- this .lock .writeLock ().unlock ();
830787 JNI .Result .NewExpiringPurchase res = new JNI .Result .NewExpiringPurchase (jsonStr );
831788 return new NewExpiringPurchaseResult (res );
832789 }
0 commit comments