001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: jonas-team@objectweb.org
005: * Copyright (C) 2006 Distributed Systems Lab.
006: * Universidad Politécnica de Madrid (Spain)
007: * Contact: http://lsd.ls.fi.upm.es/lsd
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
022: * USA
023: *
024: * --------------------------------------------------------------------------
025: * $Id: HaServiceImpl.java 9665 2006-10-05 09:55:22Z japaz $
026: * --------------------------------------------------------------------------
027: */package org.objectweb.jonas.ha;
028:
029: import javax.naming.Context;
030:
031: import org.objectweb.carol.cmi.configuration.TraceCmi;
032: import org.objectweb.carol.cmi.ha.ReplicationManager;
033: import org.objectweb.carol.cmi.ha.ReplicationManagerImpl;
034: import org.objectweb.carol.cmi.ha.interceptor.HACurrent;
035: import org.objectweb.carol.cmi.ha.interceptor.HACurrentDelegate;
036: import org.objectweb.jonas.ha.interceptor.HACurrentDelegateImpl;
037: import org.objectweb.jonas.service.AbsServiceImpl;
038: import org.objectweb.jonas.service.ServiceException;
039:
040: /**
041: * This class binds the HA service to Jonas and initializes the HA architecture
042: * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
043: * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
044: * @author benoit pelletier
045: */
046: public class HaServiceImpl extends AbsServiceImpl implements HaService {
047:
048: private final String SERVICE_NAME = "HAService";
049:
050: private boolean started = false;
051:
052: private ReplicationManager replicationMgr;
053:
054: private HACurrentDelegate haCurrentDlg = null;
055:
056: public void doInit(Context ctx) throws ServiceException {
057: TraceCmi.infoCmiHA("Initializing replication service...");
058: try {
059:
060: replicationMgr = new ReplicationManagerImpl(ctx);
061:
062: // Init the HA current class
063: haCurrentDlg = HACurrentDelegateImpl.getCurrent();
064: HACurrent.getHACurrent().setDlg(haCurrentDlg);
065:
066: if (TraceCmi.isDebugCmiHA()) {
067: TraceCmi.debugCmiHA("replicationMgr=" + replicationMgr);
068: TraceCmi.debugCmiHA("haCurrentDlg=" + haCurrentDlg);
069: }
070:
071: } catch (Exception e) {
072: throw new ServiceException("Error in GCL name");
073: }
074: }
075:
076: public void doStart() throws ServiceException {
077: // COMPLETE: Allow to start and shutdown service dinamically
078: started = true;
079: TraceCmi.infoCmiHA("Replication service started");
080: }
081:
082: public void doStop() throws ServiceException {
083: // COMPLETE: Allow to start and shutdown service dinamically
084: if (started) {
085: started = false;
086: replicationMgr.clear(); // Turn off the GCL
087: TraceCmi.infoCmiHA("Replication service stopped");
088: }
089: }
090:
091: public boolean isStarted() {
092: return started;
093: }
094:
095: public void setName(String name) {
096: // Nothing to do...
097: }
098:
099: public String getName() {
100: return SERVICE_NAME;
101: }
102:
103: /**
104: * Return the replication manager
105: */
106: public ReplicationManager getReplicationManager() {
107:
108: if (TraceCmi.isDebugCmiHA()) {
109: TraceCmi.debugCmiHA("replicationMgr=" + replicationMgr);
110: }
111:
112: return replicationMgr;
113: }
114: }
|