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.client.event.command.schedule; 023 024/** 025 * The ClientCommandSchedulerFactory is used to create the ClientCommandScheduler and to ensure that only one instance of 026 * ClientCommandSchedulerFactory and ClientCommandScheduler exists (singleton). 027 * @see de.novanic.eventservice.client.event.command.schedule.ClientCommandScheduler 028 * 029 * @author sstrohschein 030 * <br>Date: 04.04.2009 031 * <br>Time: 22:26:18 032 */ 033public class ClientCommandSchedulerFactory 034{ 035 private volatile ClientCommandScheduler myClientCommandScheduler; 036 037 /** 038 * The ClientCommandSchedulerFactory should be created via the getInstance method. 039 * @see ClientCommandSchedulerFactory#getInstance() 040 */ 041 private ClientCommandSchedulerFactory() {} 042 043 /** 044 * Factory-Holder class to ensure thread-safe lazy-loading with IODH. 045 */ 046 private static class ClientCommandSchedulerFactoryHolder { 047 private static ClientCommandSchedulerFactory INSTANCE = new ClientCommandSchedulerFactory(); 048 } 049 050 /** 051 * This method should be used to create an instance of ClientCommandSchedulerFactory. 052 * ClientCommandSchedulerFactory is a singleton, so this method returns always the same instance of 053 * ClientCommandSchedulerFactory. 054 * @return ClientCommandSchedulerFactory (singleton) 055 */ 056 public static ClientCommandSchedulerFactory getInstance() { 057 return ClientCommandSchedulerFactoryHolder.INSTANCE; 058 } 059 060 /** 061 * This method should be used to create an instance of RemoteEventService. 062 * RemoteEventService is a singleton, so this method returns always the same instance of RemoteEventService. 063 * The session is needed to generate the client/user id. 064 * @return RemoteEventService (singleton) 065 */ 066 public ClientCommandScheduler getClientCommandScheduler() { 067 if(myClientCommandScheduler == null) { 068 synchronized(this) { 069 if(myClientCommandScheduler == null) { 070 myClientCommandScheduler = new GWTCommandScheduler(); 071 } 072 } 073 } 074 return myClientCommandScheduler; 075 } 076 077 /** 078 * Sets an instance of ClientCommandScheduler which is returned by {@link ClientCommandSchedulerFactory#getClientCommandScheduler()}. 079 * @param aClientCommandScheduler {@link ClientCommandScheduler} 080 */ 081 public void setClientCommandSchedulerInstance(ClientCommandScheduler aClientCommandScheduler) { 082 myClientCommandScheduler = aClientCommandScheduler; 083 } 084 085 /** 086 * Resets the ClientCommandScheduler instance. 087 */ 088 public void reset() { 089 setClientCommandSchedulerInstance(null); 090 } 091}