Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java 21] Remove the use of SLF4J from Ballerina Runtime #43407

Open
wants to merge 5 commits into
base: java21
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import io.ballerina.runtime.internal.scheduling.Scheduler;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.util.RuntimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -45,6 +43,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDateTime;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;

Expand Down Expand Up @@ -86,7 +85,7 @@ public class TransactionResourceManager {
private static final String ATOMIKOS_LOG_NAME_PROPERTY = "com.atomikos.icatch.log_base_name";
private static final String ATOMIKOS_REGISTERED_PROPERTY = "com.atomikos.icatch.registered";

private static final Logger log = LoggerFactory.getLogger(TransactionResourceManager.class);
private static final PrintStream outStream = System.out;
private Map<String, List<BallerinaTransactionContext>> resourceRegistry;
private Map<String, Transaction> trxRegistry;
private Map<String, Xid> xidRegistry;
Expand Down Expand Up @@ -261,7 +260,7 @@ public boolean prepare(String transactionId, String transactionBlockId) {
xaResource.prepare(xid);
}
} catch (XAException e) {
log.error("error at transaction prepare phase in transaction " + transactionId
logError("error at transaction prepare phase in transaction " + transactionId
+ ":" + e.getMessage(), e);
return false;
}
Expand All @@ -273,7 +272,7 @@ public boolean prepare(String transactionId, String transactionBlockId) {
// resource participant reported failure.
status = false;
}
log.info(String.format("Transaction prepare (participants): %s", status ? "success" : "failed"));
outStream.printf("Transaction prepare (participants): %s%n", status ? "success" : "failed");
return status;
}

Expand All @@ -297,7 +296,7 @@ public boolean notifyCommit(String transactionId, String transactionBlockId) {
}
} catch (SystemException | HeuristicMixedException | HeuristicRollbackException
| RollbackException e) {
log.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
logError("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
commitSuccess = false;
}
}
Expand All @@ -316,7 +315,7 @@ public boolean notifyCommit(String transactionId, String transactionBlockId) {
}
}
} catch (XAException e) {
log.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
logError("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
commitSuccess = false;
} finally {
ctx.close();
Expand Down Expand Up @@ -354,7 +353,7 @@ public boolean notifyAbort(String transactionId, String transactionBlockId) {
trx.rollback();
}
} catch (SystemException e) {
log.error("error when aborting transaction " + transactionId + ":" + e.getMessage(), e);
logError("error when aborting transaction " + transactionId + ":" + e.getMessage(), e);
abortSuccess = false;
}
}
Expand All @@ -373,7 +372,7 @@ public boolean notifyAbort(String transactionId, String transactionBlockId) {
}
}
} catch (XAException e) {
log.error("error when aborting the transaction " + transactionId + ":" + e.getMessage(), e);
logError("error when aborting the transaction " + transactionId + ":" + e.getMessage(), e);
abortSuccess = false;
} finally {
ctx.close();
Expand Down Expand Up @@ -412,7 +411,7 @@ public void beginXATransaction(String transactionId, String transactionBlockId,
trxRegistry.put(combinedId, trx);
}
} catch (SystemException | NotSupportedException e) {
log.error("error in initiating transaction " + transactionId + ":" + e.getMessage(), e);
logError("error in initiating transaction " + transactionId + ":" + e.getMessage(), e);
}
} else {
Xid xid = xidRegistry.get(combinedId);
Expand All @@ -423,7 +422,7 @@ public void beginXATransaction(String transactionId, String transactionBlockId,
try {
xaResource.start(xid, TMNOFLAGS);
} catch (XAException e) {
log.error("error in starting XA transaction " + transactionId + ":" + e.getMessage(), e);
logError("error in starting XA transaction " + transactionId + ":" + e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -556,7 +555,7 @@ void endXATransaction(String transactionId, String transactionBlockId, boolean a
trx.delistResource(xaResource, TMSUCCESS);
}
} catch (IllegalStateException | SystemException e) {
log.error("error in ending the XA transaction " + transactionId
logError("error in ending the XA transaction " + transactionId
+ ":" + e.getMessage(), e);
}
}
Expand All @@ -573,7 +572,7 @@ void endXATransaction(String transactionId, String transactionBlockId, boolean a
xaResource.end(xid, abortOnly ? TMFAIL : TMSUCCESS);
}
} catch (XAException e) {
log.error("error in ending XA transaction " + transactionId + ":" + e.getMessage(), e);
logError("error in ending XA transaction " + transactionId + ":" + e.getMessage(), e);
}
}
}
Expand All @@ -600,7 +599,7 @@ private String generateCombinedTransactionId(String transactionId, String transa
public void notifyResourceFailure(String gTransactionId) {
failedResourceParticipantSet.add(gTransactionId);
// The resource excepted (uncaught).
log.info("Trx infected callable unit excepted id : " + gTransactionId);
outStream.println("Trx infected callable unit excepted id : " + gTransactionId);
}

public void notifyLocalParticipantFailure(String gTransactionId, String blockId) {
Expand All @@ -618,4 +617,9 @@ public Object getTransactionRecord(BArray xid) {
return null;
}
}

private void logError(String message, Exception err) {
outStream.println(LocalDateTime.now() + "ERROR\t" + message + "\n");
err.printStackTrace();
ravinperera00 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading