core/src/main/java/org/mobicents/ha/javax/sip/ClusteredSipStackImpl.java
@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();
			// we should only check the cache for dialog Id where the remote tag is set since we support only established dialog failover
			// Issue 1378 : http://code.google.com/p/restcomm/issues/detail?id=1378
			// 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);
						// avoid returning wrong dialog if 2 threads try to recreate
						// 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;
		}
	}
@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();
			// we should only check the cache for dialog Id where the remote tag is set since we support only established dialog failover
			// Issue 1378 : http://code.google.com/p/restcomm/issues/detail?id=1378
			// 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);
						// avoid returning wrong dialog if 2 threads try to recreate
						// 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;
		}
	}
@ 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 ( ) ; // we should only check the cache for dialog Id where the remote tag is set since we support only established dialog failover // Issue 1378 : http://code.google.com/p/restcomm/issues/detail?id=1378 // 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 ) ; // avoid returning wrong dialog if 2 threads try to recreate // 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 ; } }
/*
(non-Javadoc)
@see gov.nist.javax.sip.stack.SIPTransactionStack#getDialog(java.lang.String)
/ * ( non - Javadoc )