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);
}
}
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations