View Javadoc
1   /*
2    * Copyright 2001-2010 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi;
18  
19  import javax.naming.NamingException;
20  
21  import org.apache.commons.configuration.ConfigurationException;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.juddi.config.AppConfig;
25  import org.apache.juddi.config.Property;
26  import org.apache.juddi.replication.ReplicationNotifier;
27  import org.apache.juddi.subscription.SubscriptionNotifier;
28  
29  public class Registry {
30  
31          private static Registry registry = null;
32          private static Log log = LogFactory.getLog(Registry.class);
33          private static SubscriptionNotifier subscriptionNotifier = null;
34          private static ReplicationNotifier replicationNotifier = null;
35  
36          /**
37           * Singleton.
38           */
39          private Registry() {
40                  super();
41          }
42  
43          /**
44           * Stops the registry.
45           *
46           * @throws ConfigurationException
47           */
48          public synchronized static void stop() throws ConfigurationException {
49                  if (registry != null) {
50                          log.info("Stopping jUDDI registry...");
51                          if (subscriptionNotifier != null) {
52                                  log.info("Shutting down SubscriptionNotifier");
53                                  subscriptionNotifier.cancel();
54                                  subscriptionNotifier = null;
55                          }
56                          if (replicationNotifier != null) {
57                                  replicationNotifier.cancel();
58                                  replicationNotifier = null;
59                          }
60                          registry = null;
61                          log.info("jUDDI shutdown completed.");
62                  }
63          }
64  
65          /**
66           * Starts the registry.
67           *
68           * @throws ConfigurationException
69           */
70          public synchronized static void start() throws ConfigurationException {
71                  if (registry == null) {
72                          log.info("Starting jUDDI registry...This is node " + AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, ""));
73                          registry = new Registry();
74                          replicationNotifier = new ReplicationNotifier();
75                          AppConfig.triggerReload();
76                          if (AppConfig.getConfiguration().getBoolean(Property.JUDDI_SUBSCRIPTION_NOTIFICATION, true)) {
77                                  subscriptionNotifier = new SubscriptionNotifier();
78                          }
79                          log.info("jUDDI registry started successfully.");
80                  }
81          }
82  
83  }