use of org.mobicents.ha.javax.sip.cache.SipCacheException in project jain-sip.ha by RestComm.
the class ClusteredSipStackImpl method getDialog.
/*
* (non-Javadoc)
* @see gov.nist.javax.sip.stack.SIPTransactionStack#getDialog(java.lang.String)
*/
@Override
public SIPDialog getDialog(String dialogId) {
if (sipCache.inLocalMode()) {
return super.getDialog(dialogId);
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("checking if the dialog " + dialogId + " is present in the local cache");
}
SIPDialog sipDialog = super.getDialog(dialogId);
int nbToken = new StringTokenizer(dialogId, Separators.COLON).countTokens();
// there can be more than 3 tokens if the callid part of the dialog id contains a COLON as well
if (nbToken >= 3) {
if (sipDialog == null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("local dialog " + dialogId + " is null, checking in the distributed cache");
}
sipDialog = getDialogFromDistributedCache(dialogId);
if (sipDialog != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("dialog " + dialogId + " found in the distributed cache, storing it locally");
}
SIPDialog existingDialog = super.putDialog(sipDialog);
// the dialog after failover, we use the one that won the race
if (existingDialog != null) {
sipDialog = existingDialog;
}
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("dialog " + dialogId + " not found in the distributed cache");
}
}
} else {
// we check for updates only if the dialog is confirmed
if (sipDialog.getState() == DialogState.CONFIRMED) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("local dialog " + dialogId + " is present locally " + sipDialog + " checking if it needs to be updated from the cache");
}
try {
sipCache.updateDialog(sipDialog);
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem updating dialog " + dialogId + " from the distributed cache", e);
}
}
}
}
return sipDialog;
}
}
use of org.mobicents.ha.javax.sip.cache.SipCacheException in project jain-sip.ha by RestComm.
the class ClusteredSipStackImpl method findTransaction.
/*
* (non-Javadoc)
* @see gov.nist.javax.sip.stack.SIPTransactionStack#findTransaction(java.lang.String, boolean)
*/
@Override
public SIPTransaction findTransaction(String transactionId, boolean isServer) {
if (sipCache.inLocalMode() || replicationStrategy != ReplicationStrategy.EarlyDialog) {
return super.findTransaction(transactionId, isServer);
}
final String txId = transactionId.toLowerCase();
SIPTransaction sipTransaction = super.findTransaction(txId, isServer);
if (sipTransaction == null && transactionFactory != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("local transaction " + txId + " server = " + isServer + " is null, checking in the distributed cache");
}
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " checking if the transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
if (isServer) {
// fetch the corresponding server transaction from the cache instance
try {
sipTransaction = sipCache.getServerTransaction(txId);
if (sipTransaction != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
SIPServerTransaction retval = serverTransactionTable.putIfAbsent(txId, (SIPServerTransaction) sipTransaction);
if (retval != null) {
sipTransaction = retval;
}
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is not present in the distributed cache");
}
}
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem getting transaction " + txId + " server = " + isServer + " from the distributed cache", e);
}
} else {
// fetch the corresponding client transaction from the cache instance
try {
sipTransaction = sipCache.getClientTransaction(txId);
if (sipTransaction != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
SIPClientTransaction retval = clientTransactionTable.putIfAbsent(txId, (SIPClientTransaction) sipTransaction);
if (retval != null) {
sipTransaction = retval;
} else {
// start the transaction timer only when the transaction has been added to the stack
// to avoid leaks on retransmissions
((MobicentsHASIPClientTransaction) sipTransaction).startTransactionTimerOnFailover();
}
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is not present in the distributed cache");
}
}
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem getting transaction " + txId + " server = " + isServer + " from the distributed cache", e);
}
}
}
return sipTransaction;
}
use of org.mobicents.ha.javax.sip.cache.SipCacheException in project jain-sip.ha by RestComm.
the class ConfirmedNoAppDataReplicationSipDialog method replicateState.
/*
*
*/
protected void replicateState() {
final DialogState dialogState = getState();
final ReplicationStrategy replicationStrategy = ((ClusteredSipStack) getStack()).getReplicationStrategy();
boolean replicationStateVsDialogStateOK = false;
if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
logger.logDebug("dialogState = " + dialogState + ", replicationStrategy = " + replicationStrategy);
}
if (dialogState == DialogState.CONFIRMED && (replicationStrategy == ReplicationStrategy.ConfirmedDialog || replicationStrategy == ReplicationStrategy.ConfirmedDialogNoApplicationData)) {
replicationStateVsDialogStateOK = true;
}
if ((dialogState == DialogState.EARLY || dialogState == DialogState.CONFIRMED || // Added as part of https://github.com/Mobicents/jain-sip.ha/pull/1
dialogState == DialogState.TERMINATED) && replicationStrategy == ReplicationStrategy.EarlyDialog) {
replicationStateVsDialogStateOK = true;
}
if (replicationStateVsDialogStateOK && isCreated && super.dialogId != null && isRemoteTagSet() && isLocalTagSet() && getStack().getDialog(getDialogIdToReplicate()) != null) {
try {
((ClusteredSipStack) getStack()).getSipCache().putDialog(this);
} catch (SipCacheException e) {
logger.logError("problem storing dialog " + getDialogId() + " into the distributed cache", e);
}
}
}
use of org.mobicents.ha.javax.sip.cache.SipCacheException in project jain-sip.ha by RestComm.
the class MobicentsHASIPServerTransaction method sendMessage.
@Override
public void sendMessage(SIPMessage message) throws IOException {
final SIPResponse response = (SIPResponse) message;
if (response != null && Request.INVITE.equals(getMethod()) && response.getStatusCode() > 100 && response.getStatusCode() < 200) {
this.localDialogId = response.getDialogId(true);
if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
logger.logDebug(transactionId + " : local dialog Id " + localDialogId);
}
if (isReliable()) {
this.peerReliablePort = ((ResponseExt) response).getTopmostViaHeader().getPort();
if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
logger.logDebug(transactionId + " : peer Reliable Port " + peerReliablePort);
}
}
// store the tx when the response will be sent
try {
((ClusteredSipStack) sipStack).getSipCache().putServerTransaction(this);
} catch (SipCacheException e) {
logger.logError("problem storing server transaction " + transactionId + " into the distributed cache", e);
}
}
super.sendMessage(message);
}
use of org.mobicents.ha.javax.sip.cache.SipCacheException in project jain-sip.ha by RestComm.
the class SIPDialogCacheData method updateDialog.
public void updateDialog(HASipDialog haSipDialog, Map<String, Object> dialogMetaData, Object dialogAppData) throws SipCacheException {
if (dialogMetaData != null) {
final long currentVersion = haSipDialog.getVersion();
final Long cacheVersion = ((Long) dialogMetaData.get(AbstractHASipDialog.VERSION));
if (cacheVersion != null && currentVersion < cacheVersion.longValue()) {
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("HA SIP Dialog " + haSipDialog + " with dialogId " + haSipDialog.getDialogIdToReplicate() + " is older " + currentVersion + " than the one in the cache " + cacheVersion + " updating it");
}
try {
final String lastResponseStringified = (String) dialogMetaData.get(AbstractHASipDialog.LAST_RESPONSE);
final SIPResponse lastResponse = (SIPResponse) SipFactory.getInstance().createMessageFactory().createResponse(lastResponseStringified);
haSipDialog.setLastResponse(lastResponse);
updateDialogMetaData(dialogMetaData, dialogAppData, haSipDialog, false);
} catch (PeerUnavailableException e) {
throw new SipCacheException("A problem occured while retrieving the following dialog " + haSipDialog.getDialogIdToReplicate() + " from the TreeCache", e);
} catch (ParseException e) {
throw new SipCacheException("A problem occured while retrieving the following dialog " + haSipDialog.getDialogIdToReplicate() + " from the TreeCache", e);
}
} else {
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("HA SIP Dialog " + haSipDialog + " with dialogId " + haSipDialog.getDialogIdToReplicate() + " is not older " + currentVersion + " than the one in the cache " + cacheVersion + ", not updating it");
}
}
}
}
Aggregations