This is the old documentation of lombok-pg. The new version can be found in the wiki of the github repository. Take me to the new Version then!

@Signal/@Await/@SignalBeforeAwaitAfter

Overview

Detailed Description

With Lombok

01 import lombok.AccessLevel;
02 import lombok.Await;
03 import lombok.Getter;
04 import lombok.Signal;
05 
06 class ConditionExample {
07   @Getter(AccessLevel.PRIVATE)
08   private volatile boolean paused;
09   
10   @Signal("canResume")
11   void unpause() {
12     paused = false;
13   }
14   
15   @Await(conditionName = "canResume", conditionMethod="isPaused")
16   void pause() {
17   }
18 }

Vanilla Java

01 class ConditionExample {
02   private volatile boolean paused;
03   private final java.util.concurrent.locks.Lock $canResumeLock = new java.util.concurrent.locks.ReentrantLock();
04   private final java.util.concurrent.locks.Condition canResume = $canResumeLock.newCondition();
05 
06   void unpause() {
07     this.$canResumeLock.lock();
08     try {
09       paused = false;
10       this.canResume.signal();
11     finally {
12       this.$canResumeLock.unlock();
13     }
14   }
15 
16   void pause() {
17     this.$canResumeLock.lock();
18     try {
19       try {
20         while (this.isPaused()) {
21           this.canResume.await();
22         }
23       catch (final java.lang.InterruptedException e) {
24         throw new RuntimeException(e);
25       }
26     finally {
27       this.$canResumeLock.unlock();
28     }
29   }
30 
31   private boolean isPaused() {
32     return this.paused;
33   }
34 }

Small print

Smallprint