tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session DeltaManager.java DeltaSession.java
Date Tue, 27 Apr 2004 17:50:43 GMT
fhanik      2004/04/27 10:50:43

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java DeltaSession.java
  Log:
  Added in the ability to run the DeltaManager/DeltaSession without a container, so
  that a different clustering plug in can be used to backup sessions in a primary/secondary
store
  
  Revision  Changes    Path
  1.23      +12 -2     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
  
  Index: DeltaManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- DeltaManager.java	8 Apr 2004 15:30:11 -0000	1.22
  +++ DeltaManager.java	27 Apr 2004 17:50:43 -0000	1.23
  @@ -369,8 +369,18 @@
           ReplicationStream ois = null;
           Loader loader = null;
           ClassLoader classLoader = null;
  +        //fix to be able to run the DeltaManager
  +        //stand alone without a container.
  +        //use the Threads context class loader
  +        if ( container != null ) 
  +            loader = container.getLoader();
  +        if ( loader != null ) 
  +            classLoader = loader.getClassLoader();
  +        else
  +            classLoader = Thread.currentThread().getContextClassLoader();
  +        //end fix
           fis = new ByteArrayInputStream(data);
  -        ois = new ReplicationStream(fis,container.getLoader().getClassLoader());
  +        ois = new ReplicationStream(fis,classLoader);
           session.getDeltaRequest().readExternal(ois);
           ois.close();
           return session.getDeltaRequest();
  
  
  
  1.22      +131 -112  jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
  
  Index: DeltaSession.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- DeltaSession.java	7 Apr 2004 19:02:31 -0000	1.21
  +++ DeltaSession.java	27 Apr 2004 17:50:43 -0000	1.22
  @@ -396,36 +396,42 @@
   
           // Notify interested application event listeners
           Context context = (Context) manager.getContainer();
  -        Object listeners[] = context.getApplicationLifecycleListeners();
  -        if (listeners != null) {
  -            HttpSessionEvent event =
  -                new HttpSessionEvent(getSession());
  -            for (int i = 0; i < listeners.length; i++) {
  -                if (!(listeners[i] instanceof HttpSessionListener))
  -                    continue;
  -                HttpSessionListener listener =
  -                    (HttpSessionListener) listeners[i];
  -                try {
  -                    fireContainerEvent(context,
  -                                       "beforeSessionCreated",
  -                                       listener);
  -                    listener.sessionCreated(event);
  -                    fireContainerEvent(context,
  -                                       "afterSessionCreated",
  -                                       listener);
  -                } catch (Throwable t) {
  +        //fix for standalone manager without container
  +        if ( context != null ) { 
  +            Object listeners[] = context.getApplicationLifecycleListeners();
  +            if (listeners != null) {
  +                HttpSessionEvent event =
  +                    new HttpSessionEvent(getSession());
  +                for (int i = 0; i < listeners.length; i++) {
  +                    if (! (listeners[i] instanceof HttpSessionListener))
  +                        continue;
  +                    HttpSessionListener listener =
  +                        (HttpSessionListener) listeners[i];
                       try {
                           fireContainerEvent(context,
  +                                           "beforeSessionCreated",
  +                                           listener);
  +                        listener.sessionCreated(event);
  +                        fireContainerEvent(context,
                                              "afterSessionCreated",
                                              listener);
  -                    } catch (Exception e) {
  -                        ;
  +                    } catch (Throwable t) {
  +                        try {
  +                            fireContainerEvent(context,
  +                                               "afterSessionCreated",
  +                                               listener);
  +                        } catch (Exception e) {
  +                            ;
  +                        }
  +                        // FIXME - should we do anything besides log these?
  +                        log.error(sm.getString("standardSession.sessionEvent"),
  +                                  t);
                       }
  -                    // FIXME - should we do anything besides log these?
  -                    log.error(sm.getString("standardSession.sessionEvent"), t);
                   }
               }
  -        }
  +        }//end if
  +        //end fix
  +
   
       }
   
  @@ -710,37 +716,42 @@
               // Notify interested application event listeners
               // FIXME - Assumes we call listeners in reverse order
               Context context = (Context) manager.getContainer();
  -            Object listeners[] = context.getApplicationLifecycleListeners();
  -            if (notify && (listeners != null)) {
  -                HttpSessionEvent event =
  -                    new HttpSessionEvent(getSession());
  -                for (int i = 0; i < listeners.length; i++) {
  -                    int j = (listeners.length - 1) - i;
  -                    if (!(listeners[j] instanceof HttpSessionListener))
  -                        continue;
  -                    HttpSessionListener listener =
  -                        (HttpSessionListener) listeners[j];
  -                    try {
  -                        fireContainerEvent(context,
  -                                           "beforeSessionDestroyed",
  -                                           listener);
  -                        listener.sessionDestroyed(event);
  -                        fireContainerEvent(context,
  -                                           "afterSessionDestroyed",
  -                                           listener);
  -                    } catch (Throwable t) {
  +            //fix for standalone manager without container
  +            if ( context != null ) {
  +                Object listeners[] = context.getApplicationLifecycleListeners();
  +                if (notify && (listeners != null)) {
  +                    HttpSessionEvent event =
  +                        new HttpSessionEvent(getSession());
  +                    for (int i = 0; i < listeners.length; i++) {
  +                        int j = (listeners.length - 1) - i;
  +                        if (! (listeners[j] instanceof HttpSessionListener))
  +                            continue;
  +                        HttpSessionListener listener =
  +                            (HttpSessionListener) listeners[j];
                           try {
                               fireContainerEvent(context,
  +                                               "beforeSessionDestroyed",
  +                                               listener);
  +                            listener.sessionDestroyed(event);
  +                            fireContainerEvent(context,
                                                  "afterSessionDestroyed",
                                                  listener);
  -                        } catch (Exception e) {
  -                            ;
  +                        } catch (Throwable t) {
  +                            try {
  +                                fireContainerEvent(context,
  +                                    "afterSessionDestroyed",
  +                                    listener);
  +                            } catch (Exception e) {
  +                                ;
  +                            }
  +                            // FIXME - should we do anything besides log these?
  +                            log.error(sm.getString(
  +                                "standardSession.sessionEvent"), t);
                           }
  -                        // FIXME - should we do anything besides log these?
  -                        log.error(sm.getString("standardSession.sessionEvent"), t);
                       }
                   }
  -            }
  +            }//end if
  +            //end fix
               accessCount=0;
               setValid(false);
   
  @@ -1295,58 +1306,62 @@
   
           // Notify interested application event listeners
           Context context = (Context) manager.getContainer();
  -        Object listeners[] = context.getApplicationEventListeners();
  -        if (listeners == null)
  -            return;
  -        for (int i = 0; i < listeners.length; i++) {
  -            if (!(listeners[i] instanceof HttpSessionAttributeListener))
  -                continue;
  -            HttpSessionAttributeListener listener =
  -                (HttpSessionAttributeListener) listeners[i];
  -            try {
  -                if (unbound != null) {
  -                    fireContainerEvent(context,
  -                                       "beforeSessionAttributeReplaced",
  -                                       listener);
  -                    if ( event == null ) {
  -                        event = new HttpSessionBindingEvent
  -                            (this,name,unbound);
  -                    }
  -                    listener.attributeReplaced(event);
  -                    fireContainerEvent(context,
  -                                       "afterSessionAttributeReplaced",
  -                                       listener);
  -                } else {
  -                    fireContainerEvent(context,
  -                                       "beforeSessionAttributeAdded",
  -                                       listener);
  -                    if (event == null) {
  -                        event = new HttpSessionBindingEvent
  -                            (this, name, unbound);
  -                    }
  -                    listener.attributeAdded(event);
  -                    fireContainerEvent(context,
  -                                       "afterSessionAttributeAdded",
  -                                       listener);
  -                }
  -            } catch (Throwable t) {
  +        //fix for standalone manager without container
  +        if ( context != null ) {
  +            Object listeners[] = context.getApplicationEventListeners();
  +            if (listeners == null)
  +                return;
  +            for (int i = 0; i < listeners.length; i++) {
  +                if (! (listeners[i] instanceof HttpSessionAttributeListener))
  +                    continue;
  +                HttpSessionAttributeListener listener =
  +                    (HttpSessionAttributeListener) listeners[i];
                   try {
                       if (unbound != null) {
                           fireContainerEvent(context,
  +                                           "beforeSessionAttributeReplaced",
  +                                           listener);
  +                        if (event == null) {
  +                            event = new HttpSessionBindingEvent
  +                                (this, name, unbound);
  +                        }
  +                        listener.attributeReplaced(event);
  +                        fireContainerEvent(context,
                                              "afterSessionAttributeReplaced",
                                              listener);
                       } else {
                           fireContainerEvent(context,
  +                                           "beforeSessionAttributeAdded",
  +                                           listener);
  +                        if (event == null) {
  +                            event = new HttpSessionBindingEvent
  +                                (this, name, unbound);
  +                        }
  +                        listener.attributeAdded(event);
  +                        fireContainerEvent(context,
                                              "afterSessionAttributeAdded",
                                              listener);
                       }
  -                } catch (Exception e) {
  -                    ;
  +                } catch (Throwable t) {
  +                    try {
  +                        if (unbound != null) {
  +                            fireContainerEvent(context,
  +                                               "afterSessionAttributeReplaced",
  +                                               listener);
  +                        } else {
  +                            fireContainerEvent(context,
  +                                               "afterSessionAttributeAdded",
  +                                               listener);
  +                        }
  +                    } catch (Exception e) {
  +                        ;
  +                    }
  +                    // FIXME - should we do anything besides log these?
  +                    log.error(sm.getString("standardSession.attributeEvent"), t);
                   }
  -                // FIXME - should we do anything besides log these?
  -                log.error(sm.getString("standardSession.attributeEvent"), t);
  -            }
  -        }
  +            } //for
  +        }//end if
  +        //end fix
   
       }
   
  @@ -1612,34 +1627,38 @@
   
           // Notify interested application event listeners
           Context context = (Context) manager.getContainer();
  -        Object listeners[] = context.getApplicationEventListeners();
  -        if (listeners == null)
  -            return;
  -        for (int i = 0; i < listeners.length; i++) {
  -            if (!(listeners[i] instanceof HttpSessionAttributeListener))
  -                continue;
  -            HttpSessionAttributeListener listener =
  -                (HttpSessionAttributeListener) listeners[i];
  -            try {
  -                fireContainerEvent(context,
  -                                   "beforeSessionAttributeRemoved",
  -                                   listener);
  -                listener.attributeRemoved(event);
  -                fireContainerEvent(context,
  -                                   "afterSessionAttributeRemoved",
  -                                   listener);
  -            } catch (Throwable t) {
  +        //fix for standalone manager without container
  +        if ( context != null ) {
  +            Object listeners[] = context.getApplicationEventListeners();
  +            if (listeners == null)
  +                return;
  +            for (int i = 0; i < listeners.length; i++) {
  +                if (! (listeners[i] instanceof HttpSessionAttributeListener))
  +                    continue;
  +                HttpSessionAttributeListener listener =
  +                    (HttpSessionAttributeListener) listeners[i];
                   try {
                       fireContainerEvent(context,
  +                                       "beforeSessionAttributeRemoved",
  +                                       listener);
  +                    listener.attributeRemoved(event);
  +                    fireContainerEvent(context,
                                          "afterSessionAttributeRemoved",
                                          listener);
  -                } catch (Exception e) {
  -                    ;
  +                } catch (Throwable t) {
  +                    try {
  +                        fireContainerEvent(context,
  +                                           "afterSessionAttributeRemoved",
  +                                           listener);
  +                    } catch (Exception e) {
  +                        ;
  +                    }
  +                    // FIXME - should we do anything besides log these?
  +                    log.error(sm.getString("standardSession.attributeEvent"), t);
                   }
  -                // FIXME - should we do anything besides log these?
  -                log.error(sm.getString("standardSession.attributeEvent"), t);
  -            }
  -        }
  +            } //for
  +        }//end if
  +        //end fix
   
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message