1919import org .lable .oss .uniqueid .GeneratorException ;
2020import org .lable .oss .uniqueid .GeneratorIdentityHolder ;
2121import org .lable .oss .uniqueid .bytes .Blueprint ;
22+ import org .slf4j .Logger ;
23+ import org .slf4j .LoggerFactory ;
2224
2325import java .io .IOException ;
2426import java .time .Duration ;
3436 * @see #basedOn(String, String, Supplier, Supplier)
3537 */
3638public class SynchronizedGeneratorIdentity implements GeneratorIdentityHolder {
39+ private static final Logger logger = LoggerFactory .getLogger (SynchronizedGeneratorIdentity .class );
40+
3741 final int clusterId ;
3842
3943 final Supplier <Duration > claimDurationSupplier ;
@@ -135,6 +139,10 @@ public void relinquishGeneratorIdClaim() {
135139 }
136140
137141 private ResourceClaim acquireResourceClaim () throws GeneratorException {
142+ return acquireResourceClaim (0 );
143+ }
144+
145+ private ResourceClaim acquireResourceClaim (int retries ) throws GeneratorException {
138146 try {
139147 return ExpiringResourceClaim .claimExpiring (
140148 zooKeeperConnection ,
@@ -144,7 +152,15 @@ private ResourceClaim acquireResourceClaim() throws GeneratorException {
144152 acquisitionTimeoutSupplier .get ()
145153 );
146154 } catch (IOException e ) {
147- throw new GeneratorException (e );
155+ logger .warn (
156+ "Connection to ZooKeeper quorum failed, retrying resource claim acquisition, attempt {}." ,
157+ retries + 1
158+ );
159+ if (retries < 3 ) {
160+ return acquireResourceClaim (retries + 1 );
161+ } else {
162+ throw new GeneratorException (e );
163+ }
148164 }
149165 }
150166
0 commit comments