User: olegnitz
  Date: 02/02/10 09:57:44

  Modified:    jetty/src/main/org/mortbay/jetty/servlet Dispatcher.java
                        FilterHandler.java FilterHolder.java
                        HashSessionManager.java Holder.java
                        ServletHandler.java ServletHolder.java
                        ServletHttpContext.java ServletHttpRequest.java
                        ServletHttpResponse.java ServletIn.java
                        ServletOut.java ServletSSL.java ServletWriter.java
                        SessionContext.java SessionManager.java
                        WebApplicationContext.java
  Added:       jetty/src/main/org/mortbay/jetty/servlet
                        AbstractSessionManager.java
  Log:
  Fresh version of Jetty and patches to Jetty plugin by Jan Bartel
  
  Revision  Changes    Path
  1.2       +0 -0      contrib/jetty/src/main/org/mortbay/jetty/servlet/Dispatcher.java
  
  Index: Dispatcher.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/Dispatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Dispatcher.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ Dispatcher.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: Dispatcher.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: Dispatcher.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -45,7 +45,7 @@
   /* ------------------------------------------------------------ */
   /** Servlet RequestDispatcher.
    * 
  - * @version $Id: Dispatcher.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: Dispatcher.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class Dispatcher implements RequestDispatcher
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/FilterHandler.java
  
  Index: FilterHandler.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/FilterHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilterHandler.java        17 Jan 2002 01:23:21 -0000      1.1
  +++ FilterHandler.java        10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 2001 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: FilterHandler.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: FilterHandler.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -41,7 +41,7 @@
    * or more intelligently merge entries in the cache.
    *
    * @since Servlet 2.3
  - * @version  $Id: FilterHandler.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version  $Id: FilterHandler.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class FilterHandler
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/FilterHolder.java
  
  Index: FilterHolder.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/FilterHolder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilterHolder.java 17 Jan 2002 01:23:21 -0000      1.1
  +++ FilterHolder.java 10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: FilterHolder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: FilterHolder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -17,7 +17,7 @@
   /* --------------------------------------------------------------------- */
   /** 
    * @see org.mortbay.jetty.ServletHandler
  - * @version $Id: FilterHolder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: FilterHolder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins
    */
   public class FilterHolder
  
  
  
  1.2       +13 -519   
contrib/jetty/src/main/org/mortbay/jetty/servlet/HashSessionManager.java
  
  Index: HashSessionManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/HashSessionManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HashSessionManager.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ HashSessionManager.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: HashSessionManager.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: HashSessionManager.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -28,552 +28,46 @@
   import org.mortbay.util.Log;
   import org.mortbay.util.Code;
   import org.mortbay.util.LazyList;
  +import java.util.Random;
   
   
   /* ------------------------------------------------------------ */
   /** An in-memory implementation of SessionManager
    * <p>
    *
  - * @version $Id: HashSessionManager.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: HashSessionManager.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
  -public class HashSessionManager implements SessionManager
  +public class HashSessionManager extends AbstractSessionManager
   {
       /* ------------------------------------------------------------ */
  -    public final static int __distantFuture = 60*60*24*7*52*20;
  -    private static long __nextSessionId = System.currentTimeMillis();
  -    
  -    /* ------------------------------------------------------------ */
  -    // Setting of max inactive interval for new sessions
  -    // -1 means no timeout
  -    private int _dftMaxIdleSecs = -1;
  -    private SessionScavenger _scavenger = null;
  -    private Map _sessions;
  -    private int _scavengePeriodMs = 30000;
  -    private ServletHandler _handler;
  -
  -    private ArrayList _sessionListeners=new ArrayList();
  -    private ArrayList _sessionAttributeListeners=new ArrayList();
  -    
  -    
  -    /* ------------------------------------------------------------ */
  -    protected HashSessionManager(ServletHandler handler)
  -    {
  -        _handler=handler;
  -    }
  -
  -    /* ------------------------------------------------------------ */
  -    /**
  -     * @param id
  -     * @return
  -     */
  -    public HttpSession getHttpSession(String id)
  -    {
  -        HttpSession s = (HttpSession)_sessions.get(id);
  -        return s;
  -    }
  -
  -    /* ------------------------------------------------------------ */
  -    public synchronized HttpSession newHttpSession()
  -    {
  -        Session session = new Session();
  -        session.setMaxInactiveInterval(_dftMaxIdleSecs);
  -        _sessions.put(session.getId(),session);
  -
  -        for(int i=0;i<_sessionListeners.size();i++)
  -            ((HttpSessionListener)_sessionListeners.get(i))
  -                .sessionCreated(session.getHttpSessionEvent());
  -        return session;
  -    }
  -
  -    /* ------------------------------------------------------------ */
  -    /** 
  -     * @param seconds 
  -     */
  -    public synchronized void setMaxInactiveInterval(int seconds)
  +    public HashSessionManager()
       {
  -        _dftMaxIdleSecs = seconds;
  -        if (_dftMaxIdleSecs>0 && _scavengePeriodMs>_dftMaxIdleSecs*100)
  -            setScavangePeriod((_dftMaxIdleSecs+9)/10);
  +        super();
       }
       
       /* ------------------------------------------------------------ */
  -    /** 
  -     * @param seconds 
  -     */
  -    public synchronized void setScavangePeriod(int seconds)
  +    public HashSessionManager(Random random)
       {
  -        if (seconds==0)
  -            seconds=60;
  -        
  -        int old_period=_scavengePeriodMs;
  -        int period = seconds*1000;
  -        if (period>60000)
  -            period=60000;
  -        if (period<1000)
  -            period=1000;
  -        
  -        // Start the session scavenger if we haven't already
  -        if (_scavenger == null && period>0)
  -            _scavenger = new SessionScavenger();
  -        
  -        if (period!=old_period)
  -        {
  -            _scavengePeriodMs=period;
  -            _scavenger.interrupt();
  -        }
  +        super(random);
       }
  -    
  -    
  -    /* ------------------------------------------------------------ */
  -    public void addEventListener(EventListener listener)
  -        throws IllegalArgumentException
  -    {
  -        boolean known =false;
  -        if (listener instanceof HttpSessionAttributeListener)
  -        {
  -            _sessionAttributeListeners.add(listener);
  -            known=true;
  -        }
  -        if (listener instanceof HttpSessionListener)
  -        {
  -            _sessionListeners.add(listener);
  -            known=true;
  -        }
   
  -        if (!known)
  -            throw new IllegalArgumentException("Unknown listener "+listener);
  -    }
  -    
  -    /* ------------------------------------------------------------ */
  -    public void removeEventListener(EventListener listener)
  -    {
  -        boolean known =false;
  -        if (listener instanceof HttpSessionAttributeListener)
  -            _sessionAttributeListeners.remove(listener);
  -        if (listener instanceof HttpSessionListener)
  -            _sessionListeners.remove(listener);
  -    }
  -    
  -    /* ------------------------------------------------------------ */
  -    public boolean isStarted()
  -    {
  -        return _scavenger!=null;
  -    }
  -    
  -    /* ------------------------------------------------------------ */
  -    public void start()
  -        throws Exception
  -    {
  -        if (_sessions==null)
  -            _sessions=new HashMap();
  -        
  -        // Start the session scavenger if we haven't already
  -        if (_scavenger == null)
  -            _scavenger = new SessionScavenger();
  -    }
  -    
       /* ------------------------------------------------------------ */
  -    public void stop()
  -    {
  -        // Invalidate all sessions to cause unbind events
  -        ArrayList sessions = new ArrayList(_sessions.values());
  -        for (Iterator i = sessions.iterator(); i.hasNext(); )
  -        {
  -            Session session = (Session)i.next();
  -            session.invalidate();
  -        }
  -        _sessions.clear();
  -        
  -        // stop the scavenger
  -        SessionScavenger scavenger = _scavenger;
  -        _scavenger=null;
  -        if (scavenger!=null)
  -            scavenger.interrupt();
  -    }
  -    
  -    /* -------------------------------------------------------------- */
  -    /** Find sessions that have timed out and invalidate them.
  -     *  This runs in the SessionScavenger thread.
  -     */
  -    private void scavenge()
  +    protected AbstractSessionManager.Session newSession()
       {
  -        long now = System.currentTimeMillis();
  -
  -        // Since Hashtable enumeration is not safe over deletes,
  -        // we build a list of stale sessions, then go back and invalidate them
  -        LazyList stale=null;
  -
  -        // For each session
  -        try
  -        {
  -            for (Iterator i = _sessions.values().iterator(); i.hasNext(); )
  -            {
  -                Session session = (Session)i.next();
  -                long idleTime = session._maxIdleMs;
  -                if (idleTime > 0 && session._accessed + idleTime < now) {
  -                    // Found a stale session, add it to the list
  -                    stale=LazyList.add(stale,session);
  -                }
  -            }
  -        }
  -        catch(ConcurrentModificationException e)
  -        {
  -            Code.ignore(e);
  -            // Oops something changed while we were looking.
  -            // Lock the context and try again.
  -            // Set our priority high while we have the sessions locked
  -            int oldPriority = Thread.currentThread().getPriority();
  -            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  -            try
  -            {
  -                synchronized(this)
  -                {
  -                    stale=null;
  -                    scavenge();
  -                }
  -            }
  -            finally {Thread.currentThread().setPriority(oldPriority);}
  -        }
  -
  -        // Remove the stale sessions
  -        for (int i = LazyList.size(stale); i-->0;)
  -        {
  -            ((Session)LazyList.get(stale,i)).invalidate();
  -        }
  +        return new Session();
       }
       
  -
  -    /* ------------------------------------------------------------ */
       /* ------------------------------------------------------------ */
  -    /* -------------------------------------------------------------- */
  -    /** SessionScavenger is a background thread that kills off old sessions */
  -    class SessionScavenger extends Thread
  -    {
  -        public void run()
  -        {
  -            int period=-1;
  -            try{
  -                while (isStarted())
  -                {
  -                    try {
  -                        if (period!=_scavengePeriodMs)
  -                        {
  -                            Log.event("Session scavenger period = 
"+_scavengePeriodMs/1000+"s");
  -                            period=_scavengePeriodMs;
  -                        }
  -                        sleep(period>1000?period:1000);
  -                        HashSessionManager.this.scavenge();
  -                    }
  -                    catch (InterruptedException ex){continue;}
  -                    catch (Error e) {Code.warning(e);}
  -                    catch (Exception e) {Code.warning(e);}
  -                }
  -            }
  -            finally
  -            {
  -                HashSessionManager.this._scavenger=null;
  -            }
  -        }
  -
  -        SessionScavenger()
  -        {
  -            super("SessionScavenger");
  -            setDaemon(true);
  -            this.start();
  -        }
  -
  -    }   // SessionScavenger
  -    
       /* ------------------------------------------------------------ */
       /* ------------------------------------------------------------ */
  -    /* ------------------------------------------------------------ */
  -    protected class Session
  -        implements SessionManager.Session
  +    protected class Session extends AbstractSessionManager.Session
       {
  -        HashMap _values = new HashMap(11);
  -        boolean _invalid=false;
  -        boolean _newSession=true;
  -        long _created=System.currentTimeMillis();
  -        long _accessed=_created;
  -        long _maxIdleMs = _dftMaxIdleSecs*1000;
  -        String _id;
  -        HttpSessionEvent _event;
  -
           /* ------------------------------------------------------------- */
           protected Session()
           {
  -            synchronized(Session.class)
  -            {
  -                do
  -                {
  -                    long newId = __nextSessionId;
  -                    __nextSessionId+=this.hashCode();
  -                    if (newId<0)newId=-newId;
  -                    this._id=Long.toString(newId,30+(int)(_created%7));
  -                }
  -                while (_sessions.containsKey(this._id));
  -            }
  -            if (_dftMaxIdleSecs>=0)
  -                _maxIdleMs=_dftMaxIdleSecs*1000;
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        HttpSessionEvent getHttpSessionEvent()
  -        {
  -            if (_event==null)
  -                _event=new HttpSessionEvent(this);
  -            return _event;
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        public void access()
  -        {
  -            _newSession=false;
  -            _accessed=System.currentTimeMillis();
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        public boolean isValid()
  -        {
  -            return !_invalid;
  -        }
  -        
  -        /* ------------------------------------------------------------ */
  -        public ServletContext getServletContext()
  -        {
  -            return _handler.getServletContext();
  -        }
  -        
  -        /* ------------------------------------------------------------- */
  -        public String getId()
  -            throws IllegalStateException
  -        {
  -            return _id;
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public long getCreationTime()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return _created;
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public long getLastAccessedTime()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return _accessed;
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public int getMaxInactiveInterval()
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return (int)(_maxIdleMs / 1000);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /**
  -         * @deprecated
  -         */
  -        public HttpSessionContext getSessionContext()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return SessionContext.NULL_IMPL;
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public void setMaxInactiveInterval(int secs)
  -        {
  -            _maxIdleMs = (long)secs * 1000;
  -            if (_maxIdleMs>0 && (_maxIdleMs/10)<_scavengePeriodMs)
  -                HashSessionManager.this.setScavangePeriod((secs+9)/10);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public synchronized void invalidate()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            
  -            Iterator iter = _values.keySet().iterator();
  -            while (iter.hasNext())
  -            {
  -                String key = (String)iter.next();
  -                Object value = _values.get(key);
  -                iter.remove();
  -                unbindValue(key, value);
  -
  -                if (_sessionAttributeListeners.size()>0)
  -                {
  -                    HttpSessionBindingEvent event =
  -                        new HttpSessionBindingEvent(this,key,value);
  -                    
  -                    for(int i=0;i<_sessionAttributeListeners.size();i++)
  -                        ((HttpSessionAttributeListener)
  -                         _sessionAttributeListeners.get(i))
  -                            .attributeRemoved(event);
  -                }
  -            }
  -            synchronized (HashSessionManager.this)
  -            {
  -                _invalid=true;
  -                _sessions.remove(_id);
  -                for(int i=0;i<_sessionListeners.size();i++)
  -                    ((HttpSessionListener)_sessionListeners.get(i)).
  -                        sessionDestroyed(getHttpSessionEvent());       
  -            }
  -             
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        public boolean isNew()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return _newSession;
  -        }
  -
  -
  -        /* ------------------------------------------------------------ */
  -        public Object getAttribute(String name)
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return _values.get(name);
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        public Enumeration getAttributeNames()
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            return Collections.enumeration(_values.keySet());
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        public synchronized void setAttribute(String name, Object value)
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            Object oldValue = _values.put(name,value);
  -
  -            if (value==null || !value.equals(oldValue))
  -            {
  -                unbindValue(name, oldValue);
  -                bindValue(name, value);
  -                
  -                if (_sessionAttributeListeners.size()>0)
  -                {
  -                    HttpSessionBindingEvent event =
  -                        new HttpSessionBindingEvent(this,name,
  -                                                    oldValue==null?value:oldValue);
  -                    
  -                    for(int i=0;i<_sessionAttributeListeners.size();i++)
  -                    {
  -                        HttpSessionAttributeListener l =
  -                            (HttpSessionAttributeListener)
  -                            _sessionAttributeListeners.get(i);
  -                        
  -                        if (oldValue==null)
  -                            l.attributeAdded(event);
  -                        else if (value==null)
  -                            l.attributeRemoved(event);
  -                        else
  -                            l.attributeReplaced(event);
  -                    }
  -                }
  -            }
  -        }
  -
  -        /* ------------------------------------------------------------ */
  -        public synchronized void removeAttribute(String name)
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            Object old=_values.remove(name);
  -            if (old!=null)
  -            {
  -                unbindValue(name, old);
  -                if (_sessionAttributeListeners.size()>0)
  -                {
  -                    HttpSessionBindingEvent event =
  -                        new HttpSessionBindingEvent(this,name,old);
  -                    
  -                    for(int i=0;i<_sessionAttributeListeners.size();i++)
  -                    {
  -                        HttpSessionAttributeListener l =
  -                            (HttpSessionAttributeListener)
  -                            _sessionAttributeListeners.get(i);
  -                        l.attributeRemoved(event);
  -                    }
  -                }
  -            }
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /**
  -         * @deprecated       As of Version 2.2, this method is
  -         *           replaced by {@link #getAttribute}
  -         */
  -        public Object getValue(String name)
  -            throws IllegalStateException
  -        {
  -            return getAttribute(name);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /**
  -         * @deprecated       As of Version 2.2, this method is
  -         *           replaced by {@link #getAttributeNames}
  -         */
  -        public synchronized String[] getValueNames()
  -            throws IllegalStateException
  -        {
  -            if (_invalid) throw new IllegalStateException();
  -            String[] a = new String[_values.size()];
  -            return (String[])_values.keySet().toArray(a);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /**
  -         * @deprecated       As of Version 2.2, this method is
  -         *           replaced by {@link #setAttribute}
  -         */
  -        public void putValue(java.lang.String name,
  -                             java.lang.Object value)
  -            throws IllegalStateException
  -        {
  -            setAttribute(name,value);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /**
  -         * @deprecated       As of Version 2.2, this method is
  -         *           replaced by {@link #removeAttribute}
  -         */
  -        public void removeValue(java.lang.String name)
  -            throws IllegalStateException
  -        {
  -            removeAttribute(name);
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /** If value implements HttpSessionBindingListener, call valueBound() */
  -        private void bindValue(java.lang.String name, Object value)
  -        {
  -            if (value!=null && value instanceof HttpSessionBindingListener)
  -                ((HttpSessionBindingListener)value)
  -                    .valueBound(new HttpSessionBindingEvent(this,name));            
  -        }
  -
  -        /* ------------------------------------------------------------- */
  -        /** If value implements HttpSessionBindingListener, call valueUnbound() */
  -        private void unbindValue(java.lang.String name, Object value)
  -        {
  -            if (value!=null && value instanceof HttpSessionBindingListener)
  -                ((HttpSessionBindingListener)value)
  -                    .valueUnbound(new HttpSessionBindingEvent(this,name));
  +            super(new HashMap(11));
           }
       }
  +    
   }
  
  
  
  1.2       +0 -0      contrib/jetty/src/main/org/mortbay/jetty/servlet/Holder.java
  
  Index: Holder.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/Holder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Holder.java       17 Jan 2002 01:23:21 -0000      1.1
  +++ Holder.java       10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: Holder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: Holder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -20,7 +20,7 @@
   
   /* --------------------------------------------------------------------- */
   /** 
  - * @version $Id: Holder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: Holder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins
    */
   public class Holder
  
  
  
  1.2       +16 -6     
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHandler.java
  
  Index: ServletHandler.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHandler.java       17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletHandler.java       10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: ServletHandler.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletHandler.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -66,7 +66,11 @@
    * This handler maps requests to servlets that implement the
    * javax.servlet.http.HttpServlet API.
    *
  - * @version $Id: ServletHandler.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * If a SessionManager is not added to the handler before it is
  + * initialized, then a HashSessionManager with a standard
  + * java.util.Random generator is created.
  + * 
  + * @version $Id: ServletHandler.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins
    */
   public class ServletHandler
  @@ -104,9 +108,7 @@
       /* ------------------------------------------------------------ */
       public void initialize(HttpContext context)
       {
  -        if (_sessionManager==null)
  -            _sessionManager = new HashSessionManager(this);
  -        
  +        SessionManager sessionManager=getSessionManager();
           super.initialize(context);
           if (context instanceof ServletHttpContext)
           {
  @@ -114,6 +116,7 @@
               servletHttpContext.setServletHandler(this);
               servletHttpContext.setServletContext(_context);
           }
  +        sessionManager.initialize(this);
       }
   
       /* ------------------------------------------------------------ */
  @@ -126,7 +129,7 @@
       public SessionManager getSessionManager()
       {
           if (_sessionManager==null)
  -            _sessionManager = new HashSessionManager(this);
  +            _sessionManager = new HashSessionManager();
           return _sessionManager;
       }
       
  @@ -253,6 +256,13 @@
                                             String servletName)
       {
           ServletHolder holder =(ServletHolder)_nameMap.get(servletName);
  +
  +        if (!pathSpec.startsWith("/") && !pathSpec.startsWith("*"))
  +        {
  +            Code.warning("pathSpec must start with '/' or '*' : "+pathSpec);
  +            pathSpec="/"+pathSpec;
  +        }
  +        
           if (holder==null)
               throw new IllegalArgumentException("Unknown servlet: "+servletName);
           _servletMap.put(pathSpec,holder);
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHolder.java
  
  Index: ServletHolder.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHolder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHolder.java        17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletHolder.java        10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: ServletHolder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletHolder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -33,7 +33,7 @@
    * requested.
    *
    * @see org.mortbay.jetty.ServletHandler
  - * @version $Id: ServletHolder.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: ServletHolder.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins
    */
   public class ServletHolder extends Holder
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpContext.java
  
  Index: ServletHttpContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHttpContext.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletHttpContext.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2001 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletHttpContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletHttpContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  @@ -14,7 +14,7 @@
   /** ServletHttpContext.
    * Extends HttpContext with conveniance methods for adding servlets.
    * Enforces a single ServletHandler per context.
  - * @version $Id: ServletHttpContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: ServletHttpContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class ServletHttpContext extends HttpContext
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpRequest.java
  
  Index: ServletHttpRequest.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHttpRequest.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletHttpRequest.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletHttpRequest.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletHttpRequest.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   
  @@ -56,7 +56,7 @@
    * be operated on by multiple threads, then higher level
    * synchronizations may be required.
    * 
  - * @version $Id: ServletHttpRequest.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: ServletHttpRequest.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class ServletHttpRequest
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpResponse.java
  
  Index: ServletHttpResponse.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletHttpResponse.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletHttpResponse.java  17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletHttpResponse.java  10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletHttpResponse.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletHttpResponse.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  @@ -37,7 +37,7 @@
    * be operated on by multiple threads, then higher level
    * synchronizations may be required.
    *
  - * @version $Id: ServletHttpResponse.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: ServletHttpResponse.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class ServletHttpResponse implements HttpServletResponse
  
  
  
  1.2       +0 -0      contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletIn.java
  
  Index: ServletIn.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletIn.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletIn.java    17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletIn.java    10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletIn.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletIn.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  
  
  
  1.2       +0 -0      contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletOut.java
  
  Index: ServletOut.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletOut.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletOut.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletOut.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletOut.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletOut.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  
  
  
  1.2       +0 -0      contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletSSL.java
  
  Index: ServletSSL.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletSSL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletSSL.java   17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletSSL.java   10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2001 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletSSL.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletSSL.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  @@ -12,7 +12,7 @@
    *
    * <p> Used by the SSL listener classes.
    *
  - * @version $Id: ServletSSL.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: ServletSSL.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Brett Sealey
    */
   public class ServletSSL
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletWriter.java
  
  Index: ServletWriter.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/ServletWriter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletWriter.java        17 Jan 2002 01:23:21 -0000      1.1
  +++ ServletWriter.java        10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: ServletWriter.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: ServletWriter.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  @@ -21,7 +21,7 @@
    * This writer can be disabled.
    * It is crying out for optimization.
    *
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    * @author Greg Wilkins (gregw)
    */
   class ServletWriter extends PrintWriter
  
  
  
  1.2       +0 -0      
contrib/jetty/src/main/org/mortbay/jetty/servlet/SessionContext.java
  
  Index: SessionContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/SessionContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SessionContext.java       17 Jan 2002 01:23:21 -0000      1.1
  +++ SessionContext.java       10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: SessionContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: SessionContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -12,7 +12,7 @@
   /* ------------------------------------------------------------ */
   /** 
    * Null returning implementation of HttpSessionContext
  - * @version $Id: SessionContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: SessionContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class SessionContext implements HttpSessionContext
  
  
  
  1.2       +5 -2      
contrib/jetty/src/main/org/mortbay/jetty/servlet/SessionManager.java
  
  Index: SessionManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/SessionManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SessionManager.java       17 Jan 2002 01:23:21 -0000      1.1
  +++ SessionManager.java       10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ===========================================================================
   // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  -// $Id: SessionManager.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: SessionManager.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ---------------------------------------------------------------------------
   
   package org.mortbay.jetty.servlet;
  @@ -13,7 +13,7 @@
   /* --------------------------------------------------------------------- */
   /**
    *
  - * @version $Id: SessionManager.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: SessionManager.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins
    */
   public interface SessionManager extends LifeCycle
  @@ -21,6 +21,9 @@
       /* ------------------------------------------------------------ */
       public final static String __SessionId  = "jsessionid";
       public final static String __SessionUrlPrefix = ";"+__SessionId+"=";
  +
  +    /* ------------------------------------------------------------ */
  +    public void initialize(ServletHandler handler);
       
       /* ------------------------------------------------------------ */
       public HttpSession getHttpSession(String id);
  
  
  
  1.2       +10 -5     
contrib/jetty/src/main/org/mortbay/jetty/servlet/WebApplicationContext.java
  
  Index: WebApplicationContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/mortbay/jetty/servlet/WebApplicationContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebApplicationContext.java        17 Jan 2002 01:23:21 -0000      1.1
  +++ WebApplicationContext.java        10 Feb 2002 17:57:44 -0000      1.2
  @@ -1,6 +1,6 @@
   // ========================================================================
   // Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
  -// $Id: WebApplicationContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  +// $Id: WebApplicationContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
   // ========================================================================
   
   package org.mortbay.jetty.servlet;
  @@ -69,7 +69,7 @@
    * after the servlet handler within the context.
    * </UL>
    *
  - * @version $Id: WebApplicationContext.java,v 1.1 2002/01/17 01:23:21 olegnitz Exp $
  + * @version $Id: WebApplicationContext.java,v 1.2 2002/02/10 17:57:44 olegnitz Exp $
    * @author Greg Wilkins (gregw)
    */
   public class WebApplicationContext extends ServletHttpContext
  @@ -194,7 +194,9 @@
           {
               // Set dir or WAR
               _webApp = Resource.newResource(_war);
  -            if (_webApp.exists() && !_webApp.isDirectory())
  +            if (_webApp.exists() &&
  +                !_webApp.isDirectory() &&
  +                !_webApp.toString().startsWith("jar:"))
               {
                   _webApp = Resource.newResource("jar:"+_webApp+"!/");
                   if (_webApp.exists())
  @@ -1024,13 +1026,16 @@
           XmlParser.Node auths=node.get("auth-constraint");
           if (auths!=null)
           {
  +            scBase.setAuthenticate(true);
  +            // auth-constraint
               Iterator iter= auths.iterator("role-name");
               while(iter.hasNext())
               {
  -                XmlParser.Node role=(XmlParser.Node)iter.next();
  -                scBase.addRole(role.toString(false,true));
  +                String role=((XmlParser.Node)iter.next()).toString(false,true);
  +                scBase.addRole(role);
               }
           }
  +        
           
           XmlParser.Node data=node.get("user-data-constraint");
           if (data!=null)
  
  
  
  1.1                  
contrib/jetty/src/main/org/mortbay/jetty/servlet/AbstractSessionManager.java
  
  Index: AbstractSessionManager.java
  ===================================================================
  // ===========================================================================
  // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
  // $Id: AbstractSessionManager.java,v 1.1 2002/02/10 17:57:44 olegnitz Exp $
  // ---------------------------------------------------------------------------
  
  package org.mortbay.jetty.servlet;
  
  import java.util.AbstractCollection;
  import java.util.AbstractList;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.ConcurrentModificationException;
  import java.util.Enumeration;
  import java.util.EventListener;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpSessionAttributeListener;
  import javax.servlet.http.HttpSessionBindingEvent;
  import javax.servlet.http.HttpSessionBindingListener;
  import javax.servlet.http.HttpSessionContext;
  import javax.servlet.http.HttpSessionEvent;
  import javax.servlet.http.HttpSessionListener;
  import org.mortbay.util.Log;
  import org.mortbay.util.Code;
  import org.mortbay.util.LazyList;
  import java.util.Random;
  
  
  /* ------------------------------------------------------------ */
  /** An Abstract implementation of SessionManager.
   * The partial implementation of SessionManager interface provides
   * the majority of the handling required to implement a
   * SessionManager.  Concrete implementations of SessionManager based
   * on AbstractSessionManager need only implement the newSession method
   * to return a specialized version of the Session inner class that
   * provides an attribute Map.
   *
   * @version $Id: AbstractSessionManager.java,v 1.1 2002/02/10 17:57:44 olegnitz Exp $
   * @author Greg Wilkins (gregw)
   */
  public abstract class AbstractSessionManager implements SessionManager
  {
      /* ------------------------------------------------------------ */
      public final static int __distantFuture = 60*60*24*7*52*20;
      
      /* ------------------------------------------------------------ */
      // Setting of max inactive interval for new sessions
      // -1 means no timeout
      private int _dftMaxIdleSecs = -1;
      private SessionScavenger _scavenger = null;
      private Map _sessions;
      private int _scavengePeriodMs = 30000;
      private ServletHandler _handler;
  
      private ArrayList _sessionListeners=new ArrayList();
      private ArrayList _sessionAttributeListeners=new ArrayList();
      private Random _random;
      
      /* ------------------------------------------------------------ */
      public AbstractSessionManager()
      {
          this(null);
      }
      
      /* ------------------------------------------------------------ */
      public AbstractSessionManager(Random random)
      {
          _random=random;
      }
  
      /* ------------------------------------------------------------ */
      public void initialize(ServletHandler handler)
      {
          _handler=handler;
      }
      
      /* ------------------------------------------------------------ */
      private synchronized String newSessionId(long created)
      {
          String id=null;
          do
          {
              long r = _random.nextLong();
              if (r<0)r=-r;
              id=Long.toString(r,30+(int)(created%7));
          }
          while (_sessions.containsKey(id));
          return id;
      }
      
      /* ------------------------------------------------------------ */
      /**
       * @param id
       * @return
       */
      public HttpSession getHttpSession(String id)
      {
          HttpSession s = (HttpSession)_sessions.get(id);
          return s;
      }
  
      /* ------------------------------------------------------------ */
      public synchronized HttpSession newHttpSession()
      {
          Session session = newSession();
          session.setMaxInactiveInterval(_dftMaxIdleSecs);
          _sessions.put(session.getId(),session);
  
          for(int i=0;i<_sessionListeners.size();i++)
              ((HttpSessionListener)_sessionListeners.get(i))
                  .sessionCreated(session.getHttpSessionEvent());
          return session;
      }
  
      /* ------------------------------------------------------------ */
      protected abstract Session newSession();
      
      /* ------------------------------------------------------------ */
      /** 
       * @param seconds 
       */
      public synchronized void setMaxInactiveInterval(int seconds)
      {
          _dftMaxIdleSecs = seconds;
          if (_dftMaxIdleSecs>0 && _scavengePeriodMs>_dftMaxIdleSecs*100)
              setScavangePeriod((_dftMaxIdleSecs+9)/10);
      }
      
      /* ------------------------------------------------------------ */
      /** 
       * @param seconds 
       */
      public synchronized void setScavangePeriod(int seconds)
      {
          if (seconds==0)
              seconds=60;
          
          int old_period=_scavengePeriodMs;
          int period = seconds*1000;
          if (period>60000)
              period=60000;
          if (period<1000)
              period=1000;
          
          // Start the session scavenger if we haven't already
          if (_scavenger == null && period>0)
              _scavenger = new SessionScavenger();
          
          if (period!=old_period)
          {
              _scavengePeriodMs=period;
              _scavenger.interrupt();
          }
      }
      
      
      /* ------------------------------------------------------------ */
      public void addEventListener(EventListener listener)
          throws IllegalArgumentException
      {
          boolean known =false;
          if (listener instanceof HttpSessionAttributeListener)
          {
              _sessionAttributeListeners.add(listener);
              known=true;
          }
          if (listener instanceof HttpSessionListener)
          {
              _sessionListeners.add(listener);
              known=true;
          }
  
          if (!known)
              throw new IllegalArgumentException("Unknown listener "+listener);
      }
      
      /* ------------------------------------------------------------ */
      public void removeEventListener(EventListener listener)
      {
          boolean known =false;
          if (listener instanceof HttpSessionAttributeListener)
              _sessionAttributeListeners.remove(listener);
          if (listener instanceof HttpSessionListener)
              _sessionListeners.remove(listener);
      }
      
      /* ------------------------------------------------------------ */
      public boolean isStarted()
      {
          return _scavenger!=null;
      }
      
      /* ------------------------------------------------------------ */
      public void start()
          throws Exception
      {
          Log.event("Initializing random session key: "+_random);
          if (_random==null)
              _random=new Random();
          _random.nextLong();
          
          if (_sessions==null)
              _sessions=new HashMap();
          
          // Start the session scavenger if we haven't already
          if (_scavenger == null)
              _scavenger = new SessionScavenger();
      }
      
      /* ------------------------------------------------------------ */
      public void stop()
      {
          // Invalidate all sessions to cause unbind events
          ArrayList sessions = new ArrayList(_sessions.values());
          for (Iterator i = sessions.iterator(); i.hasNext(); )
          {
              Session session = (Session)i.next();
              session.invalidate();
          }
          _sessions.clear();
          
          // stop the scavenger
          SessionScavenger scavenger = _scavenger;
          _scavenger=null;
          if (scavenger!=null)
              scavenger.interrupt();
      }
      
      /* -------------------------------------------------------------- */
      /** Find sessions that have timed out and invalidate them.
       *  This runs in the SessionScavenger thread.
       */
      private void scavenge()
      {
          long now = System.currentTimeMillis();
  
          // Since Hashtable enumeration is not safe over deletes,
          // we build a list of stale sessions, then go back and invalidate them
          LazyList stale=null;
  
          // For each session
          try
          {
              for (Iterator i = _sessions.values().iterator(); i.hasNext(); )
              {
                  Session session = (Session)i.next();
                  long idleTime = session._maxIdleMs;
                  if (idleTime > 0 && session._accessed + idleTime < now) {
                      // Found a stale session, add it to the list
                      stale=LazyList.add(stale,session);
                  }
              }
          }
          catch(ConcurrentModificationException e)
          {
              Code.ignore(e);
              // Oops something changed while we were looking.
              // Lock the context and try again.
              // Set our priority high while we have the sessions locked
              int oldPriority = Thread.currentThread().getPriority();
              Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
              try
              {
                  synchronized(this)
                  {
                      stale=null;
                      scavenge();
                  }
              }
              finally {Thread.currentThread().setPriority(oldPriority);}
          }
  
          // Remove the stale sessions
          for (int i = LazyList.size(stale); i-->0;)
          {
              ((Session)LazyList.get(stale,i)).invalidate();
          }
      }
      
  
      /* ------------------------------------------------------------ */
      /* ------------------------------------------------------------ */
      /* -------------------------------------------------------------- */
      /** SessionScavenger is a background thread that kills off old sessions */
      class SessionScavenger extends Thread
      {
          public void run()
          {
              int period=-1;
              try{
                  while (isStarted())
                  {
                      try {
                          if (period!=_scavengePeriodMs)
                          {
                              Log.event("Session scavenger period = 
"+_scavengePeriodMs/1000+"s");
                              period=_scavengePeriodMs;
                          }
                          sleep(period>1000?period:1000);
                          AbstractSessionManager.this.scavenge();
                      }
                      catch (InterruptedException ex){continue;}
                      catch (Error e) {Code.warning(e);}
                      catch (Exception e) {Code.warning(e);}
                  }
              }
              finally
              {
                  AbstractSessionManager.this._scavenger=null;
              }
          }
  
          SessionScavenger()
          {
              super("SessionScavenger");
              setDaemon(true);
              this.start();
          }
  
      }   // SessionScavenger
  
  
      
      /* ------------------------------------------------------------ */
      /* ------------------------------------------------------------ */
      /* ------------------------------------------------------------ */
      public abstract class Session implements SessionManager.Session
      {
          Map _values;
          boolean _invalid=false;
          boolean _newSession=true;
          long _created=System.currentTimeMillis();
          long _accessed=_created;
          long _maxIdleMs = _dftMaxIdleSecs*1000;
          String _id;
          HttpSessionEvent _event;
  
          /* ------------------------------------------------------------- */
          protected Session(Map values)
          {
              _values=values;
              _id=newSessionId(_created);
              if (_dftMaxIdleSecs>=0)
                  _maxIdleMs=_dftMaxIdleSecs*1000;
          }
  
          /* ------------------------------------------------------------ */
          HttpSessionEvent getHttpSessionEvent()
          {
              if (_event==null)
                  _event=new HttpSessionEvent(this);
              return _event;
          }
  
          /* ------------------------------------------------------------ */
          public void access()
          {
              _newSession=false;
              _accessed=System.currentTimeMillis();
          }
  
          /* ------------------------------------------------------------ */
          public boolean isValid()
          {
              return !_invalid;
          }
          
          /* ------------------------------------------------------------ */
          public ServletContext getServletContext()
          {
              return _handler.getServletContext();
          }
          
          /* ------------------------------------------------------------- */
          public String getId()
              throws IllegalStateException
          {
              return _id;
          }
  
          /* ------------------------------------------------------------- */
          public long getCreationTime()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              return _created;
          }
  
          /* ------------------------------------------------------------- */
          public long getLastAccessedTime()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              return _accessed;
          }
  
          /* ------------------------------------------------------------- */
          public int getMaxInactiveInterval()
          {
              if (_invalid) throw new IllegalStateException();
              return (int)(_maxIdleMs / 1000);
          }
  
          /* ------------------------------------------------------------- */
          /**
           * @deprecated
           */
          public HttpSessionContext getSessionContext()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              return SessionContext.NULL_IMPL;
          }
  
          /* ------------------------------------------------------------- */
          public void setMaxInactiveInterval(int secs)
          {
              _maxIdleMs = (long)secs * 1000;
              if (_maxIdleMs>0 && (_maxIdleMs/10)<_scavengePeriodMs)
                  AbstractSessionManager.this.setScavangePeriod((secs+9)/10);
          }
  
          /* ------------------------------------------------------------- */
          public synchronized void invalidate()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              
              Iterator iter = _values.keySet().iterator();
              while (iter.hasNext())
              {
                  String key = (String)iter.next();
                  Object value = _values.get(key);
                  iter.remove();
                  unbindValue(key, value);
  
                  if (_sessionAttributeListeners.size()>0)
                  {
                      HttpSessionBindingEvent event =
                          new HttpSessionBindingEvent(this,key,value);
                      
                      for(int i=0;i<_sessionAttributeListeners.size();i++)
                          ((HttpSessionAttributeListener)
                           _sessionAttributeListeners.get(i))
                              .attributeRemoved(event);
                  }
              }
              synchronized (AbstractSessionManager.this)
              {
                  _invalid=true;
                  _sessions.remove(_id);
                  for(int i=0;i<_sessionListeners.size();i++)
                      ((HttpSessionListener)_sessionListeners.get(i)).
                          sessionDestroyed(getHttpSessionEvent());       
              }
               
          }
  
          /* ------------------------------------------------------------- */
          public boolean isNew()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              return _newSession;
          }
  
  
          /* ------------------------------------------------------------ */
          public Object getAttribute(String name)
          {
              if (_invalid) throw new IllegalStateException();
              return _values.get(name);
          }
  
          /* ------------------------------------------------------------ */
          public Enumeration getAttributeNames()
          {
              if (_invalid) throw new IllegalStateException();
              return Collections.enumeration(_values.keySet());
          }
  
          /* ------------------------------------------------------------ */
          public synchronized void setAttribute(String name, Object value)
          {
              if (_invalid) throw new IllegalStateException();
              Object oldValue = _values.put(name,value);
  
              if (value==null || !value.equals(oldValue))
              {
                  unbindValue(name, oldValue);
                  bindValue(name, value);
                  
                  if (_sessionAttributeListeners.size()>0)
                  {
                      HttpSessionBindingEvent event =
                          new HttpSessionBindingEvent(this,name,
                                                      oldValue==null?value:oldValue);
                      
                      for(int i=0;i<_sessionAttributeListeners.size();i++)
                      {
                          HttpSessionAttributeListener l =
                              (HttpSessionAttributeListener)
                              _sessionAttributeListeners.get(i);
                          
                          if (oldValue==null)
                              l.attributeAdded(event);
                          else if (value==null)
                              l.attributeRemoved(event);
                          else
                              l.attributeReplaced(event);
                      }
                  }
              }
          }
  
          /* ------------------------------------------------------------ */
          public synchronized void removeAttribute(String name)
          {
              if (_invalid) throw new IllegalStateException();
              Object old=_values.remove(name);
              if (old!=null)
              {
                  unbindValue(name, old);
                  if (_sessionAttributeListeners.size()>0)
                  {
                      HttpSessionBindingEvent event =
                          new HttpSessionBindingEvent(this,name,old);
                      
                      for(int i=0;i<_sessionAttributeListeners.size();i++)
                      {
                          HttpSessionAttributeListener l =
                              (HttpSessionAttributeListener)
                              _sessionAttributeListeners.get(i);
                          l.attributeRemoved(event);
                      }
                  }
              }
          }
  
          /* ------------------------------------------------------------- */
          /**
           * @deprecated        As of Version 2.2, this method is
           *            replaced by {@link #getAttribute}
           */
          public Object getValue(String name)
              throws IllegalStateException
          {
              return getAttribute(name);
          }
  
          /* ------------------------------------------------------------- */
          /**
           * @deprecated        As of Version 2.2, this method is
           *            replaced by {@link #getAttributeNames}
           */
          public synchronized String[] getValueNames()
              throws IllegalStateException
          {
              if (_invalid) throw new IllegalStateException();
              String[] a = new String[_values.size()];
              return (String[])_values.keySet().toArray(a);
          }
  
          /* ------------------------------------------------------------- */
          /**
           * @deprecated        As of Version 2.2, this method is
           *            replaced by {@link #setAttribute}
           */
          public void putValue(java.lang.String name,
                               java.lang.Object value)
              throws IllegalStateException
          {
              setAttribute(name,value);
          }
  
          /* ------------------------------------------------------------- */
          /**
           * @deprecated        As of Version 2.2, this method is
           *            replaced by {@link #removeAttribute}
           */
          public void removeValue(java.lang.String name)
              throws IllegalStateException
          {
              removeAttribute(name);
          }
  
          /* ------------------------------------------------------------- */
          /** If value implements HttpSessionBindingListener, call valueBound() */
          private void bindValue(java.lang.String name, Object value)
          {
              if (value!=null && value instanceof HttpSessionBindingListener)
                  ((HttpSessionBindingListener)value)
                      .valueBound(new HttpSessionBindingEvent(this,name));            
          }
  
          /* ------------------------------------------------------------- */
          /** If value implements HttpSessionBindingListener, call valueUnbound() */
          private void unbindValue(java.lang.String name, Object value)
          {
              if (value!=null && value instanceof HttpSessionBindingListener)
                  ((HttpSessionBindingListener)value)
                      .valueUnbound(new HttpSessionBindingEvent(this,name));
          }
      }
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to