Search in sources :

Example 1 with MobicentsHASIPServerTransaction

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

the class SIPServerTransactionCacheData method createServerTransaction.

public MobicentsHASIPServerTransaction createServerTransaction(String txId, Map<String, Object> transactionMetaData, Object transactionAppData) throws SipCacheException {
    MobicentsHASIPServerTransaction haServerTransaction = null;
    if (transactionMetaData != null) {
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug("sipStack " + this + " server transaction " + txId + " is present in the distributed cache, recreating it locally");
        }
        String channelTransport = (String) transactionMetaData.get(MobicentsHASIPServerTransaction.TRANSPORT);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : transport " + channelTransport);
        }
        InetAddress channelIp = (InetAddress) transactionMetaData.get(MobicentsHASIPServerTransaction.PEER_IP);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : channel peer Ip address " + channelIp);
        }
        Integer channelPort = (Integer) transactionMetaData.get(MobicentsHASIPServerTransaction.PEER_PORT);
        if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            logger.logDebug(txId + " : channel peer port " + channelPort);
        }
        Integer myPort = (Integer) transactionMetaData.get(MobicentsHASIPServerTransaction.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;
            }
        }
        haServerTransaction = new MobicentsHASIPServerTransaction((SIPTransactionStack) stack, messageChannel);
        haServerTransaction.setBranch(txId);
        try {
            updateServerTransactionMetaData(transactionMetaData, transactionAppData, haServerTransaction, 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 + " server transaction " + txId + " not found in the distributed cache");
        }
    }
    return haServerTransaction;
}
Also used : MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) 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)

Example 2 with MobicentsHASIPServerTransaction

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

the class SIPServerTransactionCacheData method putServerTransaction.

public void putServerTransaction(SIPServerTransaction serverTransaction) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        logger.logDebug("putServerTransaction(" + serverTransaction.getTransactionId() + ")");
    try {
        final MobicentsHASIPServerTransaction haServerTransaction = (MobicentsHASIPServerTransaction) serverTransaction;
        // meta data
        Map<String, Object> metaData = haServerTransaction.getMetaDataToReplicate();
        serverTransactions.put(serverTransaction.getTransactionId(), metaData);
        // app data
        final Object transactionAppData = haServerTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            serverTransactionsApp.put(serverTransaction.getTransactionId(), transactionAppData);
        }
    } catch (Exception e) {
        throw new SipCacheException(e);
    }
}
Also used : MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) 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 MobicentsHASIPServerTransaction

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

the class ServerTransactionCacheData method putServerTransaction.

public void putServerTransaction(SIPServerTransaction serverTransaction) throws SipCacheException {
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        clusteredlogger.logStackTrace();
    }
    final MobicentsHASIPServerTransaction haServerTransaction = (MobicentsHASIPServerTransaction) serverTransaction;
    final String transactionId = haServerTransaction.getTransactionId();
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        clusteredlogger.logDebug("put HA SIP Server Transaction " + serverTransaction + " with id " + transactionId);
    }
    final Cache jbossCache = getMobicentsCache().getJBossCache();
    TransactionManager transactionManager = jbossCache.getConfiguration().getRuntimeConfig().getTransactionManager();
    boolean doTx = false;
    try {
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("transaction manager :" + transactionManager);
        }
        if (transactionManager != null && transactionManager.getTransaction() == null) {
            if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                clusteredlogger.logDebug("transaction manager begin transaction");
            }
            transactionManager.begin();
            doTx = true;
        }
        final Node childNode = getNode().addChild(Fqn.fromElements(transactionId));
        for (Entry<String, Object> metaData : haServerTransaction.getMetaDataToReplicate().entrySet()) {
            childNode.put(metaData.getKey(), metaData.getValue());
        }
        final Object transactionAppData = haServerTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            childNode.put(APPDATA, transactionAppData);
        }
    } catch (Exception ex) {
        try {
            if (transactionManager != null) {
                // Let's set it no matter what.
                transactionManager.setRollbackOnly();
            }
        } catch (Exception exn) {
            clusteredlogger.logError("Problem rolling back session mgmt transaction", exn);
        }
    } finally {
        if (doTx) {
            try {
                if (transactionManager.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        clusteredlogger.logDebug("transaction manager committing transaction");
                    }
                    transactionManager.commit();
                } else {
                    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        clusteredlogger.logDebug("endBatch(): rolling back batch");
                    }
                    transactionManager.rollback();
                }
            } catch (RollbackException re) {
                // Do nothing here since cache may rollback automatically.
                clusteredlogger.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 : MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) 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 MobicentsHASIPServerTransaction

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

the class ServerTransactionCacheData method createServerTransaction.

public MobicentsHASIPServerTransaction createServerTransaction(String txId, Map<String, Object> transactionMetaData, Object transactionAppData) throws SipCacheException {
    MobicentsHASIPServerTransaction haServerTransaction = null;
    if (transactionMetaData != null) {
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("sipStack " + this + " server transaction " + txId + " is present in the distributed cache, recreating it locally");
        }
        String channelTransport = (String) transactionMetaData.get(MobicentsHASIPServerTransaction.TRANSPORT);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug(txId + " : transport " + channelTransport);
        }
        InetAddress channelIp = (InetAddress) transactionMetaData.get(MobicentsHASIPServerTransaction.PEER_IP);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug(txId + " : channel peer Ip address " + channelIp);
        }
        Integer channelPort = (Integer) transactionMetaData.get(MobicentsHASIPServerTransaction.PEER_PORT);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug(txId + " : channel peer port " + channelPort);
        }
        Integer myPort = (Integer) transactionMetaData.get(MobicentsHASIPServerTransaction.MY_PORT);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug(txId + " : my port " + myPort);
        }
        MessageChannel messageChannel = null;
        MessageProcessor[] messageProcessors = clusteredSipStack.getStackMessageProcessors();
        for (MessageProcessor messageProcessor : messageProcessors) {
            if (messageProcessor.getTransport().equalsIgnoreCase(channelTransport)) {
                try {
                    messageChannel = messageProcessor.createMessageChannel(channelIp, channelPort);
                } catch (IOException e) {
                    clusteredlogger.logError("couldn't recreate the message channel on ip address " + channelIp + " and port " + channelPort, e);
                }
                break;
            }
        }
        haServerTransaction = new MobicentsHASIPServerTransaction((SIPTransactionStack) clusteredSipStack, messageChannel);
        haServerTransaction.setBranch(txId);
        try {
            updateServerTransactionMetaData(transactionMetaData, transactionAppData, haServerTransaction, 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 (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("sipStack " + this + " server transaction " + txId + " not found in the distributed cache");
        }
    }
    return haServerTransaction;
}
Also used : MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) 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) IOException(java.io.IOException) ParseException(java.text.ParseException) InetAddress(java.net.InetAddress)

Example 5 with MobicentsHASIPServerTransaction

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

the class SIPServerTransactionCacheData method putServerTransaction.

public void putServerTransaction(SIPServerTransaction serverTransaction) throws SipCacheException {
    if (logger.isLoggingEnabled(StackLogger.TRACE_TRACE))
        logger.logDebug("putServerTransaction(" + serverTransaction.getTransactionId() + ")");
    try {
        final MobicentsHASIPServerTransaction haServerTransaction = (MobicentsHASIPServerTransaction) serverTransaction;
        // meta data
        Map<String, Object> metaData = haServerTransaction.getMetaDataToReplicate();
        getServerTransactions().put(serverTransaction.getTransactionId(), metaData);
        // app data
        final Object transactionAppData = haServerTransaction.getApplicationDataToReplicate();
        if (transactionAppData != null) {
            getServerTransactionsApp().put(serverTransaction.getTransactionId(), transactionAppData);
        }
    } catch (Exception e) {
        throw new SipCacheException(e);
    }
}
Also used : MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) 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)

Aggregations

MobicentsHASIPServerTransaction (gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction)6 IOException (java.io.IOException)6 ParseException (java.text.ParseException)6 PeerUnavailableException (javax.sip.PeerUnavailableException)6 SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)4 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 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