01: /*
02: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package com.nabhinc.ws.service.thread;
20:
21: import java.rmi.RemoteException;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25:
26: import com.nabhinc.ws.core.WebServiceException;
27: import com.nabhinc.ws.server.WebServiceDirectoryLocator;
28: import com.nabhinc.ws.server.WebServiceInfo;
29: import com.nabhinc.ws.server.WebServiceLifeCycleEvent;
30: import com.nabhinc.ws.server.WebServiceLifeCycleListener;
31: import com.nabhinc.ws.server.WebServiceManager;
32: import com.nabhinc.ws.server.WebServiceServlet;
33:
34: /**
35: *
36: *
37: * @author Padmanabh Dabke
38: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
39: */
40: public class ThreadManagerServiceLocator implements
41: WebServiceLifeCycleListener {
42: private static ThreadManagerService aslSingleton = null;
43: private static ThreadManagerServiceLocator aslLocatorSingleton = null;
44: private static String aslServiceName = null;
45: private static Log asLogger = LogFactory
46: .getLog(ThreadManagerServiceLocator.class);
47:
48: public static ThreadManagerService getService() {
49: if (aslSingleton == null) {
50: try {
51: WebServiceInfo wsInfo = WebServiceDirectoryLocator
52: .getWebServiceDirectory().lookupByType(
53: ThreadManagerService.class);
54: if (wsInfo == null) {
55: asLogger
56: .warn("Authentication web service has not been started.");
57: } else {
58: aslSingleton = (ThreadManagerService) wsInfo.webService;
59: if (aslLocatorSingleton == null) {
60: aslLocatorSingleton = new ThreadManagerServiceLocator();
61: WebServiceManager
62: .addWebServiceLifeCycleListener(aslLocatorSingleton);
63: }
64: aslServiceName = wsInfo.name;
65: }
66: } catch (WebServiceException e) {
67: asLogger
68: .error(
69: "Failed to get instance of authentication service.",
70: e);
71: }
72: }
73: return aslSingleton;
74: }
75:
76: public static ThreadManagerService getService(String serviceURL)
77: throws RemoteException {
78: // For now return the local instance. In future, we need to return a stub
79: // if the URL points to a remote service.
80: try {
81: return (ThreadManagerService) WebServiceServlet
82: .getInstance().getWebServiceInfo(serviceURL).webService;
83: } catch (WebServiceException e) {
84: throw new RemoteException("Failed to get webservice info.",
85: e);
86: }
87: }
88:
89: public void processEvent(WebServiceLifeCycleEvent e) {
90: if (e.webServiceName.equals(aslServiceName)
91: && (e.type == WebServiceLifeCycleEvent.WSLCE_DELETED
92: || e.type == WebServiceLifeCycleEvent.WSLCE_RELOADED || e.type == WebServiceLifeCycleEvent.WSLCE_UNLOADED)) {
93: aslSingleton = null;
94: }
95:
96: }
97:
98: }
|