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 Mon, 26 Sep 2005 11:58:01 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

New page:
{{{


package scm.hivemind.statefulservice;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

import org.apache.commons.logging.Log;


/**
 * 
 * @author Marcus Schulte
 */
public class ClientStateStorageImpl implements ClientStateStorage {
    protected Log myLog;
    
	private HttpSession session = null;	
	private Map clientStores = new HashMap();
	private Map map = new HashMap();
	
	
	private HttpSessionBindingListener SESSION_BINDING_LISTENER = 
	    new HttpSessionBindingListener() {
	   
        public void valueBound( HttpSessionBindingEvent arg0 ) {
            // TODO Auto-generated method stub
        }
        
        public void valueUnbound( HttpSessionBindingEvent e ) {
            ((StateStorageClearanceListener)e.getValue()).clientStateCleared();
            myLog.debug("Session expired or invalidated.");
        }
	};

	
	/* (non-Javadoc)
	 * @see com.bmw.sample.ClientStateStorage#provideSession(javax.servlet.http.HttpSession)
	 */
	public void provideSession(HttpSession s ) {
		this.session = s;
	}
	
	public void setLog( Log log ) {
	    myLog = log;
	}

	/* (non-Javadoc)
	 * @see com.bmw.sample.ClientStateStorage#store(java.lang.String, java.lang.Object)
	 */
	public void store(String key, StateStorageClearanceListener obj) {
		if (session==null) {
		    myLog.debug( "storing key: "+key );
			map.put(key,obj);
		} else
			session.setAttribute( key, obj);
	}

	
	/* (non-Javadoc)
	 * @see com.bmw.sample.ClientStateStorage#retrieve(java.lang.String)
	 */
	public StateStorageClearanceListener retrieve(String key) {
		if (session == null) {
		    myLog.debug( "retrieving key: "+key );
			return (StateStorageClearanceListener) map.get(key);
		} else
			return (StateStorageClearanceListener) session.getAttribute(key);

	}
	
	/* (non-Javadoc)
	 * @see com.bmw.sample.ClientStateStorage#setClientId(java.lang.String)
	 */
	public void setClientId(String cid) {
		Map m = (Map) clientStores.get( cid );
		if ( m == null) {
			m = new HashMap();
			clientStores.put( cid, m );
		}
		map = m;
	}
	/* (non-Javadoc)
	 * @see com.bmw.sample.ClientStateStorage#clear()
	 */
	public void clear( String clientId ) {
		Map store = ( (Map)clientStores.get(clientId) );
		for ( Iterator it = store.values().iterator(); it.hasNext(); ) {
            StateStorageClearanceListener obj 
            					= (StateStorageClearanceListener) it.next();
            obj.clientStateCleared();
        }
		store.clear();
	}

}

}}}

---------------------------------------------------------------------
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