hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-hivemind Wiki] Update of "ClientStateStorageImpl" by Marcus Schulte
Date Tue, 25 Oct 2005 08:40:12 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-hivemind Wiki" for change
notification.

The following page has been changed by Marcus Schulte:
http://wiki.apache.org/jakarta-hivemind/ClientStateStorageImpl

------------------------------------------------------------------------------
      protected Log myLog;
      
  	private HttpSession session = null;	
+ 	private boolean invalidSession = false;
  	private Map clientStores = new HashMap();
  	private Map map = new HashMap();
  	
  	
- 	private HttpSessionBindingListener SESSION_BINDING_LISTENER = 
- 	    new HttpSessionBindingListener() {
+ 	private class StoredProxy implements HttpSessionBindingListener {
+ 	   private StateStorageClearanceListener clearanceListener;
  	   
+ 	   public StoredProxy ( StateStorageClearanceListener object ){
+ 	       clearanceListener = object;
+ 	   }
+ 	    
          public void valueBound( HttpSessionBindingEvent arg0 ) {
              // TODO Auto-generated method stub
          }
          
          public void valueUnbound( HttpSessionBindingEvent e ) {
+             invalidSession = true;
-             ((StateStorageClearanceListener)e.getValue()).clientStateCleared();
+             clearanceListener.clientStateCleared();
              myLog.debug("Session expired or invalidated.");
          }
+         
+         public StateStorageClearanceListener getObject() {
+             return clearanceListener;
+         }
- 	};
+ 	}
  
  	
  	/* (non-Javadoc)
@@ -47, +57 @@

  	 */
  	public void provideSession(HttpSession s ) {
  		this.session = s;
+ 		this.invalidSession = false;
  	}
  	
  	public void setLog( Log log ) {
@@ -60, +71 @@

  		if (session==null) {
  		    myLog.debug( "storing key: "+key );
  			map.put(key,obj);
- 		} else
+ 		} else {
- 			session.setAttribute( key, obj);
+ 		    if ( ! invalidSession ) {
+ 		        StoredProxy p = (StoredProxy) session.getAttribute( key );
+ 		        
+ 		        // avoid unbind-events due to replacing an object with itself...
+ 		        if ( p!=null && p.getObject()==obj)
+ 		            return;
+ 		        
+ 		        session.setAttribute( key, new StoredProxy(obj) );
+ 		    } else
+ 		        myLog.debug("skipping store due to invalid Session");
+ 		}
  	}
  
  	
@@ -72, +93 @@

  		if (session == null) {
  		    myLog.debug( "retrieving key: "+key );
  			return (StateStorageClearanceListener) map.get(key);
- 		} else
+ 		} else {
- 			return (StateStorageClearanceListener) session.getAttribute(key);
- 
+ 		    StoredProxy p = (StoredProxy) session.getAttribute(key);
+ 		    if ( p != null )
+ 		        return p.getObject();
+ 		    else
+ 		        return null;
+ 		}		
  	}
  	
  	/* (non-Javadoc)

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


Mime
View raw message