Project

General

Profile

Revision 4981

Added by daigle almost 12 years ago

Implement stop method in services. Stop all services when shutting down metacat. This primarily keeps scheduler from hanging with open threads.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
346 346
	 */
347 347
    public void destroy() {
348 348
    	Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
349
    	
350
    	ServiceService.stopAllServices();
351
    	
349 352
        // Close all db connection
350 353
        logMetacat.warn("Destroying MetacatServlet");
351 354
        timer.cancel();
src/edu/ucsb/nceas/metacat/service/ServiceService.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.service;
28 28

  
29
import java.util.Hashtable;
30 29
import javax.servlet.ServletContext;
31 30
import org.apache.log4j.Logger;
32 31

  
32
import java.util.Hashtable;
33
import java.util.Set;
34

  
33 35
import edu.ucsb.nceas.metacat.util.SystemUtil;
34 36

  
35 37
public class ServiceService {
......
80 82
	public static void registerService(String serviceName, BaseService service)
81 83
			throws ServiceException {
82 84
		if (serviceList.containsKey(serviceName)) {
83
			throw new ServiceException("Service: " + serviceName + " is already registered."
85
			throw new ServiceException("ServiceService.registerService - Service: " + serviceName + " is already registered."
84 86
					+ " Use ServiceService.reregister() to replace the service.");
85 87
		}
86
		logMetacat.info("Registering Service: " + serviceName);
88
		logMetacat.info("ServiceService.registerService - Registering Service: " + serviceName);
87 89
		serviceList.put(serviceName, service);
88 90
	}
89 91
	
......
96 98
	public static void refreshService(String serviceName)
97 99
			throws ServiceException {
98 100
		if (!serviceList.containsKey(serviceName)) {
99
			throw new ServiceException("Service: " + serviceName + " is not registered.");
101
			throw new ServiceException("ServiceService.refreshService - Service: " + serviceName + " is not registered.");
100 102
		}
101 103
		
102 104
		BaseService baseService = serviceList.get(serviceName);
103 105
		if (!baseService.refreshable()) {
104
			throw new ServiceException("Service: " + serviceName + " is not refreshable.");
106
			throw new ServiceException("ServiceService.refreshService - Service: " + serviceName + " is not refreshable.");
105 107
		}
106
		logMetacat.info("Refreshing Service: " + serviceName);
108
		logMetacat.info("ServiceService.refreshService - Refreshing Service: " + serviceName);
107 109
		baseService.refresh();
108 110
	}
109 111
	
112
	public static void stopAllServices() {
113
		Set<String> keySet = serviceList.keySet();
114
		
115
		for (String key : keySet) {
116
			try {
117
				logMetacat.info("ServiceService- stopAllServices: Stopping Service: " + key);
118
				serviceList.get(key).stop();
119
			} catch (ServiceException se) {
120
				logMetacat.error("ServiceService.stopAllServices - problem starting service: " 
121
						+ key + " : " + se.getMessage());
122
			}
123
		}
124
	}
125
	
110 126
	/**
111 127
	 * Convert the relative config directory to a full path
112 128
	 * @return the full config path
113 129
	 */
114 130
	public static String getRealConfigDir() throws ServiceException {
115 131
		if (serviceService == null) {
116
			throw new ServiceException("Cannot access config dir before Service has been initialized");
132
			throw new ServiceException("ServiceService.getRealConfigDir - Cannot access config dir before Service has been initialized");
117 133
		}
118 134
		return REAL_CONFIG_DIR;
119 135
	}
......
124 140
	 */
125 141
	public static String getRealSkinDir() throws ServiceException {
126 142
		if (serviceService == null) {
127
			throw new ServiceException("Cannot access skin dir before Service has been initialized");
143
			throw new ServiceException("ServiceService.getRealSkinDir - Cannot access skin dir before Service has been initialized");
128 144
		}
129 145
		return REAL_SKIN_DIR;
130 146
	}
......
135 151
	 */
136 152
	public static String getRealApplicationContext() throws ServiceException {
137 153
		if (REAL_APPLICATION_CONTEXT == null) {
138
			throw new ServiceException("Application context name is null");
154
			throw new ServiceException("ServiceService.getRealApplicationContext - Application context name is null");
139 155
		}
140 156
		return REAL_APPLICATION_CONTEXT;
141 157
	}
src/edu/ucsb/nceas/metacat/service/XMLSchemaService.java
105 105
	/**
106 106
	 * refresh the persistant values in this service.
107 107
	 */
108
	protected void doRefresh() throws ServiceException {
108
	public void doRefresh() throws ServiceException {
109 109
		try {
110 110
			populateRegisteredSchemaList();
111 111
			setUseFullSchemaValidation();
......
117 117
		}
118 118
	}
119 119
	
120
	public void stop() throws ServiceException {
121
		return;
122
	}
123
	
120 124
	/**
121 125
	 * Gets the registered schema list. This list holds schemas that exist in
122 126
	 * the xml_catalog table that also have associated files in the schema
src/edu/ucsb/nceas/metacat/service/SessionService.java
66 66
		return false;
67 67
	}
68 68
	
69
	protected void doRefresh() throws ServiceException {
69
	public void doRefresh() throws ServiceException {
70 70
		return;
71 71
	}
72 72
	
73
	public void stop() throws ServiceException {
74
		return;
75
	}
76
	
73 77
	/**
74 78
	 * Register a session in the session hash table.  This uses
75 79
	 * the parameters passed in to create a SessionData object.
src/edu/ucsb/nceas/metacat/service/DatabaseService.java
65 65
		return false;
66 66
	}
67 67
	
68
	protected void doRefresh() throws ServiceException {
68
	public void doRefresh() throws ServiceException {
69 69
		return;
70 70
	}
71 71
	
72
	public void stop() throws ServiceException {
73
		return;
74
	}
75
	
72 76
    /**
73 77
	 * Instantiate a class using the name of the class at runtime
74 78
	 *
src/edu/ucsb/nceas/metacat/service/PropertyService.java
130 130
		return true;
131 131
	}
132 132
	
133
	protected void doRefresh() throws ServiceException {
133
	public void doRefresh() throws ServiceException {
134 134
		initialize();
135 135
	}
136 136
	
137
	public void stop() throws ServiceException {
138
		return;
139
	}
140
	
137 141
	/**
138 142
	 * Initialize the singleton.
139 143
	 * 
src/edu/ucsb/nceas/metacat/service/SkinPropertyService.java
104 104
		return true;
105 105
	}
106 106

  
107
	protected void doRefresh() throws ServiceException {
107
	public void doRefresh() throws ServiceException {
108 108
		try {
109 109
			initialize();
110 110
		} catch (IOException ioe) {
......
115 115
					+ " property error: " + gpe.getMessage());
116 116
		}
117 117
	}
118
	
119
	public void stop() throws ServiceException {
120
		return;
121
	}
118 122

  
119 123
	/**
120 124
	 * Initialize the singleton.
src/edu/ucsb/nceas/metacat/service/BaseService.java
40 40
	public abstract boolean refreshable();
41 41
	
42 42
	// subclass must define doRefresh.  It is only called from the refresh() method.
43
	protected abstract void doRefresh() throws ServiceException;
43
	public abstract void doRefresh() throws ServiceException;
44 44
	
45 45
	// package level method to refresh service.  We only want ServiceService 
46 46
	// calling this.
47
	void refresh() throws ServiceException{
47
	public void refresh() throws ServiceException{
48 48
		if (refreshable()) {
49 49
			doRefresh();
50 50
		}
51 51
	}
52 52
	
53
//	abstract void stop() throws ServiceException;
53
	public abstract void stop() throws ServiceException;
54 54

  
55 55
}
src/edu/ucsb/nceas/metacat/scheduler/SchedulerService.java
79 79
	}
80 80

  
81 81
	// do the refresh
82
	protected void doRefresh() throws ServiceException {
82
	public void doRefresh() throws ServiceException {
83 83
		stop();
84 84
		start();
85 85
	}
86 86

  
87 87
	// initialize the service
88
	protected void start() throws ServiceException {
88
	public void start() throws ServiceException {
89 89
		try {
90 90
			// get the Quartz scheduler factory
91 91
			SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
......
117 117
	}
118 118
	
119 119
	// Stop the scheduler
120
	protected void stop() throws ServiceException {
120
	public void stop() throws ServiceException {
121 121
		try {
122 122
			sched.shutdown(true);
123 123
			sched = null;

Also available in: Unified diff