Skip to content

Commit

Permalink
Merge pull request #23 from iron-software/automate-merge-code
Browse files Browse the repository at this point in the history
Copy from IronPolyglot on 2024-01-10
  • Loading branch information
ikkyuland authored Jan 10, 2024
2 parents 5b07f2e + e2605aa commit bb0f21c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ironpdf-engine-pack/ironpdf-engine-linux-x64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ironpdf.engine.version>2023.12.6</ironpdf.engine.version>
<ironpdf.engine.version>2024.1.20</ironpdf.engine.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion ironpdf-engine-pack/ironpdf-engine-macos-arm64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ironpdf.engine.version>2023.12.6</ironpdf.engine.version>
<ironpdf.engine.version>2024.1.20</ironpdf.engine.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion ironpdf-engine-pack/ironpdf-engine-macos-x64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ironpdf.engine.version>2023.12.6</ironpdf.engine.version>
<ironpdf.engine.version>2024.1.20</ironpdf.engine.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion ironpdf-engine-pack/ironpdf-engine-windows-x64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ironpdf.engine.version>2023.12.6</ironpdf.engine.version>
<ironpdf.engine.version>2024.1.20</ironpdf.engine.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion ironpdf-engine-pack/ironpdf-engine-windows-x86/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ironpdf.engine.version>2023.12.6</ironpdf.engine.version>
<ironpdf.engine.version>2024.1.20</ironpdf.engine.version>
</properties>

<build>
Expand Down

0 comments on commit bb0f21c

Please sign in to comment.