Search in sources :

Example 1 with ReplicationStrategy

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

the class AbstractHASipDialog method setState.

@Override
public void setState(int state) {
    DialogState oldState = this.getState();
    super.setState(state);
    final ReplicationStrategy replicationStrategy = ((ClusteredSipStack) getStack()).getReplicationStrategy();
    if (replicationStrategy == ReplicationStrategy.EarlyDialog && (oldState == null || oldState.getValue() != state)) {
        dialogStateChanged = true;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("dialogStateChanged");
        }
    }
}
Also used : DialogState(javax.sip.DialogState) ReplicationStrategy(org.mobicents.ha.javax.sip.ReplicationStrategy) ClusteredSipStack(org.mobicents.ha.javax.sip.ClusteredSipStack)

Example 2 with ReplicationStrategy

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

the class AbstractHASipDialog method setLastResponse.

@Override
public void setLastResponse(SIPTransaction transaction, SIPResponse sipResponse) {
    // version can be null on dialog recreation
    if (version != null) {
        boolean lastResponseChanged = false;
        long previousVersion = version.get();
        // for 2xx w/o 1xx
        final ReplicationStrategy replicationStrategy = ((ClusteredSipStack) getStack()).getReplicationStrategy();
        // set to confirmed dialog strategy at least
        int lowerStatusCodeToReplicateOn = 200;
        if (replicationStrategy == ReplicationStrategy.EarlyDialog) {
            lowerStatusCodeToReplicateOn = 101;
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(dialogId + " lowerStatusCodeToReplicateOn = " + lowerStatusCodeToReplicateOn);
            logger.logDebug(dialogId + " lastResponseStr = " + lastResponseStringified);
            logger.logDebug(dialogId + " sipResponse = " + sipResponse);
        }
        if (sipResponse != null && getLastResponseStringified() == null && sipResponse.getStatusCode() >= lowerStatusCodeToReplicateOn) {
            lastResponseChanged = true;
        }
        String responseStringified = sipResponse.toString();
        if (sipResponse != null && getLastResponseStringified() != null && sipResponse.getStatusCode() >= lowerStatusCodeToReplicateOn && !responseStringified.equals(this.getLastResponseStringified())) {
            lastResponseChanged = true;
        }
        super.setLastResponse(transaction, sipResponse);
        lastResponseStringified = responseStringified;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(dialogId + " lastResponseChanged = " + lastResponseChanged);
            logger.logDebug(dialogId + " previousVersion = " + previousVersion);
            logger.logDebug(dialogId + " currentVersion = " + version.get());
        }
        // we replicate only if the version is the same, otherwise it means lastResponse already triggered a replication by putting the dialog in the stack and therefore in the cache
        if (lastResponseChanged && previousVersion == version.get()) {
            // don't consider it a retrans even if it is on the new node taking over
            if (replicationStrategy == ReplicationStrategy.EarlyDialog) {
                sipResponse.setRetransmission(false);
            }
            replicateState();
        }
    }
// causes REINVITE after NOTIFY on failover to fail with NPE since method attribute is not yet initialized
// else {
// super.setLastResponse(transaction, sipResponse);
// }
}
Also used : ReplicationStrategy(org.mobicents.ha.javax.sip.ReplicationStrategy) ClusteredSipStack(org.mobicents.ha.javax.sip.ClusteredSipStack)

Example 3 with ReplicationStrategy

use of org.mobicents.ha.javax.sip.ReplicationStrategy 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);
        }
    }
}
Also used : DialogState(javax.sip.DialogState) ReplicationStrategy(org.mobicents.ha.javax.sip.ReplicationStrategy) ClusteredSipStack(org.mobicents.ha.javax.sip.ClusteredSipStack) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException)

Example 4 with ReplicationStrategy

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

the class AbstractHASipDialog method setMetaDataToReplicate.

public void setMetaDataToReplicate(Map<String, Object> metaData, boolean recreation) {
    final ReplicationStrategy replicationStrategy = ((ClusteredSipStack) getStack()).getReplicationStrategy();
    if (replicationStrategy == ReplicationStrategy.EarlyDialog) {
        Integer dialogState = (Integer) metaData.get(DIALOG_STATE);
        if (dialogState != null) {
            // the call to super is very important otherwise it triggers replication on dialog recreation
            super.setState(dialogState);
        }
    } else {
        // the call to super is very important otherwise it triggers replication on dialog recreation
        super.setState(DialogState._CONFIRMED);
    }
    lastResponseStringified = (String) metaData.get(LAST_RESPONSE);
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug(getDialogIdToReplicate() + " : lastResponse " + lastResponseStringified);
    }
    String dialogMethod = (String) metaData.get(DIALOG_METHOD);
    if (dialogMethod != null) {
        method = dialogMethod;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : dialog method " + method);
        }
    }
    version = new AtomicLong((Long) metaData.get(VERSION));
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug(getDialogIdToReplicate() + " : version " + version);
    }
    final Boolean isB2BUA = (Boolean) metaData.get(B2BUA);
    if (isB2BUA != null && isB2BUA == Boolean.TRUE) {
        setBackToBackUserAgent();
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : isB2BUA " + isB2BUA);
        }
    }
    final Boolean isReinvite = (Boolean) metaData.get(IS_REINVITE);
    if (isReinvite != null) {
        super.setReInviteFlag(isReinvite);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : isReInvite " + isReinvite);
        }
    }
    final String eventHeaderStringified = (String) metaData.get(EVENT_HEADER);
    if (eventHeaderStringified != null) {
        try {
            super.setEventHeader((EventHeader) new EventParser(eventHeaderStringified).parse());
        } catch (ParseException e) {
            logger.logError("Unexpected exception while parsing a deserialized eventHeader", e);
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : evenHeader " + eventHeaderStringified);
        }
    }
    final String remoteTargetCache = (String) metaData.get(REMOTE_TARGET);
    if (remoteTargetCache != null) {
        Contact contact = new Contact();
        try {
            super.remotePartyStringified = remoteTargetCache;
            contact.setAddress(addressFactory.createAddress(remoteTargetCache));
            super.setRemoteTarget(contact);
        } catch (ParseException e) {
            logger.logError("Unexpected exception while parsing a deserialized remoteTarget address", e);
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : remoteTarget " + remoteTargetStringified);
        }
    }
    final Boolean terminateOnBye = (Boolean) metaData.get(TERMINATE_ON_BYE);
    if (terminateOnBye != null) {
        try {
            terminateOnBye(terminateOnBye);
        } catch (SipException e) {
        // exception is never thrown
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : terminateOnBye " + terminateOnBye);
        }
    }
    final String[] routes = (String[]) metaData.get(ROUTE_LIST);
    if (routes != null) {
        final RouteList routeList = new RouteList();
        for (String route : routes) {
            try {
                routeList.add((Route) headerFactory.createRouteHeader(addressFactory.createAddress(route)));
            } catch (ParseException e) {
                logger.logError("Unexpected exception while parsing a deserialized route address", e);
            }
        }
        setRouteList(routeList);
    }
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug(getDialogIdToReplicate() + " : routes " + routes);
    }
    final Boolean isServer = (Boolean) metaData.get(IS_SERVER);
    if (isServer != null) {
        firstTransactionSeen = true;
        firstTransactionIsServerTransaction = isServer.booleanValue();
        super.setServerTransactionFlag(isServer.booleanValue());
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : isServer " + isServer.booleanValue());
        }
    }
    final Boolean firstTxSecure = (Boolean) metaData.get(FIRST_TX_SECURE);
    if (firstTxSecure != null) {
        firstTransactionSecure = firstTxSecure;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : firstTxSecure " + firstTxSecure);
        }
    }
    final String firstTxId = (String) metaData.get(FIRST_TX_ID);
    if (firstTxId != null) {
        firstTransactionId = firstTxId;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : firstTransactionId " + firstTransactionId);
        }
    }
    final String firstTxMethod = (String) metaData.get(FIRST_TX_METHOD);
    if (firstTxMethod != null) {
        firstTransactionMethod = firstTxMethod;
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : firstTransactionMethod " + firstTransactionMethod);
        }
    }
    if (recreation) {
        isLatestTxServer = (Boolean) metaData.get(IS_LATEST_TX_SERVER);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("HA SIP Dialog is Server ? " + isServer() + ", isLatestTxServer ? " + isLatestTxServer);
        }
        // From and To Uris switch places in certain conditions
        if (isLatestTxServer) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("dialog : switching parties on recreation " + getDialogIdToReplicate() + " localParty = " + getLocalParty());
            }
            Address remoteParty = getLocalParty();
            Address localParty = getRemoteParty();
            setLocalPartyInternal(localParty);
            setRemotePartyInternal(remoteParty);
            long remoteCSeq = getLocalSeqNumber();
            long localCSeq = getRemoteSeqNumber();
            localSequenceNumber = localCSeq;
            remoteSequenceNumber = remoteCSeq;
        }
    }
    String remoteTag = (String) metaData.get(REMOTE_TAG);
    setRemoteTagInternal(remoteTag);
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug(getDialogIdToReplicate() + " : remoteTag " + getRemoteTag());
    }
    String localTag = (String) metaData.get(LOCAL_TAG);
    setLocalTagInternal(localTag);
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug(getDialogIdToReplicate() + " : localTag " + getLocalTag());
    }
    Long remoteCSeq = (Long) metaData.get(REMOTE_CSEQ);
    if (remoteCSeq != null) {
        long cseq = remoteCSeq.longValue();
        if (getRemoteSeqNumber() > cseq) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_INFO)) {
                logger.logInfo("Concurrency problem. Nodes are out" + " of sync. We will assume the local CSeq is the valid one. Enable request affinity to avoid this problem, remoteSequenceNumber=" + getRemoteSeqNumber() + " while other node's remote CSeq" + " number=" + cseq);
            }
        // No need to update the number, it is greater, http://code.google.com/p/restcomm/issues/detail?id=2051
        } else {
            setRemoteSequenceNumber(cseq);
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : remoteCSeq " + getRemoteSeqNumber());
        }
    }
    Long localCSeq = (Long) metaData.get(LOCAL_CSEQ);
    if (localCSeq != null) {
        long cseq = localCSeq.longValue();
        if (localSequenceNumber > cseq) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_INFO)) {
                logger.logInfo("Concurrency problem. Nodes are out" + " of sync. We will assume the local CSeq is the valid one. Enable request affinity to avoid this problem, localSequenceNumber=" + localSequenceNumber + " while other node's local CSeq" + " number=" + cseq);
            }
        // No need to update the number, it is greater, http://code.google.com/p/restcomm/issues/detail?id=2051
        } else {
            localSequenceNumber = cseq;
        }
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : localCSeq " + getLocalSeqNumber());
        }
    }
    final Boolean enableCSeqValidation = (Boolean) metaData.get(ENABLE_CSEQ_VALIDATION);
    if (enableCSeqValidation != null) {
        if (!enableCSeqValidation)
            disableSequenceNumberValidation();
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(getDialogIdToReplicate() + " : CSeq validation is " + enableCSeqValidation);
        }
    }
}
Also used : ReplicationStrategy(org.mobicents.ha.javax.sip.ReplicationStrategy) Address(javax.sip.address.Address) ClusteredSipStack(org.mobicents.ha.javax.sip.ClusteredSipStack) RouteList(gov.nist.javax.sip.header.RouteList) Contact(gov.nist.javax.sip.header.Contact) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) EventParser(gov.nist.javax.sip.parser.EventParser) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Aggregations

ClusteredSipStack (org.mobicents.ha.javax.sip.ClusteredSipStack)4 ReplicationStrategy (org.mobicents.ha.javax.sip.ReplicationStrategy)4 DialogState (javax.sip.DialogState)2 Contact (gov.nist.javax.sip.header.Contact)1 RouteList (gov.nist.javax.sip.header.RouteList)1 EventParser (gov.nist.javax.sip.parser.EventParser)1 ParseException (java.text.ParseException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SipException (javax.sip.SipException)1 Address (javax.sip.address.Address)1 SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)1