Search in sources :

Example 1 with Configuration

use of org.jboss.cache.config.Configuration in project jain-sip.ha by RestComm.

the class ClientTransactionCacheData method getClientTransaction.

public SIPClientTransaction getClientTransaction(String txId) throws SipCacheException {
    SIPClientTransaction haSipClientTransaction = null;
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    Configuration config = jbossCache.getConfiguration();
    final boolean isBuddyReplicationEnabled = config.getBuddyReplicationConfig() != null && config.getBuddyReplicationConfig().isEnabled();
    TransactionManager transactionManager = config.getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        // Adding code to handle Buddy replication to force data gravitation
        if (isBuddyReplicationEnabled) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("forcing data gravitation since buddy replication is enabled");
            }
            jbossCache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
        }
        final Node<String, Object> childNode = getNode().getChild(txId);
        if (childNode != null) {
            try {
                final Map<String, Object> transactionMetaData = childNode.getData();
                final Object dialogAppData = childNode.get(APPDATA);
                haSipClientTransaction = createClientTransaction(txId, transactionMetaData, dialogAppData);
            } catch (CacheException e) {
                throw new SipCacheException("A problem occured while retrieving the following client transaction " + txId + " from the Cache", e);
            }
        } else {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("no child node found for transactionId " + txId);
            }
        }
    } catch (Exception ex) {
        try {
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            logger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                logger.logWarning("endBatch(): rolling back transaction with exception: " + re);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
            }
        }
    }
    return haSipClientTransaction;
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) Configuration(org.jboss.cache.config.Configuration) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) IOException(java.io.IOException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) TransactionManager(javax.transaction.TransactionManager) MobicentsCache(org.mobicents.cache.MobicentsCache) Cache(org.jboss.cache.Cache)

Example 2 with Configuration

use of org.jboss.cache.config.Configuration in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method getSIPDialog.

public SIPDialog getSIPDialog(String dialogId) throws SipCacheException {
    HASipDialog haSipDialog = null;
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    Configuration config = jbossCache.getConfiguration();
    final boolean isBuddyReplicationEnabled = config.getBuddyReplicationConfig() != null && config.getBuddyReplicationConfig().isEnabled();
    TransactionManager transactionManager = config.getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        // Adding code to handle Buddy replication to force data gravitation
        if (isBuddyReplicationEnabled) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("forcing data gravitation since buddy replication is enabled");
            }
            jbossCache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
        }
        final Node<String, Object> childNode = getNode().getChild(dialogId);
        if (childNode != null) {
            try {
                final Map<String, Object> dialogMetaData = childNode.getData();
                final Object dialogAppData = childNode.get(APPDATA);
                haSipDialog = createDialog(dialogId, dialogMetaData, dialogAppData);
            } catch (CacheException e) {
                throw new SipCacheException("A problem occured while retrieving the following dialog " + dialogId + " from the Cache", e);
            }
        }
    } catch (Exception ex) {
        try {
            logger.logError("Problem taking dialog from cache. We will try to rollback the transction is any.", ex);
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            logger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                logger.logWarning("endBatch(): rolling back transaction with exception: " + re);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
            }
        }
    }
    return (SIPDialog) haSipDialog;
}
Also used : Configuration(org.jboss.cache.config.Configuration) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog) SIPDialog(gov.nist.javax.sip.stack.SIPDialog) TransactionManager(javax.transaction.TransactionManager) Cache(org.jboss.cache.Cache) MobicentsCache(org.mobicents.cache.MobicentsCache)

Example 3 with Configuration

use of org.jboss.cache.config.Configuration in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method updateSIPDialog.

/*
	 * (non-Javadoc)
	 * @see org.mobicents.ha.javax.sip.cache.SipCache#updateDialog(gov.nist.javax.sip.stack.SIPDialog)
	 */
public void updateSIPDialog(SIPDialog sipDialog) throws SipCacheException {
    final String dialogId = sipDialog.getDialogId();
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    Configuration config = jbossCache.getConfiguration();
    final boolean isBuddyReplicationEnabled = config.getBuddyReplicationConfig() != null && config.getBuddyReplicationConfig().isEnabled();
    TransactionManager transactionManager = config.getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        // Adding code to handle Buddy replication to force data gravitation
        if (isBuddyReplicationEnabled) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("forcing data gravitation since buddy replication is enabled");
            }
            jbossCache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
        }
        final Node<String, Object> childNode = getNode().getChild(dialogId);
        if (childNode != null) {
            try {
                final Map<String, Object> dialogMetaData = childNode.getData();
                final HASipDialog haSipDialog = (HASipDialog) sipDialog;
                final Object dialogAppData = childNode.get(APPDATA);
                updateDialog(haSipDialog, dialogMetaData, dialogAppData);
            } catch (CacheException e) {
                throw new SipCacheException("A problem occured while retrieving the following dialog " + dialogId + " from the Cache", e);
            }
        }
    } catch (Exception ex) {
        try {
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            logger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                logger.logWarning("endBatch(): rolling back transaction with exception: " + re);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
            }
        }
    }
}
Also used : Configuration(org.jboss.cache.config.Configuration) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog) TransactionManager(javax.transaction.TransactionManager) Cache(org.jboss.cache.Cache) MobicentsCache(org.mobicents.cache.MobicentsCache)

Example 4 with Configuration

use of org.jboss.cache.config.Configuration in project jain-sip.ha by RestComm.

the class ServerTransactionCacheData method getServerTransaction.

public SIPServerTransaction getServerTransaction(String txId) throws SipCacheException {
    SIPServerTransaction haSipServerTransaction = null;
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    Configuration config = jbossCache.getConfiguration();
    final boolean isBuddyReplicationEnabled = config.getBuddyReplicationConfig() != null && config.getBuddyReplicationConfig().isEnabled();
    TransactionManager transactionManager = config.getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                clusteredlogger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        // Adding code to handle Buddy replication to force data gravitation
        if (isBuddyReplicationEnabled) {
            if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                clusteredlogger.logDebug("forcing data gravitation since buddy replication is enabled");
            }
            jbossCache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
        }
        final Node<String, Object> childNode = getNode().getChild(txId);
        if (childNode != null) {
            try {
                final Map<String, Object> transactionMetaData = childNode.getData();
                final Object dialogAppData = childNode.get(APPDATA);
                haSipServerTransaction = createServerTransaction(txId, transactionMetaData, dialogAppData);
            } catch (CacheException e) {
                throw new SipCacheException("A problem occured while retrieving the following server transaction " + txId + " from the Cache", e);
            }
        } else {
            if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                clusteredlogger.logDebug("no child node found for transactionId " + txId);
            }
        }
    } catch (Exception ex) {
        try {
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            clusteredlogger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        clusteredlogger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        clusteredlogger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                clusteredlogger.logWarning("endBatch(): rolling back transaction with exception: " + re);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
            }
        }
    }
    return haSipServerTransaction;
}
Also used : Configuration(org.jboss.cache.config.Configuration) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) IOException(java.io.IOException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) TransactionManager(javax.transaction.TransactionManager) MobicentsCache(org.mobicents.cache.MobicentsCache) Cache(org.jboss.cache.Cache)

Aggregations

ParseException (java.text.ParseException)4 PeerUnavailableException (javax.sip.PeerUnavailableException)4 RollbackException (javax.transaction.RollbackException)4 TransactionManager (javax.transaction.TransactionManager)4 Cache (org.jboss.cache.Cache)4 CacheException (org.jboss.cache.CacheException)4 Configuration (org.jboss.cache.config.Configuration)4 MobicentsCache (org.mobicents.cache.MobicentsCache)4 AbstractHASipDialog (gov.nist.javax.sip.stack.AbstractHASipDialog)2 IOException (java.io.IOException)2 HASipDialog (org.mobicents.ha.javax.sip.HASipDialog)2 MobicentsHASIPClientTransaction (gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction)1 MobicentsHASIPServerTransaction (gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction)1 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)1 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1