Skip to content

Commit

Permalink
Rename static final fields to screaming snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil committed Sep 9, 2024
1 parent 068ab8f commit 246a310
Show file tree
Hide file tree
Showing 43 changed files with 290 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public class JsonGenerator implements Closeable {

private boolean fieldActive;

private static final boolean[] escChars = new boolean[93];
private static final boolean[] ESC_CHARS = new boolean[93];

static {
escChars['"'] = true;
escChars['\\'] = true;
escChars['\b'] = true;
escChars['\n'] = true;
escChars['\r'] = true;
escChars['\t'] = true;
ESC_CHARS['"'] = true;
ESC_CHARS['\\'] = true;
ESC_CHARS['\b'] = true;
ESC_CHARS['\n'] = true;
ESC_CHARS['\r'] = true;
ESC_CHARS['\t'] = true;
}

public JsonGenerator(OutputStream out) {
Expand Down Expand Up @@ -159,7 +159,7 @@ private void writeStringValue(String value) throws IOException {
char[] chs = value.toCharArray();
for (int i = 0; i < count; i++) {
ch = chs[i];
if (ch < escChars.length && escChars[ch]) {
if (ch < ESC_CHARS.length && ESC_CHARS[ch]) {
escaped = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
public class XmlTreeBuilder {

// XMLInputFactory2
private static final XMLInputFactory xmlInputFactory;
private static final XMLInputFactory XML_INPUT_FACTORY;

static {
xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
XML_INPUT_FACTORY = XMLInputFactory.newInstance();
XML_INPUT_FACTORY.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
}

private XMLStreamReader xmlStreamReader;
Expand All @@ -89,7 +89,7 @@ public XmlTreeBuilder(Reader stringReader) {
seqDeque.push(new XmlSequence(siblings));

try {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(stringReader);
} catch (XMLStreamException e) {
handleXMLStreamException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
public class Scheduler {

private static final PrintStream err = System.err;
private static final PrintStream ERR = System.err;

/**
* Scheduler does not get killed if the immortal value is true. Specific to services.
Expand All @@ -66,13 +66,13 @@ public class Scheduler {
*/
private final BlockingQueue<ItemGroup> runnableList = new LinkedBlockingDeque<>();

private static final ThreadLocal<StrandHolder> strandHolder = ThreadLocal.withInitial(StrandHolder::new);
private static final ConcurrentHashMap<Integer, Strand> currentStrands = new ConcurrentHashMap<>();
private static final ThreadLocal<StrandHolder> STRAND_HOLDER = ThreadLocal.withInitial(StrandHolder::new);
private static final ConcurrentHashMap<Integer, Strand> CURRENT_STRANDS = new ConcurrentHashMap<>();
private final Strand previousStrand;

private final AtomicInteger totalStrands = new AtomicInteger();

private static final String poolSizeConf = System.getenv(RuntimeConstants.BALLERINA_MAX_POOL_SIZE_ENV_VAR);
private static final String POOL_SIZE_CONF = System.getenv(RuntimeConstants.BALLERINA_MAX_POOL_SIZE_ENV_VAR);

/**
* This can be changed by setting the BALLERINA_MAX_POOL_SIZE system variable.
Expand Down Expand Up @@ -103,13 +103,13 @@ public Scheduler(int numThreads, boolean immortal) {
this.numThreads = numThreads;
this.immortal = immortal;
this.runtimeRegistry = new RuntimeRegistry(this);
this.previousStrand = numThreads == 1 ? strandHolder.get().strand : null;
this.previousStrand = numThreads == 1 ? STRAND_HOLDER.get().strand : null;
ItemGroup group = new ItemGroup();
objectGroup.set(group);
}

public static Strand getStrand() {
Strand strand = strandHolder.get().strand;
Strand strand = STRAND_HOLDER.get().strand;
if (strand == null) {
throw new IllegalStateException("strand is not accessible from non-strand-worker threads");
}
Expand All @@ -118,11 +118,11 @@ public static Strand getStrand() {

public static Strand getStrandNoException() {
// issue #22871 is opened to fix this
return strandHolder.get().strand;
return STRAND_HOLDER.get().strand;
}

public static Map<Integer, Strand> getCurrentStrands() {
return new HashMap<>(currentStrands);
return new HashMap<>(CURRENT_STRANDS);
}

/**
Expand Down Expand Up @@ -316,7 +316,7 @@ private void run() {
item = group.get();

try {
strandHolder.get().strand = item.future.strand;
STRAND_HOLDER.get().strand = item.future.strand;
result = item.execute();
} catch (Throwable e) {
panic = createError(e);
Expand All @@ -331,7 +331,7 @@ private void run() {
RuntimeUtils.printCrashLog(panic);
}
} finally {
strandHolder.get().strand = previousStrand;
STRAND_HOLDER.get().strand = previousStrand;
}
postProcess(item, result, panic);
group.lock();
Expand Down Expand Up @@ -458,7 +458,7 @@ private void cleanUp(Strand justCompleted) {
justCompleted.frames = null;
justCompleted.waitingContexts = null;

currentStrands.remove(justCompleted.getId());
CURRENT_STRANDS.remove(justCompleted.getId());
//TODO: more cleanup , eg channels
}

Expand Down Expand Up @@ -507,7 +507,7 @@ public FutureValue createFuture(Strand parent, Callback callback, Map<String, Ob
Type constraint, String name, StrandMetadata metadata) {
Strand newStrand = new Strand(name, metadata, this, parent, properties, parent != null ?
parent.currentTrxContext : null);
currentStrands.put(newStrand.getId(), newStrand);
CURRENT_STRANDS.put(newStrand.getId(), newStrand);
return createFuture(parent, callback, constraint, newStrand);
}

Expand Down Expand Up @@ -540,12 +540,12 @@ public RuntimeRegistry getRuntimeRegistry() {

private static int getPoolSize() {
try {
if (poolSizeConf != null) {
poolSize = Integer.parseInt(poolSizeConf);
if (POOL_SIZE_CONF != null) {
poolSize = Integer.parseInt(POOL_SIZE_CONF);
}
} catch (Throwable t) {
// Log and continue with default
err.println("ballerina: error occurred in scheduler while reading system variable:" +
ERR.println("ballerina: error occurred in scheduler while reading system variable:" +
RuntimeConstants.BALLERINA_MAX_POOL_SIZE_ENV_VAR + ", " + t.getMessage());
}
return poolSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class BSpan {
private static final MapType IMMUTABLE_STRING_MAP_TYPE = TypeCreator.createMapType(
PredefinedTypes.TYPE_STRING, true);

private static final PropagatingParentContextGetter getter = new PropagatingParentContextGetter();
private static final PropagatingParentContextSetter setter = new PropagatingParentContextSetter();
private static final PropagatingParentContextGetter GETTER = new PropagatingParentContextGetter();
private static final PropagatingParentContextSetter SETTER = new PropagatingParentContextSetter();

static class PropagatingParentContextGetter implements TextMapGetter<Map<String, String>> {
@Override
Expand Down Expand Up @@ -137,7 +137,7 @@ public static BSpan start(Map<String, String> parentTraceContext, String service

Tracer tracer = TracersStore.getInstance().getTracer(serviceName);
Context parentContext = TracersStore.getInstance().getPropagators()
.getTextMapPropagator().extract(Context.current(), parentTraceContext, getter);
.getTextMapPropagator().extract(Context.current(), parentTraceContext, GETTER);
return start(tracer, parentContext, operationName, isClient);
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public Map<String, String> extractContextAsHttpHeaders() {
if (span != null) {
carrierMap = new HashMap<>();
TextMapPropagator propagator = TracersStore.getInstance().getPropagators().getTextMapPropagator();
propagator.inject(Context.current().with(span), carrierMap, setter);
propagator.inject(Context.current().with(span), carrierMap, SETTER);
} else {
carrierMap = Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TransactionLocalContext {
private Map<String, BallerinaTransactionContext> transactionContextStore;
private final Stack<String> transactionBlockIdStack;
private final Stack<TransactionFailure> transactionFailure;
private static final TransactionResourceManager transactionResourceManager =
private static final TransactionResourceManager TRANSACTION_RESOURCE_MANAGER =
TransactionResourceManager.getInstance();
private boolean isResourceParticipant;
private Object rollbackOnlyError;
Expand Down Expand Up @@ -71,7 +71,7 @@ private void validateAndPutTransactionInfo(ByteBuffer transactionIdBytes, Object
if (infoRecord == null) {
return;
}
transactionResourceManager.transactionInfoMap.put(transactionIdBytes, infoRecord);
TRANSACTION_RESOURCE_MANAGER.transactionInfoMap.put(transactionIdBytes, infoRecord);
}

public static TransactionLocalContext createTransactionParticipantLocalCtx(String globalTransactionId,
Expand Down Expand Up @@ -159,8 +159,8 @@ public boolean isRetryPossible(Strand context, String transactionId) {

public void notifyAbortAndClearTransaction(String transactionBlockId) {
transactionContextStore.clear();
transactionResourceManager.endXATransaction(globalTransactionId, transactionBlockId, true);
transactionResourceManager.notifyAbort(globalTransactionId, transactionBlockId);
TRANSACTION_RESOURCE_MANAGER.endXATransaction(globalTransactionId, transactionBlockId, true);
TRANSACTION_RESOURCE_MANAGER.notifyAbort(globalTransactionId, transactionBlockId);
}

public void setRollbackOnlyError(Object error) {
Expand All @@ -180,12 +180,12 @@ public Object getTransactionData() {
}

public void removeTransactionInfo() {
transactionResourceManager.transactionInfoMap.remove(ByteBuffer.wrap(transactionId.getBytes()));
TRANSACTION_RESOURCE_MANAGER.transactionInfoMap.remove(ByteBuffer.wrap(transactionId.getBytes()));
}

public void notifyLocalParticipantFailure() {
String blockId = transactionBlockIdStack.peek();
transactionResourceManager.notifyLocalParticipantFailure(globalTransactionId, blockId);
TRANSACTION_RESOURCE_MANAGER.notifyLocalParticipantFailure(globalTransactionId, blockId);
}

public void notifyLocalRemoteParticipantFailure() {
Expand Down Expand Up @@ -235,7 +235,7 @@ public void setResourceParticipant(boolean resourceParticipant) {
}

public Object getInfoRecord() {
return transactionResourceManager.getTransactionRecord(transactionId);
return TRANSACTION_RESOURCE_MANAGER.getTransactionRecord(transactionId);
}

public boolean isTransactional() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class TransactionResourceManager {
public static final String TRANSACTION_AUTO_COMMIT_TIMEOUT_KEY = "transactionAutoCommitTimeout";
public static final String TRANSACTION_CLEANUP_TIMEOUT_KEY = "transactionCleanupTimeout";

private static final Logger log = LoggerFactory.getLogger(TransactionResourceManager.class);
private static final Logger LOG = LoggerFactory.getLogger(TransactionResourceManager.class);
private final Map<String, List<BallerinaTransactionContext>> resourceRegistry = new HashMap<>();
private Map<String, Transaction> trxRegistry;
private Map<String, Xid> xidRegistry;
Expand All @@ -105,7 +105,7 @@ public class TransactionResourceManager {
private final ConcurrentMap<String, Set<String>> localParticipants = new ConcurrentHashMap<>();

private final boolean transactionManagerEnabled;
private static final PrintStream stderr = System.err;
private static final PrintStream STDERR = System.err;

final Map<ByteBuffer, Object> transactionInfoMap = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -151,7 +151,7 @@ private void setLogProperties() {
try {
Files.createDirectory(transactionLogDirectory);
} catch (IOException e) {
stderr.println("error: failed to create transaction log directory in " + logDir);
STDERR.println("error: failed to create transaction log directory in " + logDir);
}
}
System.setProperty(ATOMIKOS_LOG_BASE_PROPERTY, logDir);
Expand Down Expand Up @@ -313,7 +313,7 @@ public boolean prepare(String transactionId, String transactionBlockId) {
xaResource.prepare(xid);
}
} catch (XAException e) {
log.error("error at transaction prepare phase in transaction " + transactionId
LOG.error("error at transaction prepare phase in transaction " + transactionId
+ ":" + e.getMessage(), e);
return false;
}
Expand All @@ -325,7 +325,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"));
LOG.info(String.format("Transaction prepare (participants): %s", status ? "success" : "failed"));
return status;
}

Expand All @@ -349,7 +349,7 @@ public boolean notifyCommit(String transactionId, String transactionBlockId) {
}
} catch (SystemException | HeuristicMixedException | HeuristicRollbackException
| RollbackException e) {
log.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
LOG.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
commitSuccess = false;
}
}
Expand All @@ -368,7 +368,7 @@ public boolean notifyCommit(String transactionId, String transactionBlockId) {
}
}
} catch (XAException e) {
log.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
LOG.error("error when committing transaction " + transactionId + ":" + e.getMessage(), e);
commitSuccess = false;
} finally {
ctx.close();
Expand Down Expand Up @@ -406,7 +406,7 @@ public boolean notifyAbort(String transactionId, String transactionBlockId) {
trx.rollback();
}
} catch (SystemException e) {
log.error("error when aborting transaction " + transactionId + ":" + e.getMessage(), e);
LOG.error("error when aborting transaction " + transactionId + ":" + e.getMessage(), e);
abortSuccess = false;
}
}
Expand All @@ -425,7 +425,7 @@ public boolean notifyAbort(String transactionId, String transactionBlockId) {
}
}
} catch (XAException e) {
log.error("error when aborting the transaction " + transactionId + ":" + e.getMessage(), e);
LOG.error("error when aborting the transaction " + transactionId + ":" + e.getMessage(), e);
abortSuccess = false;
} finally {
ctx.close();
Expand Down Expand Up @@ -464,7 +464,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);
LOG.error("error in initiating transaction " + transactionId + ":" + e.getMessage(), e);
}
} else {
Xid xid = xidRegistry.get(combinedId);
Expand All @@ -475,7 +475,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);
LOG.error("error in starting XA transaction " + transactionId + ":" + e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -608,7 +608,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
LOG.error("error in ending the XA transaction " + transactionId
+ ":" + e.getMessage(), e);
}
}
Expand All @@ -625,7 +625,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);
LOG.error("error in ending XA transaction " + transactionId + ":" + e.getMessage(), e);
}
}
}
Expand All @@ -652,7 +652,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);
LOG.info("Trx infected callable unit excepted id : " + gTransactionId);
}

public void notifyLocalParticipantFailure(String gTransactionId, String blockId) {
Expand Down
Loading

0 comments on commit 246a310

Please sign in to comment.