cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ovi...@apache.org
Subject cvs commit: xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow WebContinuation.java
Date Wed, 10 Apr 2002 00:38:01 GMT
ovidiu      02/04/09 17:38:01

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/components/flow
                        WebContinuation.java
  Log:
  Added support for the last access time. Pass an additional
  time-to-live argument when creating a WebContinuation.
  
  Revision  Changes    Path
  1.4       +55 -7     xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/WebContinuation.java
  
  Index: WebContinuation.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/WebContinuation.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WebContinuation.java	2 Apr 2002 05:02:25 -0000	1.3
  +++ WebContinuation.java	10 Apr 2002 00:38:01 -0000	1.4
  @@ -1,6 +1,8 @@
   package org.apache.cocoon.components.flow;
   
  +import java.lang.Comparable;
   import java.util.ArrayList;
  +import java.util.Date;
   import java.util.List;
   
   /**
  @@ -19,11 +21,12 @@
    * @since March 19, 2002
    */
   public class WebContinuation
  +  implements Comparable
   {
     /**
      * The continuation this object represents.
      */
  -  Object continuation;
  +  protected Object continuation;
   
     /**
      * The parent <code>WebContinuation</code> from which processing
  @@ -35,19 +38,19 @@
      *
      * @see ContinuationsManager
      */
  -  WebContinuation parentContinuation;
  +  protected WebContinuation parentContinuation;
   
     /**
      * The children continuations. These are continuations created by
      * resuming the processing from the point stored by
      * <code>continuation</code>.
      */
  -  List children = new ArrayList();
  +  protected List children = new ArrayList();
   
     /**
      * The continuation id used to represent this instance in Web pages.
      */
  -  String id;
  +  protected String id;
   
     /**
      * A user definable object. This is present for convenience, to
  @@ -55,7 +58,21 @@
      * <code>WebContinuation</code> a particular implementation might
      * need.
      */
  -  Object userObject;
  +  protected Object userObject;
  +
  +  /**
  +   * When was this continuation accessed last time. Each time the
  +   * continuation is accessed, this time is set to the time of the
  +   * access.
  +   */
  +  protected long lastAccessTime;
  +
  +  /**
  +   * Indicates how long does this continuation will live (in
  +   * seconds). The continuation will be removed once the current time
  +   * is bigger than <code>lastAccessTime + timeToLive</code>.
  +   */
  +  protected int timeToLive;
   
     /**
      * Create a <code>WebContinuation</code> object. Saves the object in
  @@ -69,11 +86,13 @@
      */
     public WebContinuation(Object continuation,
                            WebContinuation parentContinuation,
  -                         ContinuationsManagerImpl manager)
  +                         ContinuationsManagerImpl manager,
  +                         int timeToLive)
     {
       this.continuation = continuation;
       this.parentContinuation = parentContinuation;
       id = manager.generateContinuationId(this);
  +    this.timeToLive = timeToLive;
       if (parentContinuation != null)
         this.parentContinuation.children.add(this);
     }
  @@ -85,6 +104,7 @@
      */
     public Object getContinuation()
     {
  +    updateLastAccessTime();
       return continuation;
     }
   
  @@ -101,8 +121,10 @@
      */
     public WebContinuation getContinuation(int level)
     {
  -    if (level <= 0)
  +    if (level <= 0) {
  +      updateLastAccessTime();
         return this;
  +    }
       else if (parentContinuation == null)
         return this;
       else
  @@ -187,6 +209,24 @@
     }
   
     /**
  +   * Compares the expiration time of this instance with that of the
  +   * WebContinuation passed as argument.
  +   *
  +   * <p><b>Note:</b> this class has a natural ordering that is
  +   * inconsistent with <code>equals</code>.</p>.
  +   *
  +   * @param other an <code>Object</code> value, which should be a
  +   * <code>WebContinuation</code> instance
  +   * @return an <code>int</code> value
  +   */
  +  public int compareTo(Object other)
  +  {
  +    WebContinuation wk = (WebContinuation)other;
  +    return (int)((lastAccessTime + timeToLive)
  +                 - (wk.lastAccessTime + wk.timeToLive));
  +  }
  +
  +  /**
      * Debugging method.
      *
      * <p>Assumes the receiving instance as the root of a tree and
  @@ -219,5 +259,13 @@
       depth++;
       for (int i = 0; i < size; i++)
         ((WebContinuation)children.get(i)).display(depth);
  +  }
  +
  +  /**
  +   * Update the continuation in the 
  +   */
  +  protected void updateLastAccessTime()
  +  {
  +    lastAccessTime = (new Date()).getTime();
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message