Skip to content

Commit 905b30e

Browse files
AXIS2-5788 Add non-touching overload of getServiceGroupContext
ConfigurationContext.getServiceGroupContext(id) always calls ServiceGroupContext.touch() on a hit, which resets lastTouchedTime. That is an "observer effect": any caller that wants to inspect a context (e.g. a session-cleanup sweep evaluating staleness against lastTouchedTime) mutates the very field it is trying to read and ends up keeping the context alive forever. Add an overload that takes an explicit touchServiceGroupContext flag: ServiceGroupContext getServiceGroupContext(String id, boolean touchServiceGroupContext) The existing single-arg method is preserved and delegates with touch=true, so legacy callers see no behaviour change. Callers that want a read-only peek pass touch=false. Also fix the stale Javadoc on getServiceGroupContextIDs() noted in the same ticket (it claimed to return a hashmap; it returns a String[]). No functional change to the lookup itself beyond collapsing the duplicated touch() call at the two hit sites into a single branch.
1 parent 29d29c9 commit 905b30e

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,36 @@ public ServiceGroupContext getServiceGroupContextFromSoapSessionTable(
500500

501501
/**
502502
* Returns a ServiceGroupContext object associated with the specified ID from the internal
503-
* table.
503+
* table. The returned context's {@code lastTouchedTime} is updated as a side effect of the
504+
* lookup; use {@link #getServiceGroupContext(String, boolean)} with {@code touch=false}
505+
* if the caller needs to inspect the context (for example to evaluate staleness against
506+
* {@code lastTouchedTime}) without mutating it. See AXIS2-5788.
504507
*
505508
* @param serviceGroupCtxId The ID string associated with the ServiceGroupContext object
506509
* @return The ServiceGroupContext object, or null if not found
507510
*/
508511
public ServiceGroupContext getServiceGroupContext(String serviceGroupCtxId) {
512+
return getServiceGroupContext(serviceGroupCtxId, true);
513+
}
514+
515+
/**
516+
* Returns a ServiceGroupContext object associated with the specified ID from the internal
517+
* table, optionally updating its {@code lastTouchedTime}.
518+
* <p>
519+
* Passing {@code touchServiceGroupContext=false} lets external code read the context
520+
* without the "observer effect" described in
521+
* <a href="https://issues.apache.org/jira/browse/AXIS2-5788">AXIS2-5788</a>:
522+
* for example, session-cleanup code that wants to evaluate staleness against
523+
* {@code lastTouchedTime} would otherwise reset the clock by the very act of looking.
524+
*
525+
* @param serviceGroupCtxId The ID string associated with the ServiceGroupContext object.
526+
* @param touchServiceGroupContext {@code true} to update {@code lastTouchedTime} on a hit
527+
* (legacy behaviour preserved for back-compat), {@code false}
528+
* to leave it unchanged.
529+
* @return The ServiceGroupContext object, or null if not found.
530+
*/
531+
public ServiceGroupContext getServiceGroupContext(String serviceGroupCtxId,
532+
boolean touchServiceGroupContext) {
509533

510534
if (serviceGroupCtxId == null) {
511535
// Hashtables require non-null key-value pairs
@@ -515,15 +539,13 @@ public ServiceGroupContext getServiceGroupContext(String serviceGroupCtxId) {
515539
ServiceGroupContext serviceGroupContext = null;
516540

517541
if (serviceGroupContextMap != null) {
518-
serviceGroupContext =serviceGroupContextMap.get(serviceGroupCtxId);
519-
if (serviceGroupContext != null) {
520-
serviceGroupContext.touch();
521-
} else {
522-
serviceGroupContext =applicationSessionServiceGroupContexts
542+
serviceGroupContext = serviceGroupContextMap.get(serviceGroupCtxId);
543+
if (serviceGroupContext == null) {
544+
serviceGroupContext = applicationSessionServiceGroupContexts
523545
.get(serviceGroupCtxId);
524-
if (serviceGroupContext != null) {
525-
serviceGroupContext.touch();
526-
}
546+
}
547+
if (serviceGroupContext != null && touchServiceGroupContext) {
548+
serviceGroupContext.touch();
527549
}
528550
}
529551

@@ -532,9 +554,14 @@ public ServiceGroupContext getServiceGroupContext(String serviceGroupCtxId) {
532554
}
533555

534556
/**
535-
* Gets all service groups in the system.
557+
* Returns the IDs of all service groups currently held by this
558+
* {@code ConfigurationContext} (both SOAP-session and application-session scoped).
559+
* <p>
560+
* Fixes the stale Javadoc noted in
561+
* <a href="https://issues.apache.org/jira/browse/AXIS2-5788">AXIS2-5788</a>: the return
562+
* type is a {@code String[]}, not a hashmap of {@code ServiceGroupContext} instances.
536563
*
537-
* @return Returns hashmap of ServiceGroupContexts.
564+
* @return an array of service group context IDs; never {@code null}, but may be empty.
538565
*/
539566
public String[] getServiceGroupContextIDs() {
540567
String[] ids = new String[serviceGroupContextMap.size() +

0 commit comments

Comments
 (0)