001/* 002 * GWTEventService 003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt) 004 * 005 * This is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Lesser General Public License as 007 * published by the Free Software Foundation; either version 3 of 008 * the License, or (at your option) any later version. 009 * Other licensing for GWTEventService may also be possible on request. 010 * Please view the license.txt of the project for more information. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022package de.novanic.eventservice.service.registry; 023 024import de.novanic.eventservice.config.EventServiceConfigurationFactory; 025import de.novanic.eventservice.config.EventServiceConfiguration; 026import de.novanic.eventservice.service.registry.user.UserManagerFactory; 027 028/** 029 * The EventRegistryFactory is used to create the EventRegistry and to ensure that only one instance of 030 * EventRegistryFactory and EventRegistry exists (singleton). 031 * @see EventRegistry 032 * 033 * @author sstrohschein 034 * <br>Date: 09.06.2008 035 * <br>Time: 22:46:51 036 */ 037public class EventRegistryFactory 038{ 039 private volatile EventRegistry myEventRegistry; 040 041 /** 042 * The EventRegistryFactory should be created via the getInstance method. 043 * @see EventRegistryFactory#getInstance() 044 */ 045 private EventRegistryFactory() {} 046 047 /** 048 * Factory-Holder class to ensure thread-safe lazy-loading with IODH. 049 */ 050 private static class EventRegistryFactoryHolder { 051 private static EventRegistryFactory INSTANCE = new EventRegistryFactory(); 052 } 053 054 /** 055 * This method should be used to create an instance of EventRegistryFactory. 056 * EventRegistryFactory is a singleton, so this method returns always the same instance of EventRegistryFactory. 057 * @return EventRegistryFactory (singleton) 058 */ 059 public static EventRegistryFactory getInstance() { 060 return EventRegistryFactoryHolder.INSTANCE; 061 } 062 063 /** 064 * This method should be used to create an instance of EventRegistry. 065 * EventRegistry is a singleton, so this method returns always the same instance of EventRegistry. 066 * @return EventRegistry (singleton) 067 */ 068 public EventRegistry getEventRegistry() { 069 if(myEventRegistry == null) { 070 synchronized(this) { 071 if(myEventRegistry == null) { 072 EventServiceConfiguration theConfiguration = getEventServiceConfiguration(); 073 myEventRegistry = new DefaultEventRegistry(theConfiguration); 074 } 075 } 076 } 077 return myEventRegistry; 078 } 079 080 public void resetEventRegistry() { 081 synchronized(this) { 082 myEventRegistry = null; 083 UserManagerFactory.getInstance().getUserManager().reset(); 084 } 085 } 086 087 /** 088 * Loads the {@link de.novanic.eventservice.config.EventServiceConfiguration} with {@link de.novanic.eventservice.config.EventServiceConfigurationFactory}. 089 * @return configuration ({@link de.novanic.eventservice.config.EventServiceConfiguration}) 090 */ 091 private EventServiceConfiguration getEventServiceConfiguration() { 092 EventServiceConfigurationFactory theConfigurationFactory = EventServiceConfigurationFactory.getInstance(); 093 return theConfigurationFactory.loadEventServiceConfiguration(); 094 } 095}