Hi,

On 22.06.2010 10:31, Felix Meschberger (JIRA) wrote:
> Add ResourceResolver.isLive() method
> ------------------------------------
>                  URL: https://issues.apache.org/jira/browse/SLING-1566
>
> Finally, in the JcrResourceReslver, the live-check is mainly implemented
> in the checkClosed() method. Probably this method should not only check
> the close state of itself but also, whether the underlying primary
> session is still alive. If the ResourceResolver has not been closed
> yet, but the session has already been logged out, the JcrResourceResolver
> may choose to close itself too (as a side effect). This is to be discussed.

My idea is to modify the JcrResourceResolver.isLive() and .checkClosed()
methods as follows:

   public boolean isLive() {
       if (closed) {
           return false;
       }

       if (getSession().isLive()) {
           return true;
       }

       this.close();
       return false;
   }

   private void checkClosed() {
       if (!isLive()) {
           throw new IllegalStateException(...);
       }
   }

The nice thing here is, that the ResourceResolver live state also in
reality depends on the Session live state. This makes sense, because
Jackrabbit 2 will close sessions automatically if it recognizes a
session to be used by multiple threads concurrently for writing.

The disadvantage is, that a ResourceResolver will be closed as a side
effect of checking whether it is still alive.

WDYT ?

Regards
Felix

Reply via email to