KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > SchedulerRepository


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.impl;
22
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25
26 import org.quartz.Scheduler;
27 import org.quartz.SchedulerException;
28
29 /**
30  * <p>
31  * Holds references to Scheduler instances - ensuring uniqueness, and
32  * preventing garbage collection, and allowing 'global' lookups - all within a
33  * ClassLoader space.
34  * </p>
35  *
36  * @author James House
37  */

38 public class SchedulerRepository {
39
40     /*
41      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42      *
43      * Data members.
44      *
45      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46      */

47
48     private HashMap JavaDoc schedulers;
49
50     private static SchedulerRepository inst;
51
52     /*
53      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54      *
55      * Constructors.
56      *
57      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58      */

59
60     private SchedulerRepository() {
61         schedulers = new HashMap JavaDoc();
62     }
63
64     /*
65      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66      *
67      * Interface.
68      *
69      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70      */

71
72     public static synchronized SchedulerRepository getInstance() {
73         if (inst == null) {
74             inst = new SchedulerRepository();
75         }
76
77         return inst;
78     }
79
80     public synchronized void bind(Scheduler sched) throws SchedulerException {
81
82         if ((Scheduler) schedulers.get(sched.getSchedulerName()) != null) {
83             throw new SchedulerException("Scheduler with name '"
84                     + sched.getSchedulerName() + "' already exists.",
85                     SchedulerException.ERR_BAD_CONFIGURATION);
86         }
87
88         schedulers.put(sched.getSchedulerName(), sched);
89     }
90
91     public synchronized boolean remove(String JavaDoc schedName) {
92         return (schedulers.remove(schedName) != null);
93     }
94
95     public synchronized Scheduler lookup(String JavaDoc schedName) {
96         return (Scheduler) schedulers.get(schedName);
97     }
98
99     public synchronized Collection JavaDoc lookupAll() {
100         return java.util.Collections
101                 .unmodifiableCollection(schedulers.values());
102     }
103
104 }
Popular Tags