Search in sources :

Example 11 with SipCacheException

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;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SIPDialog(gov.nist.javax.sip.stack.SIPDialog) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) ListeningPoint(javax.sip.ListeningPoint)

Example 12 with SipCacheException

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;
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction)

Example 13 with SipCacheException

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);
        }
    }
}
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 14 with SipCacheException

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);
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) ResponseExt(gov.nist.javax.sip.message.ResponseExt) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException)

Example 15 with SipCacheException

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");
            }
        }
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) PeerUnavailableException(javax.sip.PeerUnavailableException) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) ParseException(java.text.ParseException)

Aggregations

SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)20 ParseException (java.text.ParseException)16 PeerUnavailableException (javax.sip.PeerUnavailableException)16 IOException (java.io.IOException)12 MobicentsHASIPClientTransaction (gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction)7 MobicentsHASIPServerTransaction (gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction)6 SIPResponse (gov.nist.javax.sip.message.SIPResponse)5 MessageChannel (gov.nist.javax.sip.stack.MessageChannel)4 MessageProcessor (gov.nist.javax.sip.stack.MessageProcessor)4 SIPTransactionStack (gov.nist.javax.sip.stack.SIPTransactionStack)4 InetAddress (java.net.InetAddress)4 Map (java.util.Map)4 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)3 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)3 IMap (com.hazelcast.core.IMap)2 SipProviderImpl (gov.nist.javax.sip.SipProviderImpl)2 AbstractHASipDialog (gov.nist.javax.sip.stack.AbstractHASipDialog)2 HASipDialog (org.mobicents.ha.javax.sip.HASipDialog)2 ResponseExt (gov.nist.javax.sip.message.ResponseExt)1