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;
}
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);
}
}
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);
}
}
}
}
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);
}
}
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;
}
Aggregations