Search in sources :

Example 6 with Contact

use of gov.nist.javax.sip.header.Contact 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

Contact (gov.nist.javax.sip.header.Contact)6 RouteList (gov.nist.javax.sip.header.RouteList)3 SipException (javax.sip.SipException)3 AddressImpl (gov.nist.javax.sip.address.AddressImpl)2 SipUri (gov.nist.javax.sip.address.SipUri)2 ContactList (gov.nist.javax.sip.header.ContactList)2 Route (gov.nist.javax.sip.header.Route)2 SIPRequest (gov.nist.javax.sip.message.SIPRequest)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 SipURI (javax.sip.address.SipURI)2 Event (gov.nist.javax.sip.header.Event)1 RecordRoute (gov.nist.javax.sip.header.RecordRoute)1 RecordRouteList (gov.nist.javax.sip.header.RecordRouteList)1 SIPResponse (gov.nist.javax.sip.message.SIPResponse)1 EventParser (gov.nist.javax.sip.parser.EventParser)1 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)1 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)1