public static boolean isRetryableException(Throwable th) { if (th == null) { Log.debug(Log.FRAMEWORK, "isRetryableException Unknown exception !"); return false; } else if (th instanceof JMSException) { Log.debug(Log.FRAMEWORK, "isRetryableException JMSException detected."); return true; } else if (th instanceof NameNotFoundException) { Log.debug(Log.FRAMEWORK, "isRetryableException: NameNotFoundException catched"); return true; } else if (th instanceof NestingException) { NestingException nex = (NestingException) th; Class nextedExceptionClass = nex.getNestedExceptionClass(); if (NameNotFoundException.class .getSimpleName() .equals(nextedExceptionClass.getSimpleName())) { Log.debug( Log.FRAMEWORK, "isRetryableException: GT nestedException: NameNotFoundException catched"); return true; } else if (JMSException.class.getSimpleName().equals(nextedExceptionClass.getSimpleName())) { Log.debug(Log.FRAMEWORK, "isRetryableException: GT nestedException: JMSException catched"); return true; } else { return false; } } else { Throwable ex = th.getCause(); return isRetryableException(ex); } }
/** * Send the JMS message (under new transaction) with Retry mechanism enable when encounter JMS * related error * * @param destName * @param msgObj * @param msgProps * @param jmsSendProps * @param isLocal * @throws Throwable */ public static void sendMessage( String destName, Serializable msgObj, Hashtable msgProps, Hashtable<String, String> jmsSendProps, boolean isLocal) throws Throwable { boolean isRetryEnabled = _retryCount <= 0 ? false : true; int retryCount = _retryCount; Throwable th1 = null; do { try { sendJMS(isLocal, jmsSendProps, destName, msgObj, msgProps); retryCount = -10; } catch (Throwable th) { if (isRetryableException(th) && isRetryEnabled) { Log.warn( Log.FRAMEWORK, "sendMessageWithRetry: JMS exception found. Reconnect after " + _sleepFor / 1000 + " num retry left: " + retryCount, th); try { Thread.sleep(_sleepFor); } catch (Exception ex) { } Log.debug(Log.FRAMEWORK, "sendMessageWithRetry: JMS exception catched: wake up !"); th1 = new JMSFailureException(th); } else { Log.warn( Log.FRAMEWORK, "sendMessageWithRetry: Non Retryable exception found. No retry will be performed.", th); throw th; } } } while (retryCount-- > 0); if (isRetryEnabled && retryCount == -1 && th1 != null) { Log.debug( Log.FRAMEWORK, "sendMessageWithRetry: JMS retry exhausted. exception is: " + th1.getMessage(), th1); throw th1; } }
/** * Send the JMS message (under new transaction) with Retry mechanism enable when encounter JMS * related error. If the retry count has exceeded, that JMS will be stored into DB for later * retry. * * @param configName The JMS properties config name * @param destName * @param msgObj * @param msgProps * @throws Throwable */ public static void sendMessageWithPersist( String configName, String destName, Serializable msgObj, Hashtable msgProps) throws Throwable { boolean isRetryEnabled = _retryCount <= 0 ? false : true; int retryCount = _retryCount; Throwable th1 = null; do { try { getJMSMgr().sendMessage(configName, destName, msgObj, msgProps); retryCount = -10; } catch (Throwable th) { if (isRetryableException(th) && isRetryEnabled) { Log.warn( Log.FRAMEWORK, "Send: JMS exception found. Reconnect after " + _sleepFor / 1000 + " num retry left: " + retryCount, th); try { Thread.sleep(_sleepFor); } catch (Exception ex) { } Log.debug(Log.FRAMEWORK, "Send: JMS exception catched: wake up !"); th1 = th; } else { Log.warn( Log.FRAMEWORK, "Send: Non Retryable exception found. No retry will be performed.", th); throw th; } } } while (retryCount-- > 0); if (isRetryEnabled && retryCount == -1 && th1 != null) { Log.debug(Log.FRAMEWORK, "Send: JMS retry exhausted. exception is: " + th1.getMessage(), th1); dumpFailedJMS( JMS_DEST_TYPE_QUEUE, getJmsSetupPropsKey(configName), destName, msgObj, msgProps); } }
/** * Broadcast the JMS msg under a new transaction. It will perform retry if encoutner retryable * exception. If exceed the max retry, exception will be propageted up. * * @param notification * @throws Exception */ public static void broadcastInNewTrans(INotification notification) throws Exception { boolean isRetryEnabled = _retryCount <= 0 ? false : true; int retryCount = _retryCount; Exception ex1 = null; do { try { getLocalNotifierMgr().broadCastNotification(notification); retryCount = -10; } catch (Exception ex) { if (isRetryEnabled && isRetryableException(ex)) { ex1 = new JMSFailureException(ex); Log.warn( Log.FRAMEWORK, "Broadcast: JMS exception found. Reconnect after " + _sleepFor / 1000 + " num retry left: " + retryCount, ex); try { Thread.sleep(_sleepFor); } catch (Exception e) { } Log.debug(Log.FRAMEWORK, "Broadcast: JMS exception catched: wake up !"); } else { Log.warn( Log.FRAMEWORK, "Broadcast: Non Retryable exception found. No retry will be performed.", ex); throw ex; } } } while (retryCount-- > 0); if (isRetryEnabled && retryCount == -1 && ex1 != null) { Log.debug(Log.FRAMEWORK, "Broadcast: JMS retry send exhausted. Throw up ex.", ex1); throw ex1; } }
/** * Add an EntityMetaInfo into the factory. This does not add it to the database. If there is * existing EntityMetaInfo cached with the same ObjectName/EntityName, it will be replaced by this * metaInfo. * * @param metaInfo The EntityMetaInfo to add to the factory. */ public void addEntityMetaInfo(EntityMetaInfo metaInfo) { _entityMap.put(metaInfo.getObjectName(), metaInfo); Log.debug( Log.DB, "[MetaInfoFactory.addEntityMetaInfo] " + "Add mapping for EntityName " + metaInfo.getEntityName() + " to ObjectName " + metaInfo.getObjectName()); _entityNameMap.put(metaInfo.getEntityName(), metaInfo.getObjectName()); }
private static void sendJMS( boolean isLocal, Hashtable jmsSendProps, String destName, Serializable msgObj, Hashtable<String, String> msgProps) throws Exception { Log.debug(Log.FRAMEWORK, "sendJMS: isRemote:" + isLocal); if (!isLocal) { getRemoteJMSMgr().sendMessage(jmsSendProps, destName, msgObj, msgProps); } else { getJMSMgr().sendMessage(jmsSendProps, destName, msgObj, msgProps); } }
private static void dumpFailedJMS( String destType, Hashtable<String, String> configProps, String destName, Serializable msgObj, Hashtable msgProps) throws Exception { JMSFailedMsg failedMsg = new JMSFailedMsg(destType, configProps, destName, msgObj, msgProps); // use DB try { Log.debug(Log.FRAMEWORK, "Persist failed jms to DB. Failed JMS: " + failedMsg); JMSFailedMsgHelper helper = JMSFailedMsgHelper.getInstance(); helper.persistFailedJMSMsg(failedMsg); } catch (Exception ex) { Log.error("", Log.FRAMEWORK, "Failed to persist the failed jms to DB.", ex); throw ex; } }
private static Hashtable<String, String> getJmsSetupPropsKey(String configName) throws ApplicationException { Configuration config = ConfigurationManager.getInstance().getConfig(configName); Properties prop = config.getProperties(); Log.debug(Log.FRAMEWORK, "getJmsSetupPropsKey: " + prop); if (prop != null && prop.size() == 0) { throw new ApplicationException( "No properties file can be found given configName: " + configName); } Hashtable<String, String> configProps = new Hashtable<String, String>(); Enumeration keys = prop.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); configProps.put(key, (String) prop.get(key)); } return configProps; }
public static void debug(String msg, Throwable ex) { Log.debug(CATEGORY, msg, ex); }
public static void debug(Object msg) { Log.debug(CATEGORY, msg); }
/** * Broadcast the notification under a new transaction. Whenever encouter JMS retryable error, it * will perform retry until max retry has reached. If it happen, the JMS msg will be stored in the * DB. * * @param notification * @throws Exception */ public static void broadcastWithPersist(INotification notification) throws Exception { boolean isRetryEnabled = _retryCount <= 0 ? false : true; int retryCount = _retryCount; Exception ex1 = null; do { try { getLocalNotifierMgr().broadCastNotification(notification); retryCount = -10; } catch (Exception ex) { if (isRetryEnabled && isRetryableException(ex)) { ex1 = ex; Log.warn( Log.FRAMEWORK, "Broadcast: JMS exception found. Reconnect after " + _sleepFor / 1000 + " num retry left: " + retryCount, ex); try { Thread.sleep(_sleepFor); } catch (Exception e) { } Log.debug(Log.FRAMEWORK, "Broadcast: JMS exception catched: wake up !"); } else { Log.warn( Log.FRAMEWORK, "Broadcast: Non Retryable exception found. No retry will be performed.", ex); throw ex; } } } while (retryCount-- > 0); if (isRetryEnabled && retryCount == -1 && ex1 != null) { Log.debug( Log.FRAMEWORK, "Broadcast: JMS retry send exhausted. Dumping the out JMS message for later retry.", ex1); Hashtable<String, String> msgProps = new Hashtable<String, String>(); msgProps.put("id", notification.getNotificationID()); msgProps.put(SystemUtil.HOSTID_PROP_KEY, SystemUtil.getHostId()); String[] properties = notification.getPropertyKeys(); for (int i = 0; i < properties.length; i++) { Log.debug( Log.FRAMEWORK, "Broadcast: Adding msg props : key: " + properties[i] + " value: " + notification.getProperty(properties[i])); msgProps.put(properties[i], notification.getProperty(properties[i])); } // debug Hashtable<String, String> jmsConfigProps = Notifier.getInstance().getJmsSetupPropsKey(); Log.debug(Log.FRAMEWORK, "JMSConfigProps is: " + jmsConfigProps); String destName = jmsConfigProps.get(JMSSender.JMS_DEST_NAME); dumpFailedJMS( JMS_DEST_TYPE_TOPIC, Notifier.getInstance().getJmsSetupPropsKey(), destName, notification, msgProps); } }