1 23 24 package com.sun.enterprise.connectors.util; 25 26 import com.sun.enterprise.config.serverbeans.*; 27 import com.sun.enterprise.config.*; 28 import com.sun.enterprise.server.*; 29 import com.sun.enterprise.deployment.*; 30 import com.sun.enterprise.server.*; 31 import com.sun.enterprise.connectors.*; 32 import com.sun.enterprise.connectors.system.*; 33 import com.sun.enterprise.connectors.inflow.*; 34 import com.sun.enterprise.util.zip.*; 35 import com.sun.logging.LogDomains; 36 import java.io.*; 37 import java.util.logging.*; 38 import java.util.jar.*; 39 40 44 public class JmsRaUtil { 45 46 private final String MQ_RAR = "imqjmsra.rar"; 47 48 private final String SYSTEM_APP_DIR = 49 "lib" + File.separator + "install" + File.separator + "applications"; 50 51 private final String MQ_RAR_MANIFEST = 52 ConnectorConstants.DEFAULT_JMS_ADAPTER + File.separator + "META-INF" 53 + File.separator + "MANIFEST.MF"; 54 55 private final String MANIFEST_TAG = "Implementation-Version"; 57 58 private static final String propName_reconnect_delay_in_seconds = 59 "reconnect-delay-in-seconds"; 60 private static final String propName_reconnect_max_retries = 61 "reconnect-max-retries"; 62 private static final String propName_reconnect_enabled = 63 "reconnect-enabled"; 64 private static final int DEFAULT_RECONNECT_DELAY = 60; 65 private static final int DEFAULT_RECONNECT_RETRIES = 60; 66 67 private static final String propName_cmt_max_runtime_exceptions 68 = "cmt-max-runtime-exceptions"; 69 private static final int DEFAULT_CMT_MAX_RUNTIME_EXCEPTIONS = 1; 70 71 private int cmtMaxRuntimeExceptions = DEFAULT_CMT_MAX_RUNTIME_EXCEPTIONS; 72 73 private int reconnectDelayInSeconds = DEFAULT_RECONNECT_DELAY; 74 private int reconnectMaxRetries = DEFAULT_RECONNECT_RETRIES; 75 private boolean reconnectEnabled = false; 76 77 ServerContext sc = null; 78 ConfigContext ctx = null; 79 JmsService js = null; 80 MQAddressList list = null; 81 82 static Logger _mdblogger = LogDomains.getLogger(LogDomains.MDB_LOGGER); 83 static Logger _rarlogger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 84 85 public JmsRaUtil() throws ConnectorRuntimeException { 86 this(null); 87 } 88 89 public JmsRaUtil(JmsService js) throws ConnectorRuntimeException { 90 try { 91 if (js != null) { 92 this.js = js; 93 } else { 94 sc = ApplicationServer.getServerContext(); 95 ctx = sc.getConfigContext(); 96 this.js = ServerBeansFactory.getJmsServiceBean(ctx); 97 } 98 list = new MQAddressList(this.js); 99 list.setup(); 104 } catch(ConfigException ce) { 106 throw handleException(ce); 107 } 108 } 109 110 public String getUrl() { 111 try { 112 return list.toString(); 113 } catch (Exception e) { 114 return null; 115 } 116 } 117 118 public static boolean isClustered() throws ConnectorRuntimeException { 119 try { 120 ConfigContext ctxt = ApplicationServer.getServerContext().getConfigContext(); 121 return ServerHelper.isServerClustered(ctxt, 122 ApplicationServer.getServerContext().getInstanceName()); 123 } catch (ConfigException e) { 124 throw handleException(e); 125 } 126 } 127 128 public String getJMSServiceType(){ 129 return this.js.getType(); 130 } 131 132 public MQAddressList getUrlList() { 133 return list; 134 } 135 136 public boolean getReconnectEnabled() { 137 return js.isReconnectEnabled(); 138 } 139 140 public String getReconnectInterval() { 141 return js.getReconnectIntervalInSeconds(); 142 } 143 144 public String getReconnectAttempts() { 145 return js.getReconnectAttempts(); 146 } 147 148 public String getAddressListIterations() { 149 return js.getAddresslistIterations(); 150 } 151 152 public String getAddressListBehaviour() { 153 return js.getAddresslistBehavior(); 154 } 155 156 public void setMdbContainerProperties(){ 157 com.sun.enterprise.config.serverbeans.MdbContainer mdbc = null; 158 try { 159 com.sun.enterprise.server.ServerContext sc = 160 com.sun.enterprise.server.ApplicationServer.getServerContext(); 161 162 mdbc = com.sun.enterprise.config.serverbeans.ServerBeansFactory. 163 getMdbContainerBean(sc.getConfigContext()); 164 165 } 166 catch (Exception e) { 167 _mdblogger.log(Level.WARNING, "containers.mdb.config_exception", 168 new Object []{e.getMessage()}); 169 if (_mdblogger.isLoggable(Level.FINE)) { 170 _mdblogger.log(Level.FINE, e.getClass().getName(), e); 171 } 172 } 173 174 if (mdbc != null) { 175 ElementProperty[] props = mdbc.getElementProperty(); 176 if (props != null) { 177 for (int i = 0; i < props.length; i++) { 178 ElementProperty p = props[i]; 179 if (p == null) continue; 180 String name = p.getName(); 181 if (name == null) continue; 182 try { 183 if (name.equals(propName_reconnect_enabled)) { 184 if (p.getValue() == null) continue; 185 reconnectEnabled = 186 Boolean.valueOf(p.getValue()).booleanValue(); 187 } 188 else if (name.equals 189 (propName_reconnect_delay_in_seconds)) { 190 try { 191 reconnectDelayInSeconds = 192 Integer.parseInt(p.getValue()); 193 } catch (Exception e) { 194 _mdblogger.log(Level.WARNING, 195 "containers.mdb.config_exception", 196 new Object []{e.getMessage()}); 197 } 198 } 199 else if (name.equals(propName_reconnect_max_retries)) { 200 try { 201 reconnectMaxRetries = 202 Integer.parseInt(p.getValue()); 203 } catch (Exception e) { 204 _mdblogger.log(Level.WARNING, 205 "containers.mdb.config_exception", 206 new Object []{e.getMessage()}); 207 } 208 } 209 else if (name.equals 210 (propName_cmt_max_runtime_exceptions)) { 211 try { 212 cmtMaxRuntimeExceptions = 213 Integer.parseInt(p.getValue()); 214 } catch (Exception e) { 215 _mdblogger.log(Level.WARNING, 216 "containers.mdb.config_exception", 217 new Object []{e.getMessage()}); 218 } 219 } 220 } catch (Exception e) { 221 _mdblogger.log(Level.WARNING, 222 "containers.mdb.config_exception", 223 new Object []{e.getMessage()}); 224 if (_mdblogger.isLoggable(Level.FINE)) { 225 _mdblogger.log(Level.FINE, e.getClass().getName(), e); 226 } 227 } 228 } 229 } 230 } 231 if (reconnectDelayInSeconds < 0) { 232 reconnectDelayInSeconds = DEFAULT_RECONNECT_DELAY; 233 } 234 if (reconnectMaxRetries < 0) { 235 reconnectMaxRetries = DEFAULT_RECONNECT_RETRIES; 236 } 237 if (_mdblogger.isLoggable(Level.FINE)) { 238 _mdblogger.log(Level.FINE, 239 propName_reconnect_delay_in_seconds+"="+ 240 reconnectDelayInSeconds +", "+ 241 propName_reconnect_max_retries+ "="+reconnectMaxRetries + ", "+ 242 propName_reconnect_enabled+"="+reconnectEnabled); 243 } 244 245 MdbContainerProps.setReconnectDelay(reconnectDelayInSeconds); 247 MdbContainerProps.setReconnectMaxRetries(reconnectMaxRetries); 248 MdbContainerProps.setReconnectEnabled(reconnectEnabled); 249 MdbContainerProps.setMaxRuntimeExceptions(cmtMaxRuntimeExceptions); 250 251 } 252 253 public void configureDescriptor(ConnectorDescriptor cd) { 254 255 Object [] envProps = cd.getConfigProperties().toArray(); 256 257 for (int i = 0; i < envProps.length; i++) { 258 EnvironmentProperty envProp = (EnvironmentProperty) envProps[i]; 259 String name = envProp.getName(); 260 if (!name.equals("ConnectionURL")) { 261 continue; 262 } 263 String userValue = getUrl(); 264 if (userValue != null) { 265 cd.removeConfigProperty(envProp); 266 cd.addConfigProperty(new EnvironmentProperty( 267 name, userValue, userValue, envProp.getType())); 268 } 269 270 } 271 272 } 273 274 279 public void upgradeIfNecessary() { 280 281 String installedMqVersion = null; 282 String deployedMqVersion = null; 283 284 try { 285 installedMqVersion = getInstalledMqVersion(); 286 _rarlogger.log(Level.FINE,"installedMQVersion :: " + installedMqVersion); 287 deployedMqVersion = getDeployedMqVersion(); 288 _rarlogger.log(Level.FINE,"deployedMQVersion :: " + deployedMqVersion); 289 }catch (Exception e) { 290 return; 291 } 292 293 String deployed_dir = 294 java.lang. System.getProperty(Constants.INSTALL_ROOT) 295 + File.separator + SYSTEM_APP_DIR + File.separator 296 + ConnectorConstants.DEFAULT_JMS_ADAPTER; 297 298 if (!installedMqVersion.equals(deployedMqVersion)) { 301 try { 302 _rarlogger.log(Level.INFO, "jmsra.upgrade_started" ); 303 ZipFile rarFile = new ZipFile(java.lang.System.getProperty 304 (Constants.INSTALL_IMQ_LIB) + 305 File.separator + MQ_RAR, deployed_dir); 306 rarFile.explode(); 307 _rarlogger.log(Level.INFO, "jmsra.upgrade_completed"); 308 } catch(ZipFileException ze) { 309 _rarlogger.log(Level.SEVERE,"jmsra.upgrade_failed",ze.getMessage()); 310 } 311 } 312 313 } 314 315 private String getInstalledMqVersion() throws Exception { 316 String ver = null; 317 String installed_dir = 319 java.lang.System.getProperty(Constants.INSTALL_IMQ_LIB); 320 String jarFile = installed_dir + File.separator + MQ_RAR; 321 _rarlogger.log(Level.FINE,"Installed MQ JAR " + jarFile); 322 323 try { 324 JarFile jFile = new JarFile(jarFile); 325 Manifest mf = jFile.getManifest(); 326 ver = mf.getMainAttributes().getValue(MANIFEST_TAG); 327 return ver; 328 } catch (Exception e) { 329 _rarlogger.log(Level.WARNING, "jmsra.upgrade_check_failed", 330 e.getMessage() + ":" + jarFile ); 331 throw e; 332 } 333 } 334 335 private String getDeployedMqVersion() throws Exception { 336 String ver = null; 337 String deployed_dir = 339 java.lang.System.getProperty(Constants.INSTALL_ROOT) 340 + File.separator + SYSTEM_APP_DIR; 341 String manifestFile = deployed_dir + File.separator + 342 MQ_RAR_MANIFEST; 343 _rarlogger.log(Level.FINE,"Deployed MQ version Manifest file" + manifestFile); 344 try { 345 Manifest mf = new Manifest(new FileInputStream(manifestFile)); 346 ver = mf.getMainAttributes().getValue(MANIFEST_TAG); 347 return ver; 348 } catch (Exception e) { 349 _rarlogger.log(Level.WARNING, "jmsra.upgrade_check_failed", 350 e.getMessage() + ":" + manifestFile ); 351 throw e; 352 } 353 } 354 355 private static ConnectorRuntimeException handleException(Exception e) { 356 ConnectorRuntimeException cre = 357 new ConnectorRuntimeException(e.getMessage()); 358 cre.initCause(e); 359 return cre; 360 } 361 } 362 | Popular Tags |