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
021package org.granite.tide.seam;
022
023import java.util.concurrent.ConcurrentHashMap;
024
025import org.jboss.seam.Component;
026import org.jboss.seam.ScopeType;
027import org.jboss.seam.annotations.AutoCreate;
028import org.jboss.seam.annotations.Name;
029import org.jboss.seam.annotations.Scope;
030import 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
042public 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            UserEvents tmpUserEvents = userEventsMap.putIfAbsent(sessionId, userEvents); 
053            if (tmpUserEvents != null) 
054                userEvents = tmpUserEvents;         
055        }
056        userEvents.addEventType(eventType);
057    }
058    
059    public void unregisterSession(String sessionId) {
060        userEventsMap.remove(sessionId);
061    }
062    
063    public UserEvents getUserEvents(String sessionId) {
064        return userEventsMap.get(sessionId);
065    }
066    
067    public boolean hasEventType(String sessionId, String eventType) {
068        UserEvents userEvents = userEventsMap.get(sessionId);
069        if (userEvents == null)
070            return false;
071        return userEvents.hasEventType(eventType);
072    }
073    
074    
075    public static TideUserEvents instance() {
076        return (TideUserEvents)Component.getInstance(TideUserEvents.class, ScopeType.APPLICATION);
077    }
078}