00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.openmobileis.bundle.coldupdate.terminal;
00029
00030 import java.io.File;
00031
00032 import org.openmobileis.common.util.collection.Array;
00033 import org.openmobileis.common.util.exception.ServiceException;
00034 import org.openmobileis.common.util.log.LogManager;
00035 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00036 import org.openmobileis.module.core.ProfileModule;
00037 import org.openmobileis.module.core.ProfileModuleSynchroListener;
00038 import org.openmobileis.module.terminal.ModuleManagerListener;
00039 import org.openmobileis.modules.profiles.terminal.RubricLoader;
00040 import org.openmobileis.services.common.ServiceManager;
00041 import org.openmobileis.synchro.client.SynchroDescriptor;
00042 import org.openmobileis.synchro.openmsp.OpenMSPException;
00043 import org.openmobileis.synchro.openmsp.client.EmptyOpenMSPSyncListener;
00044 import org.openmobileis.synchro.openmsp.client.OpenMSPSyncListener;
00045 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00046 import org.openmobileis.synchro.openmsp.client.core.NumSyncManagerDB;
00047 import org.openmobileis.synchro.security.auth.Credential;
00048
00053 public final class ColdUpdateModuleManagerListener extends EmptyOpenMSPSyncListener implements ModuleManagerListener {
00054 private static Array collectionToremoveList;
00055 private boolean restartAppli = false;
00056
00060 public ColdUpdateModuleManagerListener() {
00061 collectionToremoveList = new Array();
00062 }
00063
00064 public void initManager() throws ServiceException {
00065
00066
00067 File copyDir = new File(this.getJarInstallPath());
00068 File[] jarList = copyDir.listFiles();
00069 String baseDestDir = System.getProperty("user.dir")+"/WEB-INF/lib/";
00070 for (int i=0; i<jarList.length; i++) {
00071
00072
00073 jarList[i].getAbsoluteFile().renameTo(new File(baseDestDir+jarList[i].getName()));
00074 }
00075 OpenMSPSynchroManager.getManager().addListener(this, null);
00076 }
00077
00082 public String getSyncName() {
00083 return "FWK StaticModuleManagerListener";
00084 }
00085
00086
00087
00088
00089 public String getJarInstallPath() {
00090 return System.getProperty("user.dir")+"/WEB-INF/module/jar";
00091 }
00092
00093
00094
00095
00096 public String getXMLInstallPath() {
00097 return System.getProperty("user.dir")+"/WEB-INF/module/xml";
00098 }
00099
00100
00101
00102
00103 public void notifyModuleLoading(ProfileModule module) throws ServiceException {
00104 String loaderClassName = module.getModuleLoaderClass();
00105 if (loaderClassName != null) {
00106 try {
00107 RubricLoader loader = (RubricLoader) Thread.currentThread().getContextClassLoader().loadClass(loaderClassName).newInstance();
00108 ServiceManager.getManager().loadRubricLoader(loader);
00109 } catch (Throwable ex) {
00110 LogManager.traceError(0, "StaticModuleManagerListener notifyModuleLoading : Exception during module "+module.getName()+" loading :"+ex.getMessage());
00111 throw new ServiceException(ex);
00112 }
00113 }
00114 }
00115
00116
00117
00118
00119 public void notifyModuleUpdate(ProfileModule module) throws ServiceException {
00120 try {
00121 if (FastObjectDBManager.getManager().isFodbStarted()) {
00122 Array listenerlist = module.getSynchroListenerList();
00123 for (int i=0; i<listenerlist.size(); i++){
00124 ProfileModuleSynchroListener synclistener = (ProfileModuleSynchroListener)listenerlist.get(i);
00125 OpenMSPSyncListener listener = OpenMSPSynchroManager.getManager().getListenerByName(synclistener.name);
00126 if (listener != null){
00127 if (!listener.isSyncOK()) {
00128 throw new ServiceException(module.getName()+" collection "+synclistener.name+" synchro error. Module can't be updated. Remove synchro module files");
00129 }
00130
00131 collectionToremoveList.add(synclistener.name);
00132
00133 NumSyncManagerDB.getManager().saveSyncNumberForService(0, synclistener.name);
00134 }
00135
00136 }
00137 }
00138 } catch (Exception ex) {
00139 throw new ServiceException(ex);
00140 }
00141 this.restartAppli = true;
00142 }
00143
00144
00145
00146
00147 public void startSync(Credential cred, SynchroDescriptor synchrodescriptor) throws OpenMSPException {
00148 this.restartAppli = false;
00149 collectionToremoveList.clear();
00150 }
00151
00152
00153
00154
00155 public void endSync() throws OpenMSPException {
00156 if (this.restartAppli) {
00157 Thread thread = new Thread(new Runnable() {
00158 public void run() {
00159 try {
00160 Thread.currentThread().sleep(10000);
00161 } catch (Throwable ex) {
00162 LogManager.traceError(0, ex);
00163 }
00164 System.exit(0);
00165 };
00166 });
00167 thread.start();
00168
00169
00170
00171
00172 }
00173 }
00174
00175 }