1 25 package org.ofbiz.shark.container; 26 27 import java.util.Properties ; 28 29 import org.ofbiz.base.container.Container; 30 import org.ofbiz.base.container.ContainerException; 31 import org.ofbiz.base.container.ContainerConfig; 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.UtilProperties; 34 import org.ofbiz.base.util.UtilMisc; 35 import org.ofbiz.base.util.GeneralRuntimeException; 36 import org.ofbiz.service.LocalDispatcher; 37 import org.ofbiz.service.GenericDispatcher; 38 import org.ofbiz.service.GenericServiceException; 39 import org.ofbiz.entity.GenericDelegator; 40 import org.ofbiz.entity.GenericValue; 41 import org.ofbiz.entity.GenericEntityException; 42 43 import org.enhydra.shark.Shark; 44 import org.enhydra.shark.corba.SharkCORBAServer; 45 import org.enhydra.shark.api.client.wfservice.AdminInterface; 46 import org.enhydra.shark.api.client.wfservice.RepositoryMgr; 47 import org.enhydra.shark.api.client.wfservice.SharkConnection; 48 import org.enhydra.shark.api.client.wfservice.ExecutionAdministration; 49 import org.enhydra.shark.api.client.wfservice.ConnectFailed; 50 import org.enhydra.shark.api.client.wfservice.NotConnected; 51 import org.enhydra.shark.api.client.wfbase.BaseException; 52 import org.enhydra.shark.api.SharkTransaction; 53 import org.enhydra.shark.api.TransactionException; 54 55 62 public class SharkContainer implements Container, Runnable { 63 64 public static final String module = SharkContainer.class.getName(); 65 66 private static GenericDelegator delegator = null; 67 private static LocalDispatcher dispatcher = null; 68 private static GenericValue adminUser = null; 69 private static String adminPass = null; 70 private static Shark shark = null; 71 72 protected String configFile = null; 73 private SharkCORBAServer corbaServer = null; 74 private Thread orbThread = null; 75 76 79 public void init(String [] args, String configFile) { 80 this.configFile = configFile; 81 } 82 83 public boolean start() throws ContainerException { 84 ContainerConfig.Container cfg = ContainerConfig.getContainer("shark-container", configFile); 85 ContainerConfig.Container.Property dispatcherProp = cfg.getProperty("dispatcher-name"); 86 ContainerConfig.Container.Property delegatorProp = cfg.getProperty("delegator-name"); 87 ContainerConfig.Container.Property adminProp = cfg.getProperty("admin-user"); 88 ContainerConfig.Container.Property adminPassProp = cfg.getProperty("admin-pass"); 89 ContainerConfig.Container.Property engineName = cfg.getProperty("engine-name"); 90 ContainerConfig.Container.Property iiopHost = cfg.getProperty("iiop-host"); 91 ContainerConfig.Container.Property iiopPort = cfg.getProperty("iiop-port"); 92 93 if (delegatorProp == null || delegatorProp.value == null || delegatorProp.value.length() == 0) { 95 throw new ContainerException("Invalid delegator-name defined in container configuration"); 96 } 97 98 if (dispatcherProp == null || dispatcherProp.value == null || dispatcherProp.value.length() == 0) { 100 throw new ContainerException("Invalid dispatcher-name defined in container configuration"); 101 } 102 103 if (adminProp == null || adminProp.value == null || adminProp.value.length() == 0) { 105 throw new ContainerException("Invalid admin-user defined in container configuration"); 106 } 107 108 if (adminPassProp == null || adminPassProp.value == null || adminPassProp.value.length() == 0) { 109 throw new ContainerException("Invalid admin-pass defined in container configuration"); 110 } 111 112 if (engineName == null || engineName.value == null || engineName.value.length() == 0) { 113 throw new ContainerException("Invalid engine-name defined in container configuration"); 114 } 115 116 SharkContainer.delegator = GenericDelegator.getGenericDelegator(delegatorProp.value); 118 try { 119 SharkContainer.dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherProp.value, SharkContainer.delegator); 120 } catch (GenericServiceException e) { 121 throw new ContainerException(e); 122 } 123 124 try { 126 SharkContainer.adminUser = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", adminProp.value)); 127 } catch (GenericEntityException e) { 128 throw new ContainerException(e); 129 } 130 131 if (SharkContainer.adminUser == null) { 133 Debug.logWarning("Invalid admin-user; UserLogin not found not starting Shark!", module); 134 return false; 135 } 136 137 SharkContainer.adminPass = adminPassProp.value; 138 139 Properties props = UtilProperties.getProperties("shark.properties"); 141 Shark.configure(props); 142 143 SharkContainer.shark = Shark.getInstance(); 144 Debug.logInfo("Started Shark workflow service", module); 145 146 if (iiopHost != null && iiopHost.value != null && iiopHost.value.length() > 0) { 148 if (iiopPort != null && iiopPort.value != null && iiopPort.value.length() > 0) { 149 try { 150 corbaServer = new SharkCORBAServer(engineName.value, iiopHost.value, iiopPort.value, shark); 151 orbThread = new Thread (this); 152 orbThread.setDaemon(false); 153 orbThread.setName(this.getClass().getName()); 154 orbThread.start(); 155 Debug.logInfo("Started Shark CORBA service", module); 156 } catch (IllegalArgumentException e) { 157 throw new ContainerException(e); 158 } catch (GeneralRuntimeException e) { 159 throw new ContainerException(e); 160 } 161 } 162 } 163 164 ExecutionAdministration exAdmin = SharkContainer.getAdminInterface().getExecutionAdministration(); 166 try { 167 exAdmin.connect(adminUser.getString("userLoginId"), SharkContainer.adminPass, null, null); 168 exAdmin.reevaluateAssignments(); 170 exAdmin.disconnect(); 171 } catch (ConnectFailed e) { 172 String errMsg = "Shark Connection error (if it is a password wrong error, check the admin-pass property in the container config file, probably ofbiz-containers.xml): " + e.toString(); 173 throw new ContainerException(errMsg, e); 174 } catch (NotConnected e) { 175 throw new ContainerException(e); 176 } catch (BaseException e) { 177 throw new ContainerException(e); 178 } 179 180 return true; 181 } 182 183 public void run() { 184 try { 185 corbaServer.startCORBAServer(); 186 } catch (BaseException e) { 187 throw new GeneralRuntimeException(e); 188 } 189 } 190 191 public void stop() throws ContainerException { 192 if (dispatcher != null) { 194 dispatcher.deregister(); 195 } 196 197 if (corbaServer != null) { 199 corbaServer.shutdownORB(); 200 } 201 Debug.logInfo("stop Shark", module); 202 } 203 204 public static GenericDelegator getDelegator() { 206 return SharkContainer.delegator; 207 } 208 209 public static LocalDispatcher getDispatcher() { 210 return SharkContainer.dispatcher; 211 } 212 213 public static GenericValue getAdminUser() { 214 return SharkContainer.adminUser; 215 } 216 217 public static AdminInterface getAdminInterface() { 218 return shark.getAdminInterface(); 219 } 220 221 public static RepositoryMgr getRepositoryMgr() { 222 return shark.getRepositoryManager(); 223 } 224 225 public static SharkConnection getSharkConntection() { 226 return shark.getSharkConnection(); 227 } 228 229 public static SharkTransaction getTransaction() throws TransactionException { 230 return shark.createTransaction(); 231 } 232 } | Popular Tags |