tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/threads Expirer.java TimeStamp.java
Date Tue, 27 Feb 2001 18:23:13 GMT
costin      01/02/27 10:23:13

  Modified:    src/share/org/apache/tomcat/core ServerSession.java
               src/share/org/apache/tomcat/modules/session
                        SimpleSessionStore.java
               src/share/org/apache/tomcat/util/log Logger.java
               src/share/org/apache/tomcat/util/threads Expirer.java
  Added:       src/share/org/apache/tomcat/util/buf TimeStamp.java
               src/share/org/apache/tomcat/util/log FastDateFormat.java
  Removed:     src/share/org/apache/tomcat/util FastDateFormat.java
               src/share/org/apache/tomcat/util/threads TimeStamp.java
  Log:
  Code move to simplify dependencies.
  
  Revision  Changes    Path
  1.7       +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/ServerSession.java
  
  Index: ServerSession.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServerSession.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ServerSession.java	2001/02/27 16:24:23	1.6
  +++ ServerSession.java	2001/02/27 18:22:58	1.7
  @@ -67,8 +67,8 @@
   import java.util.Vector;
   
   import org.apache.tomcat.util.buf.MessageBytes;
  +import org.apache.tomcat.util.buf.TimeStamp;
   
  -import org.apache.tomcat.util.threads.TimeStamp;
   
   /**
    * Server representation of a Session.
  
  
  
  1.9       +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SimpleSessionStore.java
  
  Index: SimpleSessionStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SimpleSessionStore.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SimpleSessionStore.java	2001/01/25 05:07:39	1.8
  +++ SimpleSessionStore.java	2001/02/27 18:23:01	1.9
  @@ -67,8 +67,8 @@
   import java.util.*;
   import org.apache.tomcat.util.collections.SimplePool;
   import org.apache.tomcat.util.log.*;
  +import org.apache.tomcat.util.buf.*;
   import java.security.*;
  -//import org.apache.tomcat.session.*;
   
   
   /**
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/buf/TimeStamp.java
  
  Index: TimeStamp.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  package org.apache.tomcat.util.buf;
  
  import org.apache.tomcat.util.buf.MessageBytes;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.Serializable;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Vector;
  
  
  /**
   * Main tool for object expiry. 
   * Marks creation and access time of an "expirable" object,
   * and extra properties like "id", "valid", etc.
   *
   * Used for objects that expire - originally Sessions, but 
   * also Contexts, Servlets, cache - or any other object that
   * expires.
   * 
   * @author Costin Manolache
   */
  public final class TimeStamp implements  Serializable {
      private long creationTime = 0L;
      private long lastAccessedTime = creationTime;
      private long thisAccessedTime = creationTime;
      private boolean isNew = true;
      private long maxInactiveInterval = -1;
      private boolean isValid = false;
      MessageBytes name;
      int id=-1;
      
      Object parent;
      
      public TimeStamp() {
      }
  
      // -------------------- Active methods --------------------
  
      /**
       *  Access notification. This method takes a time parameter in order
       *  to allow callers to efficiently manage expensive calls to
       *  System.currentTimeMillis() 
       */
      public void touch(long time) {
  	this.lastAccessedTime = this.thisAccessedTime;
  	this.thisAccessedTime = time;
  	this.isNew=false;
      }
  
      // -------------------- Property access --------------------
  
      /** Return the "name" of the timestamp. This can be used
       *  to associate unique identifier with each timestamped object.
       *  The name is a MessageBytes - i.e. a modifiable byte[] or char[]. 
       */
      public MessageBytes getName() {
  	if( name==null ) name=new MessageBytes();//lazy
  	return name;
      }
  
      /** Each object can have an unique id, similar with name but
       *  providing faster access ( array vs. hashtable lookup )
       */
      public int getId() {
  	return id;
      }
  
      public void setId( int id ) {
  	this.id=id;
      }
      
      /** Returns the owner of this stamp ( the object that is
       *  time-stamped ).
       *  For a 
       */
      public void setParent( Object o ) {
  	parent=o;
      }
  
      public Object getParent() {
  	return parent;
      }
  
      public void setCreationTime(long time) {
  	this.creationTime = time;
  	this.lastAccessedTime = time;
  	this.thisAccessedTime = time;
      }
  
  
      public long getLastAccessedTime() {
  	return lastAccessedTime;
      }
  
      /** Inactive interval in millis - the time is computed
       *  in millis, convert to secs in the upper layer
       */
      public long getMaxInactiveInterval() {
  	return maxInactiveInterval;
      }
  
      public void setMaxInactiveInterval(long interval) {
  	maxInactiveInterval = interval;
      }
  
      public boolean isValid() {
  	return isValid;
      }
  
      public void setValid(boolean isValid) {
  	this.isValid = isValid;
      }
  
      public boolean isNew() {
  	return isNew;
      }
  
      public void setNew(boolean isNew) {
  	this.isNew = isNew;
      }
  
      public long getCreationTime() {
  	return creationTime;
      }
  
      // -------------------- Maintainance --------------------
  
      public void recycle() {
  	creationTime = 0L;
  	lastAccessedTime = 0L;
  	maxInactiveInterval = -1;
  	isNew = true;
  	isValid = false;
  	id=-1;
  	if( name!=null) name.recycle();
      }
  
  }
  
  
  
  
  1.6       +0 -4      jakarta-tomcat/src/share/org/apache/tomcat/util/log/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/log/Logger.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Logger.java	2001/01/27 00:40:03	1.5
  +++ Logger.java	2001/02/27 18:23:08	1.6
  @@ -69,10 +69,6 @@
   import java.text.DateFormat;
   import java.text.SimpleDateFormat;
   
  -// import javax.servlet.ServletException;	// for throwableToString()
  -// import org.apache.tomcat.core.TomcatException;	// for throwableToString()
  -import org.apache.tomcat.util.FastDateFormat;
  -
   /**
    * Interface for a logging object. A logging object provides mechanism
    * for logging errors and messages that are of interest to someone who
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/log/FastDateFormat.java
  
  Index: FastDateFormat.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Original code Copyright 2000 Quadcap Software: 
   * This software may be freely redistributed in source or binary form
   * for any purpose.
   *
   */
  
  package org.apache.tomcat.util.log;
  
  import java.util.Date;
  
  import java.text.DateFormat;
  import java.text.FieldPosition;
  import java.text.ParsePosition;
  import java.text.SimpleDateFormat;
  
  /**
   * Fast date formatter that caches recently formatted date information
   * and uses it to avoid too-frequent calls to the underlying
   * formatter.  Note: breaks fieldPosition param of format(Date,
   * StringBuffer, FieldPosition).  If you care about the field
   * position, call the underlying DateFormat directly.
   *
   * @author Stan Bailes
   * @author Alex Chaffee
   **/
  public class FastDateFormat extends DateFormat {
      DateFormat    df;
      long          lastSec = -1;
      StringBuffer  sb      = new StringBuffer();
      FieldPosition fp      = new FieldPosition(DateFormat.MILLISECOND_FIELD);
      
      public FastDateFormat(DateFormat df) {
          this.df = df;
      }
  
      public Date parse(String text, ParsePosition pos) {
  	return df.parse(text, pos);
      }
  
      /**
       * Note: breaks functionality of fieldPosition param. Also:
       * there's a bug in SimpleDateFormat with "S" and "SS", use "SSS"
       * instead if you want a msec field.
       **/
      public StringBuffer format(Date date, StringBuffer toAppendTo,
  			       FieldPosition fieldPosition) {
          long dt = date.getTime();
          long ds = dt / 1000;
          if (ds != lastSec) {
              sb.setLength(0);
              df.format(date, sb, fp);
              lastSec = ds;
          } else {
  	    // munge current msec into existing string
              int ms = (int)(dt % 1000);
              int pos = fp.getEndIndex();
  	    int begin = fp.getBeginIndex();
  	    if (pos > 0) {
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  		ms /= 10;
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  		ms /= 10;
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  	    }
          }
  	toAppendTo.append(sb.toString());
  	return toAppendTo;
      }
  
      /*
      public static void main(String[] args) {
  	String format = "yyyy-MM-dd HH:mm:ss.SSS";
  	if (args.length > 0)
  	    format = args[0];
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          FastDateFormat fdf = new FastDateFormat(sdf);
          Date d = new Date();
  
  	d.setTime(1); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(20); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(500); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(543); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(999); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(1050); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(2543); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(12345); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(12340); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	
          final int reps = 100000;
          {
              long start = System.currentTimeMillis();
              for (int i = 0; i < reps; i++) {
                  d.setTime(System.currentTimeMillis());
                  fdf.format(d);
              }
              long elap = System.currentTimeMillis() - start;
              System.out.println("fast: " + elap + " elapsed");
  	    System.out.println(fdf.format(d));
          }
          {
              long start = System.currentTimeMillis();
              for (int i = 0; i < reps; i++) {
                  d.setTime(System.currentTimeMillis());
                  sdf.format(d);
              }
              long elap = System.currentTimeMillis() - start;	    
              System.out.println("slow: " + elap + " elapsed");
  	    System.out.println(sdf.format(d));
          }
      }
      */
  }
  
  
  
  1.3       +1 -2      jakarta-tomcat/src/share/org/apache/tomcat/util/threads/Expirer.java
  
  Index: Expirer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/threads/Expirer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Expirer.java	2000/09/26 03:49:55	1.2
  +++ Expirer.java	2001/02/27 18:23:11	1.3
  @@ -62,8 +62,7 @@
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Vector;
  -import org.apache.tomcat.util.*;
  -import org.apache.tomcat.util.threads.*;
  +import org.apache.tomcat.util.buf.*;
   
   /**
    * Expire unused objects. 
  
  
  

Mime
View raw message