001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.tide.seam;
022    
023    import java.util.concurrent.ConcurrentHashMap;
024    
025    import org.jboss.seam.Component;
026    import org.jboss.seam.ScopeType;
027    import org.jboss.seam.annotations.AutoCreate;
028    import org.jboss.seam.annotations.Name;
029    import org.jboss.seam.annotations.Scope;
030    import org.jboss.seam.annotations.intercept.BypassInterceptors;
031    
032    
033    /**
034     * TideAsync stores user events configuration
035     * 
036     * @author William DRAI
037     */
038    @Name("org.granite.tide.seam.userEvents")
039    @Scope(ScopeType.APPLICATION)
040    @BypassInterceptors
041    @AutoCreate
042    public class TideUserEvents {
043        
044        private ConcurrentHashMap<String, UserEvents> userEventsMap = new ConcurrentHashMap<String, UserEvents>();
045        
046        
047        public synchronized void registerEventType(String sessionId, String eventType) {
048            UserEvents userEvents = userEventsMap.get(sessionId);
049            if (userEvents == null) {
050                userEvents = new UserEvents();
051                userEventsMap.put(sessionId, userEvents);
052            }
053            userEvents.addEventType(eventType);
054        }
055        
056        public void unregisterSession(String sessionId) {
057            userEventsMap.remove(sessionId);
058        }
059        
060        public UserEvents getUserEvents(String sessionId) {
061            return userEventsMap.get(sessionId);
062        }
063        
064        public boolean hasEventType(String sessionId, String eventType) {
065            UserEvents userEvents = userEventsMap.get(sessionId);
066            if (userEvents == null)
067                return false;
068            return userEvents.hasEventType(eventType);
069        }
070        
071        
072        public static TideUserEvents instance() {
073            return (TideUserEvents)Component.getInstance(TideUserEvents.class, ScopeType.APPLICATION);
074        }
075    }