Search in sources :

Example 6 with HASipDialog

use of org.mobicents.ha.javax.sip.HASipDialog in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method putSIPDialog.

public void putSIPDialog(SIPDialog dialog) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logStackTrace();
    }
    final HASipDialog haSipDialog = (HASipDialog) dialog;
    final String dialogId = haSipDialog.getDialogIdToReplicate();
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug("put HA SIP Dialog " + dialog + " with dialog " + dialogId);
    }
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    TransactionManager transactionManager = jbossCache.getConfiguration().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;
        }
        final Node childNode = getNode().addChild(Fqn.fromElements(dialogId));
        for (Entry<String, Object> metaData : haSipDialog.getMetaDataToReplicate().entrySet()) {
            childNode.put(metaData.getKey(), metaData.getValue());
        }
        final Object dialogAppData = haSipDialog.getApplicationDataToReplicate();
        if (dialogAppData != null) {
            childNode.put(APPDATA, dialogAppData);
        }
    } 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 : HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog) TransactionManager(javax.transaction.TransactionManager) Node(org.jboss.cache.Node) RollbackException(javax.transaction.RollbackException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) Cache(org.jboss.cache.Cache) MobicentsCache(org.mobicents.cache.MobicentsCache)

Example 7 with HASipDialog

use of org.mobicents.ha.javax.sip.HASipDialog in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method putDialog.

public void putDialog(SIPDialog dialog) throws SipCacheException {
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_TRACE)) {
        clusteredlogger.logDebug("putDialog(" + dialog.getDialogId() + ")");
    }
    final HASipDialog haSipDialog = (HASipDialog) dialog;
    Object dialogMetaData = haSipDialog.getMetaDataToReplicate();
    if (dialogMetaData != null) {
        if (dialogs.containsKey(dialog.getDialogId())) {
            Map<String, Object> cachedMetaData = (Map<String, Object>) dialogs.get(dialog.getDialogId());
            Long currentVersion = (Long) ((Map<String, Object>) dialogMetaData).get(AbstractHASipDialog.VERSION);
            Long cacheVersion = (Long) ((Map<String, Object>) cachedMetaData).get(AbstractHASipDialog.VERSION);
            if (cacheVersion.longValue() < currentVersion.longValue()) {
                for (Entry<String, Object> e : ((Map<String, Object>) dialogMetaData).entrySet()) {
                    cachedMetaData.put(e.getKey(), e.getValue());
                }
                dialogs.replace(dialog.getDialogId(), cachedMetaData);
            }
        } else {
            dialogs.put(dialog.getDialogId(), dialogMetaData);
        }
    }
    Object dialogAppData = haSipDialog.getApplicationDataToReplicate();
    if (dialogAppData != null) {
        if (appDataMap.containsKey(dialog.getDialogId()))
            appDataMap.replace(dialog.getDialogId(), dialogAppData);
        else
            appDataMap.put(dialog.getDialogId(), dialogAppData);
    }
}
Also used : HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 8 with HASipDialog

use of org.mobicents.ha.javax.sip.HASipDialog in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method createDialog.

private HASipDialog createDialog(String dialogId, Map<String, Object> dialogMetaData, Object dialogAppData) throws SipCacheException {
    HASipDialog haSipDialog = null;
    if (dialogMetaData != null) {
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("sipStack " + this + " dialog " + dialogId + " is present in the distributed cache, recreating it locally");
        }
        final String lastResponseStringified = (String) dialogMetaData.get(AbstractHASipDialog.LAST_RESPONSE);
        try {
            final SIPResponse lastResponse = (SIPResponse) SipFactory.getInstance().createMessageFactory().createResponse(lastResponseStringified);
            haSipDialog = HASipDialogFactory.createHASipDialog(stack.getReplicationStrategy(), (SipProviderImpl) stack.getSipProviders().next(), lastResponse);
            haSipDialog.setDialogId(dialogId);
            updateDialogMetaData(dialogMetaData, dialogAppData, haSipDialog, true);
            // setLastResponse won't be called on recreation since version will be null on recreation
            haSipDialog.setLastResponse(lastResponse);
            if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                clusteredlogger.logDebug("HA SIP Dialog " + dialogId + " localTag  = " + haSipDialog.getLocalTag());
                clusteredlogger.logDebug("HA SIP Dialog " + dialogId + " remoteTag  = " + haSipDialog.getRemoteTag());
                clusteredlogger.logDebug("HA SIP Dialog " + dialogId + " localParty = " + haSipDialog.getLocalParty());
                clusteredlogger.logDebug("HA SIP Dialog " + dialogId + " remoteParty  = " + haSipDialog.getRemoteParty());
                clusteredlogger.logDebug("HA SIP Dialog " + dialogId + " state  = " + ((SIPDialog) haSipDialog).getState());
            }
        } catch (PeerUnavailableException e) {
            throw new SipCacheException("A problem occured while retrieving the following dialog " + dialogId + " from the Cache", e);
        } catch (ParseException e) {
            throw new SipCacheException("A problem occured while retrieving the following dialog " + dialogId + " from the Cache", e);
        }
    }
    return haSipDialog;
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) SipProviderImpl(gov.nist.javax.sip.SipProviderImpl) 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) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) ParseException(java.text.ParseException)

Example 9 with HASipDialog

use of org.mobicents.ha.javax.sip.HASipDialog in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method updateDialog.

public void updateDialog(SIPDialog dialog) throws SipCacheException {
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        clusteredlogger.logDebug("updateDialog(" + dialog.getDialogId() + ")");
    final HASipDialog haSipDialog = (HASipDialog) dialog;
    final Object dialogMetaData = dialogs.get(dialog.getDialogId());
    final Object dialogAppData = appDataMap.get(dialog.getDialogId());
    updateDialog(haSipDialog, (Map<String, Object>) dialogMetaData, dialogAppData);
}
Also used : HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog)

Example 10 with HASipDialog

use of org.mobicents.ha.javax.sip.HASipDialog in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method updateDialog.

public void updateDialog(SIPDialog dialog) throws SipCacheException {
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        clusteredlogger.logDebug("updateDialog(" + dialog.getDialogId() + ")");
    final HASipDialog haSipDialog = (HASipDialog) dialog;
    final Object dialogMetaData = getDialogs().get(dialog.getDialogId());
    final Object dialogAppData = getAppDataMap().get(dialog.getDialogId());
    updateDialog(haSipDialog, (Map<String, Object>) dialogMetaData, dialogAppData);
}
Also used : HASipDialog(org.mobicents.ha.javax.sip.HASipDialog) AbstractHASipDialog(gov.nist.javax.sip.stack.AbstractHASipDialog)

Aggregations

AbstractHASipDialog (gov.nist.javax.sip.stack.AbstractHASipDialog)10 HASipDialog (org.mobicents.ha.javax.sip.HASipDialog)10 ParseException (java.text.ParseException)6 PeerUnavailableException (javax.sip.PeerUnavailableException)6 SipProviderImpl (gov.nist.javax.sip.SipProviderImpl)3 SIPResponse (gov.nist.javax.sip.message.SIPResponse)3 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)3 RollbackException (javax.transaction.RollbackException)3 TransactionManager (javax.transaction.TransactionManager)3 Cache (org.jboss.cache.Cache)3 CacheException (org.jboss.cache.CacheException)3 MobicentsCache (org.mobicents.cache.MobicentsCache)3 Map (java.util.Map)2 Configuration (org.jboss.cache.config.Configuration)2 SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)2 IMap (com.hazelcast.core.IMap)1 Node (org.jboss.cache.Node)1