[ 
https://issues.apache.org/jira/browse/AXIS2-5788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Robert Lazarski resolved AXIS2-5788.
------------------------------------
    Resolution: Fixed

Fixed in git master, see below: 

    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.


> ConfigurationContext.getServiceGroupContext(id) always touches the id - 
> ("Observer Effect")
> -------------------------------------------------------------------------------------------
>
>                 Key: AXIS2-5788
>                 URL: https://issues.apache.org/jira/browse/AXIS2-5788
>             Project: Axis2
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.7.3
>         Environment: ANY
>            Reporter: Jeff Thomas
>            Assignee: Robert Lazarski
>            Priority: Major
>             Fix For: 2.0.1
>
>
> Currently it is not possibel to get a ServiceGroupContext from the 
> ConfigurationContext without forcing a touch to the 'lastTouchedTime'.
> This prevents us from performing our own checks against the lastTouchedTime 
> because it is always set to the System time ("Observer Effect" - by observing 
> the system, we change the system).
> I would propose a second API method which would allow retrieval of the 
> ServiceGroupContext by id without touching the lastTouchedTime.
> Here my proposed code change:
> {code:java}
>    /**
>      * Returns a ServiceGroupContext object associated with the specified ID 
> from the internal table.
>      * <p>
>      * If found, the returned {@code ServiceGroupContext} will be touched 
> with the current system time.
>      * 
>      * @param serviceGroupCtxId The ID string associated with the 
> ServiceGroupContext object
>      * @return The ServiceGroupContext object, or {@code null} if not found
>      */
>     public ServiceGroupContext getServiceGroupContext(String 
> serviceGroupCtxId) {
>         return getServiceGroupContext(serviceGroupCtxId, true);
>     }
>    /**
>      * Returns a ServiceGroupContext object associated with the specified ID 
> from the internal table.
>      *
>      * @param serviceGroupCtxId The ID string associated with the 
> ServiceGroupContext object
>      * @param touchServiceGroupContext if {@code true} the retrieved {@code 
> ServiceGroupContext} will be touched on
>      *    retrieval; otherwise, {@code false}.
>      * @return the ServiceGroupContext object, or {@code null} if not found
>      */
>     public ServiceGroupContext getServiceGroupContext(String 
> serviceGroupCtxId, boolean touchServiceGroupContext) {
>         if (serviceGroupCtxId == null) {
>             // Hashtables require non-null key-value pairs
>             return null;
>         }
>         ServiceGroupContext serviceGroupContext = null;
>         if (serviceGroupContextMap != null) {
>             serviceGroupContext 
> =serviceGroupContextMap.get(serviceGroupCtxId);
>             if (serviceGroupContext != null && touchServiceGroupContext) {
>                 serviceGroupContext.touch();
>             } else {
>                 serviceGroupContext =applicationSessionServiceGroupContexts
>                   .get(serviceGroupCtxId);
>                 if (serviceGroupContext != null && touchServiceGroupContext) {
>                     serviceGroupContext.touch();
>                 }
>             }
>         }
>         
>         return serviceGroupContext;
>         
>     }
> {code}
> Side note: the javadoc of getServiceGroupContextIDs is incorrect.  The method 
> returns a String[] array of ids and not a hashmap of ServiceGroupContexts.
> {code:java}
>    /**
>      * Gets all service groups in the system.
>      *
>      * @return Returns hashmap of ServiceGroupContexts.
>      */
>     public String[] getServiceGroupContextIDs() {
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to