Skip to content

Commit

Permalink
fix counter creation bug and assorted optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Jan 9, 2025
1 parent ade59a5 commit 2abaefa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions jpos/src/main/java/org/jpos/transaction/TransactionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public void initService () throws ConfigurationException {
sp = SpaceFactory.getSpace (cfg.get ("space"));
isp = iisp = SpaceFactory.getSpace (cfg.get ("input-space", cfg.get ("space")));
psp = SpaceFactory.getSpace (cfg.get ("persistent-space", this.toString()));
doRecover = cfg.getBoolean ("recover", psp instanceof PersistentSpace);

tail = initCounter (TAIL, cfg.getLong ("initial-tail", 1));
head = Math.max (initCounter (HEAD, tail), tail);
initTailLock ();
Expand All @@ -134,7 +136,7 @@ public void initService () throws ConfigurationException {
initParticipants (getPersist());
initStatusListeners (getPersist());
executor = QFactory.executorService(cfg.getBoolean("virtual-threads", true));

if (!filtersAdded.getAndSet(true)) {
getServer().getMeterRegistry().config().meterFilter(new MeterFilter() {
@Override
Expand Down Expand Up @@ -366,7 +368,6 @@ public long getInTransit () {
@Override
public void setConfiguration (Configuration cfg) throws ConfigurationException {
super.setConfiguration (cfg);
doRecover = cfg.getBoolean ("recover", true);
retryInterval = cfg.getLong ("retry-interval", retryInterval);
retryTimeout = cfg.getLong ("retry-timeout", retryTimeout);
pauseTimeout = cfg.getLong ("pause-timeout", pauseTimeout);
Expand Down Expand Up @@ -704,7 +705,7 @@ protected List<TransactionParticipant> getParticipants (String groupName) {
protected List<TransactionParticipant> getParticipants (long id) {
// Use a local copy of participant to avoid adding the
// GROUP participant to the DEFAULT_GROUP
List<TransactionParticipant> participantsChain = new ArrayList();
List<TransactionParticipant> participantsChain = new ArrayList<>();
List<TransactionParticipant> participants = getParticipants (DEFAULT_GROUP);
// Add DEFAULT_GROUP participants
participantsChain.addAll(participants);
Expand Down Expand Up @@ -829,7 +830,7 @@ protected void syncTail () {
}
}
protected void initTailLock () {
tailLock = TAILLOCK + "." + Integer.toString (this.hashCode());
tailLock = TAILLOCK + "." + this.hashCode();
sp.put (tailLock, TAILLOCK);
}
protected void checkTail () {
Expand Down Expand Up @@ -1081,11 +1082,11 @@ private void removeThreadLocal() {
}

private String getName(TransactionParticipant p) {
return getParams(p).name();
return p.getClass().getName();
}

private ParticipantParams getParams (TransactionParticipant p) {
return Optional.ofNullable(params.get(p)).orElse(
return Optional.ofNullable(params.get(p)).orElseGet(() ->
new ParticipantParams(p.getClass().getName(), 0L, 0L, Collections.emptySet(), Collections.emptySet(), Collections.emptySet(),
getOrCreateTimers(p))
);
Expand Down Expand Up @@ -1234,8 +1235,8 @@ private Serializable recover (ContextRecovery p, long id, Serializable context,
}

private Timers getOrCreateTimers(TransactionParticipant p) {
var mr = getServer().getMeterRegistry();
String participantShortName = Caller.shortClassName(p.getClass().getName());
var mr = getServer().getMeterRegistry();
var tags = Tags.of("name", getName(), "participant", participantShortName);
if (p instanceof LogSource ls) {
String realm = ls.getRealm();
Expand Down

0 comments on commit 2abaefa

Please sign in to comment.