From e2605aa588bd9e9aeb5df340e01da4eeb9f81da8 Mon Sep 17 00:00:00 2001 From: DevOps Date: Wed, 10 Jan 2024 02:26:34 +0000 Subject: [PATCH] Copy from IronPolyglot 2024-01-10 --- .../ironpdf/internal/staticapi/Access.java | 66 +++++++++++++++---- .../internal/staticapi/Setting_Api.java | 2 +- .../ironpdf-engine-linux-x64/pom.xml | 2 +- .../ironpdf-engine-macos-arm64/pom.xml | 2 +- .../ironpdf-engine-macos-x64/pom.xml | 2 +- .../ironpdf-engine-windows-x64/pom.xml | 2 +- .../ironpdf-engine-windows-x86/pom.xml | 2 +- 7 files changed, 59 insertions(+), 19 deletions(-) diff --git a/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Access.java b/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Access.java index ce020a9..77db747 100644 --- a/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Access.java +++ b/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Access.java @@ -1,5 +1,6 @@ package com.ironsoftware.ironpdf.internal.staticapi; +import com.ironsoftware.ironpdf.exception.IronPdfDeploymentException; import com.ironsoftware.ironpdf.internal.proto.HandshakeRequestP; import com.ironsoftware.ironpdf.internal.proto.HandshakeResponseP; import com.ironsoftware.ironpdf.internal.proto.IronPdfServiceGrpc; @@ -35,6 +36,52 @@ final class Access { private static BufferedReader stdInput; private static BufferedReader stdError; private static CountDownLatch serverReady; + private static final int MAX_RETRY_ATTEMPTS = 20; + + private static ManagedChannel createChannel(){ + int attempts = 0; + Exception lastException = new Exception("unknown reason"); + while (attempts < MAX_RETRY_ATTEMPTS) { + try { + return ManagedChannelBuilder.forAddress(Setting_Api.subProcessHost, + Setting_Api.subProcessPort).usePlaintext().build(); + } catch (Exception e) { + lastException = e; + attempts++; + logger.info("Connect to IronPdfEngine failed. (Retry "+attempts+"/"+MAX_RETRY_ATTEMPTS+")"); + try { + TimeUnit.SECONDS.sleep(2); // Wait for 2 seconds before retrying + } catch (InterruptedException ignored) { + } + } + } + throw new RuntimeException(String.format("Cannot connected to IronPdfEngine: %s:%d", subProcessHost, subProcessPort), lastException); + } + + private static HandshakeResponseP handshakeWithRetry(RpcClient newClient){ + HandshakeRequestP.Builder handshakeRequest = HandshakeRequestP.newBuilder(); + handshakeRequest.setExpectedVersion(Setting_Api.IRON_PDF_ENGINE_VERSION); + handshakeRequest.setProgLang("java"); + + HandshakeResponseP handshakeResult = null; + int attempts = 0; + Exception lastException = new Exception("unknown reason"); + while (attempts < MAX_RETRY_ATTEMPTS) { + try{ + return newClient.blockingStub.handshake( + handshakeRequest.build()); + }catch (Exception exception){ + lastException=exception; + attempts++; + logger.info("Waiting for IronPdfEngine is ready. (Retry "+attempts+"/"+MAX_RETRY_ATTEMPTS+")"); + try { + TimeUnit.SECONDS.sleep(4); // Wait for 4 seconds before retrying + } catch (InterruptedException ignored1) { + } + } + } + throw new RuntimeException(String.format("Cannot handshake with IronPdfEngine: %s:%d due to:", subProcessHost, subProcessPort), lastException); + } static synchronized RpcClient ensureConnection() { if (client != null) { @@ -46,8 +93,7 @@ static synchronized RpcClient ensureConnection() { } if (channel == null) { - channel = ManagedChannelBuilder.forAddress(Setting_Api.subProcessHost, - Setting_Api.subProcessPort).usePlaintext().build(); + channel = createChannel(); } RpcClient newClient = new RpcClient( @@ -57,23 +103,17 @@ static synchronized RpcClient ensureConnection() { logger.debug("Handshaking, Expected IronPdfEngine Version : " + Setting_Api.IRON_PDF_ENGINE_VERSION); - HandshakeRequestP.Builder handshakeRequest = HandshakeRequestP.newBuilder(); - handshakeRequest.setExpectedVersion(Setting_Api.IRON_PDF_ENGINE_VERSION); - handshakeRequest.setProgLang("java"); - - HandshakeResponseP res_firstTry = newClient.blockingStub.handshake( - handshakeRequest.build()); + HandshakeResponseP handshakeResult = handshakeWithRetry(newClient); - logger.debug("Handshake result:" + res_firstTry); + logger.debug("Handshake result:" + handshakeResult); - switch (res_firstTry.getResultOrExceptionCase()) { + switch (handshakeResult.getResultOrExceptionCase()) { case SUCCESS: client = newClient; setLicenseKey(); return client; case REQUIREDVERSION: - logger.error("Mismatch IronPdfEngine version expected: " - + Setting_Api.IRON_PDF_ENGINE_VERSION + " but found:" + res_firstTry); + logger.error(String.format("Mismatch IronPdfEngine version expected: %s but found: %s", Setting_Api.IRON_PDF_ENGINE_VERSION, handshakeResult.getRequiredVersion())); // //todo download new Binary if (!isIronPdfEngineDocker && tryAgain) { tryAgain = false; @@ -87,7 +127,7 @@ static synchronized RpcClient ensureConnection() { return client; case EXCEPTION: - throw Exception_Converter.fromProto(res_firstTry.getException()); + throw Exception_Converter.fromProto(handshakeResult.getException()); default: throw new RuntimeException("Unexpected result from handshake"); } diff --git a/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Setting_Api.java b/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Setting_Api.java index d47d57b..caa32eb 100644 --- a/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Setting_Api.java +++ b/IronPdf/src/main/java/com/ironsoftware/ironpdf/internal/staticapi/Setting_Api.java @@ -144,7 +144,7 @@ public static void useIronPdfEngineDocker(int port){ /** * The constant IRON_PDF_ENGINE_VERSION. */ - public static final String IRON_PDF_ENGINE_VERSION = "2023.12.6"; + public static final String IRON_PDF_ENGINE_VERSION = "2024.1.20"; public static boolean singleProcess = false; diff --git a/ironpdf-engine-pack/ironpdf-engine-linux-x64/pom.xml b/ironpdf-engine-pack/ironpdf-engine-linux-x64/pom.xml index 216a56a..1a6d0bb 100644 --- a/ironpdf-engine-pack/ironpdf-engine-linux-x64/pom.xml +++ b/ironpdf-engine-pack/ironpdf-engine-linux-x64/pom.xml @@ -108,7 +108,7 @@ 8 8 UTF-8 - 2023.12.6 + 2024.1.20 diff --git a/ironpdf-engine-pack/ironpdf-engine-macos-arm64/pom.xml b/ironpdf-engine-pack/ironpdf-engine-macos-arm64/pom.xml index b948d86..a0d9675 100644 --- a/ironpdf-engine-pack/ironpdf-engine-macos-arm64/pom.xml +++ b/ironpdf-engine-pack/ironpdf-engine-macos-arm64/pom.xml @@ -108,7 +108,7 @@ 8 8 UTF-8 - 2023.12.6 + 2024.1.20 diff --git a/ironpdf-engine-pack/ironpdf-engine-macos-x64/pom.xml b/ironpdf-engine-pack/ironpdf-engine-macos-x64/pom.xml index e900136..a687944 100644 --- a/ironpdf-engine-pack/ironpdf-engine-macos-x64/pom.xml +++ b/ironpdf-engine-pack/ironpdf-engine-macos-x64/pom.xml @@ -108,7 +108,7 @@ 8 8 UTF-8 - 2023.12.6 + 2024.1.20 diff --git a/ironpdf-engine-pack/ironpdf-engine-windows-x64/pom.xml b/ironpdf-engine-pack/ironpdf-engine-windows-x64/pom.xml index 0219cb6..9171c75 100644 --- a/ironpdf-engine-pack/ironpdf-engine-windows-x64/pom.xml +++ b/ironpdf-engine-pack/ironpdf-engine-windows-x64/pom.xml @@ -108,7 +108,7 @@ 8 8 UTF-8 - 2023.12.6 + 2024.1.20 diff --git a/ironpdf-engine-pack/ironpdf-engine-windows-x86/pom.xml b/ironpdf-engine-pack/ironpdf-engine-windows-x86/pom.xml index 2047d35..9b8acf9 100644 --- a/ironpdf-engine-pack/ironpdf-engine-windows-x86/pom.xml +++ b/ironpdf-engine-pack/ironpdf-engine-windows-x86/pom.xml @@ -108,7 +108,7 @@ 8 8 UTF-8 - 2023.12.6 + 2024.1.20