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 static final long serialVersionUID = -5395975397632138270L;
045        
046        private ConcurrentHashMap<String, UserEvents> userEventsMap = new ConcurrentHashMap<String, UserEvents>();
047        
048        
049        public synchronized void registerEventType(String sessionId, String eventType) {
050            UserEvents userEvents = userEventsMap.get(sessionId);
051            if (userEvents == null) {
052                userEvents = new UserEvents();
053                userEventsMap.put(sessionId, userEvents);
054            }
055            userEvents.addEventType(eventType);
056        }
057        
058        public void unregisterSession(String sessionId) {
059            userEventsMap.remove(sessionId);
060        }
061        
062        public UserEvents getUserEvents(String sessionId) {
063            return userEventsMap.get(sessionId);
064        }
065        
066        public boolean hasEventType(String sessionId, String eventType) {
067            UserEvents userEvents = userEventsMap.get(sessionId);
068            if (userEvents == null)
069                return false;
070            return userEvents.hasEventType(eventType);
071        }
072        
073        
074        public static TideUserEvents instance() {
075            return (TideUserEvents)Component.getInstance(TideUserEvents.class, ScopeType.APPLICATION);
076        }
077    }