Search in sources :

Example 1 with MobicentsHASIPClientTransaction

use of gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction 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 2 with MobicentsHASIPClientTransaction

use of gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction in project jain-sip.ha by RestComm.

the class SIPClientTransactionCacheData method putClientTransaction.

public void putClientTransaction(SIPClientTransaction clientTransaction) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        logger.logDebug("putClientTransaction(" + clientTransaction.getTransactionId() + ")");
    try {
        final MobicentsHASIPClientTransaction haClientTransaction = (MobicentsHASIPClientTransaction) clientTransaction;
        // metadata
        Map<String, Object> metaData = haClientTransaction.getMetaDataToReplicate();
        clientTransactions.put(clientTransaction.getTransactionId(), metaData);
        // app data
        final Object transactionAppData = haClientTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            clientTransactionsApp.put(clientTransaction.getTransactionId(), transactionAppData);
        }
    } catch (Exception e) {
        throw new SipCacheException(e);
    }
}
Also used : MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) IOException(java.io.IOException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException)

Example 3 with MobicentsHASIPClientTransaction

use of gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction in project jain-sip.ha by RestComm.

the class ClientTransactionCacheData method putClientTransaction.

public void putClientTransaction(SIPClientTransaction clientTransaction) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logStackTrace();
    }
    final MobicentsHASIPClientTransaction haClientTransaction = (MobicentsHASIPClientTransaction) clientTransaction;
    final String transactionId = haClientTransaction.getTransactionId();
    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        logger.logDebug("put HA SIP Client Transaction " + clientTransaction + " with id " + transactionId);
    }
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    TransactionManager transactionManager = jbossCache.getConfiguration().getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        final Node childNode = getNode().addChild(Fqn.fromElements(transactionId));
        for (Entry<String, Object> metaData : haClientTransaction.getMetaDataToReplicate().entrySet()) {
            childNode.put(metaData.getKey(), metaData.getValue());
        }
        final Object transactionAppData = haClientTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                logger.logDebug("replicating application data " + transactionAppData);
            }
            childNode.put(APPDATA, transactionAppData);
        }
    } catch (Exception ex) {
        try {
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            logger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        logger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                logger.logWarning("endBatch(): rolling back transaction with exception: " + re);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
            }
        }
    }
}
Also used : MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) TransactionManager(javax.transaction.TransactionManager) Node(org.jboss.cache.Node) RollbackException(javax.transaction.RollbackException) IOException(java.io.IOException) CacheException(org.jboss.cache.CacheException) RollbackException(javax.transaction.RollbackException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) MobicentsCache(org.mobicents.cache.MobicentsCache) Cache(org.jboss.cache.Cache)

Example 4 with MobicentsHASIPClientTransaction

use of gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction in project jain-sip.ha by RestComm.

the class SIPClientTransactionCacheData method putClientTransaction.

public void putClientTransaction(SIPClientTransaction clientTransaction) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        logger.logDebug("putClientTransaction(" + clientTransaction.getTransactionId() + ")");
    try {
        final MobicentsHASIPClientTransaction haClientTransaction = (MobicentsHASIPClientTransaction) clientTransaction;
        // metadata
        Map<String, Object> metaData = haClientTransaction.getMetaDataToReplicate();
        getClientTransactions().put(clientTransaction.getTransactionId(), metaData);
        // app data
        final Object transactionAppData = haClientTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            getClientTransactionsApp().put(clientTransaction.getTransactionId(), transactionAppData);
        }
    } catch (Exception e) {
        throw new SipCacheException(e);
    }
}
Also used : MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) IOException(java.io.IOException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException)

Example 5 with MobicentsHASIPClientTransaction

use of gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction in project jain-sip.ha by RestComm.

the class SIPClientTransactionCacheData method createClientTransaction.

public MobicentsHASIPClientTransaction createClientTransaction(String txId, Map<String, Object> transactionMetaData, Object transactionAppData) throws SipCacheException {
    MobicentsHASIPClientTransaction haClientTransaction = null;
    if (transactionMetaData != null) {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("sipStack " + this + " client transaction " + txId + " is present in the distributed cache, recreating it locally");
        }
        String channelTransport = (String) transactionMetaData.get(MobicentsHASIPClientTransaction.TRANSPORT);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : transport " + channelTransport);
        }
        InetAddress channelIp = (InetAddress) transactionMetaData.get(MobicentsHASIPClientTransaction.PEER_IP);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : channel peer Ip address " + channelIp);
        }
        Integer channelPort = (Integer) transactionMetaData.get(MobicentsHASIPClientTransaction.PEER_PORT);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : channel peer port " + channelPort);
        }
        Integer myPort = (Integer) transactionMetaData.get(MobicentsHASIPClientTransaction.MY_PORT);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : my port " + myPort);
        }
        MessageChannel messageChannel = null;
        MessageProcessor[] messageProcessors = stack.getStackMessageProcessors();
        for (MessageProcessor messageProcessor : messageProcessors) {
            if (messageProcessor.getTransport().equalsIgnoreCase(channelTransport)) {
                try {
                    messageChannel = messageProcessor.createMessageChannel(channelIp, channelPort);
                } catch (IOException e) {
                    logger.logError("couldn't recreate the message channel on ip address " + channelIp + " and port " + channelPort, e);
                }
                break;
            }
        }
        haClientTransaction = new MobicentsHASIPClientTransaction((SIPTransactionStack) stack, messageChannel);
        haClientTransaction.setBranch(txId);
        try {
            updateClientTransactionMetaData(transactionMetaData, transactionAppData, haClientTransaction, true);
        } catch (PeerUnavailableException e) {
            throw new SipCacheException("A problem occured while retrieving the following transaction " + txId + " from the Cache", e);
        } catch (ParseException e) {
            throw new SipCacheException("A problem occured while retrieving the following transaction " + txId + " from the Cache", e);
        }
    } else {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("sipStack " + this + " client transaction " + txId + " not found in the distributed cache");
        }
    }
    return haClientTransaction;
}
Also used : MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) MessageChannel(gov.nist.javax.sip.stack.MessageChannel) PeerUnavailableException(javax.sip.PeerUnavailableException) MessageProcessor(gov.nist.javax.sip.stack.MessageProcessor) SIPTransactionStack(gov.nist.javax.sip.stack.SIPTransactionStack) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) IOException(java.io.IOException) ParseException(java.text.ParseException) InetAddress(java.net.InetAddress)

Aggregations

MobicentsHASIPClientTransaction (gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction)8 IOException (java.io.IOException)6 ParseException (java.text.ParseException)6 PeerUnavailableException (javax.sip.PeerUnavailableException)6 SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)5 MessageChannel (gov.nist.javax.sip.stack.MessageChannel)3 MessageProcessor (gov.nist.javax.sip.stack.MessageProcessor)3 SIPTransactionStack (gov.nist.javax.sip.stack.SIPTransactionStack)3 InetAddress (java.net.InetAddress)3 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)1 RollbackException (javax.transaction.RollbackException)1 TransactionManager (javax.transaction.TransactionManager)1 Cache (org.jboss.cache.Cache)1 CacheException (org.jboss.cache.CacheException)1 Node (org.jboss.cache.Node)1 MobicentsCache (org.mobicents.cache.MobicentsCache)1