Search in sources :

Example 1 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class StompBridge method start.

/**
 * Start the bridge
 *
 * @param bc the bridge context
 * @param args start parameters
 *
 * @return true if successfully started; false if started asynchronously
 *
 * @throws Exception if unable to start the bridge
 */
@Override
public synchronized boolean start(BridgeContext bc, String[] args) throws Exception {
    if (args != null) {
        String[] params = { BridgeUtil.toString(args), getType() };
        bc.logInfo(StompServer.getStompBridgeResources().getString(StompBridgeResources.W_IGNORE_START_OPTION, params), null);
    }
    if (_state == State.STARTED) {
        return true;
    }
    _state = State.STARTING;
    boolean inited = false;
    try {
        _stompServer = new StompServer();
        _stompServer.init(bc);
        inited = true;
        _stompServer.start();
        _state = State.STARTED;
        return true;
    } catch (Exception e) {
        bc.logError(e.getMessage(), e);
        try {
            if (inited) {
                stop(bc, null);
            }
        } catch (Throwable t) {
        }
        if (!inited) {
            _stompServer = null;
            throw e;
        }
        throw new BridgeException(e.getMessage(), e, Status.CREATED);
    }
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) BridgeException(com.sun.messaging.bridge.api.BridgeException)

Example 2 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class Link method runTransacted.

private void runTransacted() throws Throwable {
    long msgCount = 0;
    long receiveTimeout = 0L;
    if (_parent.supportTransactionTimeout()) {
        receiveTimeout = (((long) _parent.getTransactionTimeout()) / (long) 2) * 1000;
    }
    int consecutiveThrowables = 0;
    while (_state != LinkState.STOPPING && _state != LinkState.STOPPED) {
        if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedException(_jbr.getKString(_jbr.X_LINK_INTERRUPTED, this.toString()));
        }
        Transaction transaction = null;
        XAResourceHandle srh = new XAResourceHandle(false);
        XAResourceHandle trh = new XAResourceHandle(true);
        Message m = null;
        MessageHeaders srcmhs = null;
        String mid = null;
        Throwable currentThrowable = null;
        _branchProducer = null;
        _targetCurrentDestinationName = null;
        try {
            if (_sourceConnException) {
                closeSource();
                initSource();
                resume(false);
            }
            if (_targetConnException) {
                closeTarget();
                if (_targetStayConnected) {
                    initTarget();
                }
            }
            srh.xar = ((XASession) _sourceSession).getXAResource();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "BEGIN transaction in " + this);
            }
            try {
                _tm.begin();
            } catch (Exception e) {
                currentThrowable = e;
                _logger.log(Level.SEVERE, "Unable to start transaction in" + this, e);
                _sourceConnException = true;
                _targetConnException = true;
                continue;
            }
            try {
                transaction = _tm.getTransaction();
            } catch (Exception e) {
                currentThrowable = e;
                _logger.log(Level.SEVERE, "Exception to get transaction in" + this, e);
                _sourceConnException = true;
                _targetConnException = true;
                continue;
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "enlist source in transaction " + transaction + " in " + this);
            }
            if (!doEnlistAndRollbackOnError(transaction, _tm, srh)) {
                currentThrowable = srh.ex;
                continue;
            }
            try {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Receiving(" + receiveTimeout + ") message from source in transaction " + transaction + " in " + this);
                }
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_RECEIVE_1, null, "jakarta.jms.JMSException", true);
                }
                m = _consumer.receive(receiveTimeout);
                if (m == null) {
                    try {
                        String logmsg = ((receiveTimeout > 0L) ? _jbr.getKString(_jbr.W_SOURCE_CONN_CLOSED_OR_RECEIVE_TIMEOUT, this.toString()) : _jbr.getKString(_jbr.W_SOURCE_CONN_CLOSED, this.toString()));
                        _logger.log(Level.WARNING, logmsg);
                    } catch (Throwable t) {
                    }
                    try {
                        _tm.rollback();
                    } catch (Throwable t1) {
                        try {
                            if (receiveTimeout == 0L) {
                                _logger.log(Level.FINE, "Unable to rollback transaction " + transaction + " on closed source connection or receive() timeout ", t1);
                            } else {
                                logWarning("Unable to rollback transaction " + transaction + " on closed source connection or receive() timeout ", t1);
                            }
                        } catch (Throwable t) {
                        }
                    }
                    continue;
                }
                msgCount++;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Received message " + m + " from source in transaction " + transaction + " in " + this + ", msgCount=" + msgCount);
                }
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_RECEIVE_2, null, "jakarta.jms.JMSException", true);
                }
            } catch (Throwable t) {
                currentThrowable = t;
                logWarning("Exception in receiving message in " + this, t);
                try {
                    _tm.rollback();
                } catch (Throwable t1) {
                    logWarning("Exception on rollback transaction " + transaction + " on receiving failure", t1);
                }
                continue;
            }
            if (!isTransactionActive(transaction, _tm)) {
                continue;
            }
            srcmhs = MessageHeaders.getMessageHeaders(m);
            mid = srcmhs.mid;
            long ttl = srcmhs.expiration;
            if (ttl != 0L) {
                ttl = ttl - System.currentTimeMillis();
            }
            if (ttl < 0) {
                handleExpiredMessage(m, mid, transaction, _tm, srh);
                continue;
            }
            if (!isTransactionActive(transaction, _tm)) {
                continue;
            }
            if (!_targetStayConnected) {
                try {
                    initTarget();
                } catch (Exception e) {
                    _logger.log(Level.SEVERE, "Unable to connect to target in " + this, e);
                    try {
                        _tm.rollback();
                    } catch (Throwable t1) {
                        _logger.log(Level.WARNING, "Unable to rollback transaction " + transaction + " on init target failure for message " + mid + " in " + this, t1);
                    }
                    throw e;
                }
            }
            if (!isTransactionActive(transaction, _tm)) {
                continue;
            }
            Message sm = null;
            String midSent = null;
            try {
                sm = handleMessageTransformer(m, srcmhs);
            } catch (Throwable t) {
                _logger.log(Level.WARNING, _jbr.getString(_jbr.W_STOP_LINK_BECAUSE_OF, this, t.getMessage()), t);
                throw t;
            }
            if (sm == null) {
                _logger.log(Level.WARNING, _jbr.getString(_jbr.W_CONSUME_NO_TRANSFER, mid, this));
                if (!isTransactionActive(transaction, _tm)) {
                    continue;
                }
            } else {
                if (_targetCF.isEmbeded() && _sourceCF.isEmbeded()) {
                    trh.xar = srh.xar;
                } else {
                    trh.xar = ((XASession) _targetSession).getXAResource();
                    if (!(_tm instanceof TransactionManagerImpl) && trh.xar.getClass().getName().equals(srh.xar.getClass().getName())) {
                        trh.xar = new XAResourceImpl(trh.xar);
                        _logger.log(Level.INFO, "Use XAResource wrapper " + trh.xar + " for target XAResource " + trh.xar.getClass().getName());
                    }
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "enlist target in transaction " + transaction + " in " + this);
                    }
                    if (!doEnlistAndRollbackOnError(transaction, _tm, trh)) {
                        currentThrowable = trh.ex;
                        continue;
                    }
                }
                try {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Sending message " + mid + " to target in transaction " + transaction + " in " + this);
                    }
                    if (_fi.FAULT_INJECTION) {
                        _fi.setLogger(_logger);
                        _fi.checkFaultAndThrowException(FaultInjection.FAULT_SEND_1, null, "jakarta.jms.JMSException", true);
                    }
                    MessageProducer producer = _producer;
                    if (_branchProducer != null) {
                        producer = _branchProducer;
                    }
                    if (!getTargetCurrentDestinationName().equals(toDestinationName(producer.getDestination()))) {
                        throw new BridgeException("Unexpected target producer's destination name " + toDestinationName(producer.getDestination()) + ": not match current target destination name " + getTargetCurrentDestinationName());
                    }
                    try {
                        if (_parent.needTagBridgeName()) {
                            _parent.tagBridgeName(sm, _sourceSession.createMessage());
                        }
                        producer.send(sm, srcmhs.deliverymode, srcmhs.priority, ttl);
                        midSent = sm.getJMSMessageID();
                    } finally {
                        if (_branchProducer != null) {
                            try {
                                _branchProducer.close();
                            } catch (Throwable t) {
                                _logger.log(Level.WARNING, "Closing temporary target producer failed: " + t.getMessage() + " in " + this, t);
                            } finally {
                                _branchProducer = null;
                            }
                        }
                        MessageHeaders.resetMessageHeaders(m, srcmhs);
                    }
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Sent message " + mid + " to target in transaction " + transaction + " in " + this);
                    }
                    if (_fi.FAULT_INJECTION) {
                        _fi.setLogger(_logger);
                        _fi.checkFaultAndThrowException(FaultInjection.FAULT_SEND_2, null, "jakarta.jms.JMSException", true);
                    }
                } catch (Throwable t) {
                    currentThrowable = t;
                    _logger.log(Level.SEVERE, "Unable to send message " + mid + " to target in " + this, t);
                    try {
                        _tm.rollback();
                    } catch (Throwable t1) {
                        _logger.log(Level.WARNING, "Unable to rollback transaction " + transaction + " on send failure for message " + mid + " in " + this, t1);
                    }
                    continue;
                }
                if (!isTransactionActive(transaction, _tm)) {
                    continue;
                }
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "delist " + trh + " in transaction " + transaction + " in " + this);
                }
                if (trh.xar != srh.xar) {
                    if (!doDelistAndRollbackOnError(transaction, _tm, trh)) {
                        currentThrowable = trh.ex;
                        continue;
                    }
                }
            }
            if (!isTransactionActive(transaction, _tm)) {
                continue;
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "delist " + srh + " in transaction " + transaction + " in " + this);
            }
            if (!doDelistAndRollbackOnError(transaction, _tm, srh)) {
                currentThrowable = srh.ex;
                continue;
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "COMMIT transaction " + transaction + " for message " + mid + " in " + this);
            }
            try {
                _tm.commit();
                String[] param = { mid, midSent, this.toString() };
                if (_parent.logMessageTransfer()) {
                    _logger.log(Level.INFO, _jbr.getString(_jbr.I_MESSAGE_TRANSFER_SUCCESS, param));
                } else if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, _jbr.getString(_jbr.I_MESSAGE_TRANSFER_SUCCESS, param));
                }
            } catch (RollbackException e) {
                _logger.log(Level.WARNING, "RollbackException on commit transaction " + transaction + " for message " + mid + " in " + this, e);
                sendToDMQ(m, mid, DMQ.DMQReason.COMMIT_FAILURE, e);
                continue;
            } catch (HeuristicMixedException e) {
                _logger.log(Level.WARNING, "HeuristicMixedException on commit transaction " + transaction + " for message " + mid + " in " + this, e);
                sendToDMQ(m, mid, DMQ.DMQReason.COMMIT_FAILURE, e);
                continue;
            } catch (HeuristicRollbackException e) {
                _logger.log(Level.WARNING, "HeuristicRollbackException on commit transaction " + transaction + " for message " + mid + " in " + this, e);
                sendToDMQ(m, mid, DMQ.DMQReason.COMMIT_FAILURE, e);
                continue;
            } catch (Throwable t) {
                currentThrowable = t;
                _logger.log(Level.SEVERE, "Failed to commit transaction " + transaction + " for message " + mid + " in " + this, t);
                sendToDMQ(m, mid, DMQ.DMQReason.COMMIT_FAILURE, t);
                continue;
            }
        } finally {
            doFinally(transaction, _tm, srh, trh);
            if (currentThrowable == null) {
                consecutiveThrowables = 0;
            } else {
                consecutiveThrowables++;
                if (consecutiveThrowables > MAX_CONSECUTIVE_THROWABLES) {
                    throw new RuntimeException("Maximum consecutive exceptions exceeded", currentThrowable);
                }
            }
        }
    }
}
Also used : Message(jakarta.jms.Message) HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) RollbackException(jakarta.transaction.RollbackException) BridgeException(com.sun.messaging.bridge.api.BridgeException) JMSException(jakarta.jms.JMSException) HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) RollbackException(jakarta.transaction.RollbackException) HeuristicMixedException(jakarta.transaction.HeuristicMixedException) BridgeException(com.sun.messaging.bridge.api.BridgeException) HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) Transaction(jakarta.transaction.Transaction) TransactionManagerImpl(com.sun.messaging.bridge.service.jms.tx.TransactionManagerImpl) HeuristicMixedException(jakarta.transaction.HeuristicMixedException) MessageProducer(jakarta.jms.MessageProducer)

Example 3 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class Link method handleMessageTransformer.

/**
 * @param m The message to be transformed
 *
 * @return a Message object that is tranformed from 'm' or null to inform caller to consume 'm' from source and no
 * forward to target
 * @exception to inform caller that the link must be stopped
 */
private Message handleMessageTransformer(Message m, MessageHeaders srcmhs) throws Throwable {
    Message msgToSend = m;
    String mid = srcmhs.mid;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Retain JMSReplyTo " + _retainReplyTo + " for message " + mid + " in " + this);
    }
    if (!_retainReplyTo) {
        try {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Setting JMSReplyTo null for message " + mid + " in " + this);
            }
            msgToSend.setJMSReplyTo((Destination) null);
        } catch (Throwable t) {
            _logger.log(Level.WARNING, "setJMSReplyTo(null) failed: " + t.getMessage() + " in " + this, t);
        }
    }
    boolean transformed = false;
    Destination asSourceDest = m.getJMSDestination();
    if (_msgTransformer != null) {
        _msgTransformer.init(_targetSession, Bridge.JMS_TYPE);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Transforming message " + mid + " using " + _msgTransformer.getClass().getName() + " in " + this);
        }
        try {
            try {
                msgToSend = _msgTransformer.transform(m, true, null, getSourceProviderName(), getTargetProviderName(), _msgTransformerProps);
                transformed = true;
                if (msgToSend == null) {
                    throw new BridgeException(_jbr.getKString(_jbr.X_NULL_RETURN_FROM_FOR_MESSAGE, _msgTransformer.getClass().getName() + ".transform()", mid));
                }
            } finally {
                MessageHeaders.resetMessageHeaders(m, srcmhs);
            }
            if (_fi.FAULT_INJECTION) {
                _fi.setLogger(_logger);
                _fi.checkFaultAndThrowException(FaultInjection.FAULT_TRANSFORM_2, null, "jakarta.jms.JMSException", true);
            }
            if (_msgTransformer.isNoTransfer()) {
                String[] param = { "MessageTransformer.transform()", mid, this.toString() };
                _logger.log(Level.INFO, _jbr.getString(_jbr.I_INSTRUCTED_NO_TRANSFER_AND_CONSUME, param));
                if (_firstTransformerNoTransfer) {
                    sendToDMQ(m, mid, DMQ.DMQReason.FIRST_TRANSFORMER_NOTRANSFER, null);
                    _firstTransformerNoTransfer = false;
                }
                return null;
            }
        } catch (Throwable t) {
            if (_consumeOnTransformError && (!transformed || msgToSend == null)) {
                _logger.log(Level.WARNING, "Exception from message transformer: " + t.getMessage() + " for message " + m + " in " + this, t);
                sendToDMQ(m, mid, DMQ.DMQReason.TRANSFORMER_FAILURE, t);
                return null;
            }
            throw t;
        }
        if (_logger.isLoggable(Level.FINE)) {
            StringBuilder buf = new StringBuilder();
            buf.append("Transformed message " + mid);
            try {
                buf.append(" to " + msgToSend + " in " + this);
            } catch (Throwable t) {
                buf.append(" in " + this);
            }
            _logger.log(Level.FINE, buf.toString());
        }
    }
    // if (_msgTransformer != null)
    handleBranchTo(m, mid, transformed, asSourceDest);
    return msgToSend;
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) Destination(jakarta.jms.Destination) Message(jakarta.jms.Message)

Example 4 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class Link method runNonTransacted.

private void runNonTransacted() throws Throwable {
    long msgCount = 0;
    int consecutiveThrowables = 0;
    while (_state != LinkState.STOPPING && _state != LinkState.STOPPED) {
        if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedException(_jbr.getKString(_jbr.X_LINK_INTERRUPTED, this.toString()));
        }
        _branchProducer = null;
        _targetCurrentDestinationName = null;
        Throwable currentThrowable = null;
        Message m = null;
        MessageHeaders srcmhs = null;
        String mid = null;
        try {
            if (_sourceConnException) {
                closeSource();
                initSource();
                resume(false);
            }
            if (_targetConnException) {
                closeTarget();
                if (_targetStayConnected) {
                    initTarget();
                }
            }
            try {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Receiving message from source in " + this + " ...");
                }
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_RECEIVE_1, null, "jakarta.jms.JMSException", true);
                }
                m = _consumer.receive();
                if (m == null) {
                    try {
                        _logger.log(Level.WARNING, "receive() returned null,  source connection may have closed in " + this);
                    } catch (Throwable e) {
                    }
                    continue;
                }
                msgCount++;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Received message " + m + " from source in " + this + ", msgCount=" + msgCount);
                }
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_RECEIVE_2, null, "jakarta.jms.JMSException", true);
                }
            } catch (Throwable t) {
                currentThrowable = t;
                logWarning("Exception in receiving message: " + t.getMessage() + " in " + this, t);
                if (_state == LinkState.STOPPING || _state == LinkState.STOPPED) {
                    return;
                }
                closeSource();
                _sourceConnException = true;
                continue;
            }
            srcmhs = MessageHeaders.getMessageHeaders(m);
            mid = srcmhs.mid;
            long ttl = srcmhs.expiration;
            if (ttl != 0L) {
                ttl = ttl - System.currentTimeMillis();
            }
            if (ttl < 0) {
                _logger.log(Level.INFO, _jbr.getString(_jbr.I_NONTXN_MESSAGE_EXPIRED, mid, this.toString()));
                try {
                    sendToDMQ(m, mid, DMQ.DMQReason.MESSAGE_EXPIRED, (Throwable) null);
                } finally {
                    closeSource();
                    _sourceConnException = true;
                    continue;
                }
            }
            if (_targetConnException || !_targetStayConnected) {
                if (_targetConnException) {
                    closeTarget();
                }
                try {
                    initTarget();
                } catch (Exception e) {
                    _logger.log(Level.SEVERE, "Unable to connect to target for message " + mid + " in " + this);
                    throw e;
                }
            }
            Message sm = null;
            String midSent = null;
            try {
                sm = handleMessageTransformer(m, srcmhs);
            } catch (Throwable t) {
                _logger.log(Level.WARNING, _jbr.getString(_jbr.W_STOP_LINK_BECAUSE_OF, this, t.getMessage()), t);
                throw t;
            }
            if (sm == null) {
                _logger.log(Level.WARNING, _jbr.getString(_jbr.W_CONSUME_NO_TRANSFER, mid, this));
            } else {
                try {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Sending message " + mid + " to target in " + this);
                    }
                    if (_fi.FAULT_INJECTION) {
                        _fi.setLogger(_logger);
                        _fi.checkFaultAndThrowException(FaultInjection.FAULT_SEND_1, null, "jakarta.jms.JMSException", true);
                    }
                    MessageProducer producer = _producer;
                    if (_branchProducer != null) {
                        producer = _branchProducer;
                    }
                    if (!getTargetCurrentDestinationName().equals(toDestinationName(producer.getDestination()))) {
                        throw new BridgeException("Unexpected target producer's destination name " + toDestinationName(producer.getDestination()) + ": not match current target destination name " + getTargetCurrentDestinationName());
                    }
                    try {
                        if (_parent.needTagBridgeName()) {
                            _parent.tagBridgeName(sm, _sourceSession.createMessage());
                        }
                        producer.send(sm, srcmhs.deliverymode, srcmhs.priority, ttl);
                        midSent = sm.getJMSMessageID();
                    } finally {
                        if (_branchProducer != null) {
                            try {
                                _branchProducer.close();
                            } catch (Throwable t) {
                                _logger.log(Level.WARNING, "Closing temporary target producer failed: " + t.getMessage() + " in " + this, t);
                            } finally {
                                _branchProducer = null;
                            }
                        }
                        MessageHeaders.resetMessageHeaders(m, srcmhs);
                    }
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Sent message " + mid + " to target in " + this);
                    }
                    if (_fi.FAULT_INJECTION) {
                        _fi.setLogger(_logger);
                        _fi.checkFaultAndThrowException(FaultInjection.FAULT_SEND_2, null, "jakarta.jms.JMSException", true);
                    }
                } catch (Throwable t) {
                    currentThrowable = t;
                    _logger.log(Level.SEVERE, "Unable to send message " + mid + " to target in " + this, t);
                    try {
                        sendToDMQ(m, mid, DMQ.DMQReason.SEND_FAILURE, t);
                    } finally {
                        try {
                            // XXX
                            _sourceSession.recover();
                        } catch (Throwable t1) {
                            _logger.log(Level.WARNING, "Unable to recover session for expired message " + mid + " in " + this, t1);
                            closeSource();
                            _sourceConnException = true;
                        }
                        closeTarget();
                        _targetConnException = true;
                        continue;
                    }
                }
            }
            try {
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_ACK_1, null, "jakarta.jms.JMSException", true);
                }
                if (_sourceCF.getRefed() instanceof com.sun.messaging.ConnectionFactory) {
                    ((com.sun.messaging.jmq.jmsclient.MessageImpl) m).acknowledgeThisMessage();
                } else {
                    m.acknowledge();
                }
                String[] param = { mid, midSent, this.toString() };
                if (_parent.logMessageTransfer()) {
                    _logger.log(Level.INFO, _jbr.getString(_jbr.I_MESSAGE_TRANSFER_SUCCESS, param));
                } else if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, _jbr.getString(_jbr.I_MESSAGE_TRANSFER_SUCCESS, param));
                }
                if (_fi.FAULT_INJECTION) {
                    _fi.setLogger(_logger);
                    _fi.checkFaultAndThrowException(FaultInjection.FAULT_ACK_2, null, "jakarta.jms.JMSException", true);
                }
            } catch (Throwable t) {
                currentThrowable = t;
                _logger.log(Level.SEVERE, "Failed to acknowledge message " + mid + " in " + this, t);
                sendToDMQ(m, mid, DMQ.DMQReason.ACK_FAILURE, t);
            }
            continue;
        } finally {
            if (!_targetStayConnected) {
                closeTarget();
            }
            if (currentThrowable == null) {
                consecutiveThrowables = 0;
            } else {
                consecutiveThrowables++;
                if (consecutiveThrowables > MAX_CONSECUTIVE_THROWABLES) {
                    throw new RuntimeException("Maximum consecutive exceptions exceeded", currentThrowable);
                }
            }
        }
    }
}
Also used : Message(jakarta.jms.Message) BridgeException(com.sun.messaging.bridge.api.BridgeException) JMSException(jakarta.jms.JMSException) HeuristicRollbackException(jakarta.transaction.HeuristicRollbackException) RollbackException(jakarta.transaction.RollbackException) HeuristicMixedException(jakarta.transaction.HeuristicMixedException) BridgeException(com.sun.messaging.bridge.api.BridgeException) XAConnectionFactory(jakarta.jms.XAConnectionFactory) MessageProducer(jakarta.jms.MessageProducer)

Example 5 with BridgeException

use of com.sun.messaging.bridge.api.BridgeException in project openmq by eclipse-ee4j.

the class BridgeImpl method start.

/**
 * Start the bridge
 *
 * @param bc the bridge context
 * @param args start parameters
 *
 * @return true if successfully started; false if started asynchronously
 *
 * @throws Exception if unable to start the bridge
 */
@Override
public synchronized boolean start(BridgeContext bc, String[] args) throws Exception {
    String linkName = parseLinkName(args);
    if (linkName != null) {
        if (_state != State.STARTED) {
            throw new IllegalStateException(JMSBridge.getJMSBridgeResources().getKString(JMSBridge.getJMSBridgeResources().X_LINKOP_ALLOWED_STATE, State.STARTED.toString(JMSBridge.getJMSBridgeResources())));
        }
        return _jmsbridge.start(linkName, null);
    }
    if (_state == State.STARTED) {
        return true;
    }
    if (_state == State.STARTING) {
        return false;
    }
    State oldstate = _state;
    _state = State.STARTING;
    boolean inited = false;
    try {
        _jmsbridge = new JMSBridge();
        _jmsbridge.init(bc, _name, parseResetArg(args));
        inited = true;
        try {
            if (_jmsbridge.start(parseLinkName(args), this)) {
                _state = State.STARTED;
                return true;
            } else {
                return false;
            }
        } catch (RejectedExecutionException e) {
            _state = oldstate;
            throw e;
        }
    } catch (Exception e) {
        try {
            stop(bc, null);
        } catch (Throwable t) {
        }
        if (!inited) {
            _jmsbridge = null;
            throw e;
        }
        throw new BridgeException(e.getMessage(), e, Status.CREATED);
    }
}
Also used : BridgeException(com.sun.messaging.bridge.api.BridgeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) BridgeException(com.sun.messaging.bridge.api.BridgeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

BridgeException (com.sun.messaging.bridge.api.BridgeException)16 Bridge (com.sun.messaging.bridge.api.Bridge)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Properties (java.util.Properties)5 Message (jakarta.jms.Message)3 DupKeyException (com.sun.messaging.bridge.api.DupKeyException)2 Destination (jakarta.jms.Destination)2 JMSException (jakarta.jms.JMSException)2 MessageProducer (jakarta.jms.MessageProducer)2 HeuristicMixedException (jakarta.transaction.HeuristicMixedException)2 HeuristicRollbackException (jakarta.transaction.HeuristicRollbackException)2 RollbackException (jakarta.transaction.RollbackException)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 ConnectionFactory (com.sun.messaging.ConnectionFactory)1 AdminMessageHandler (com.sun.messaging.bridge.admin.handlers.AdminMessageHandler)1 BridgeManagerResources (com.sun.messaging.bridge.admin.resources.BridgeManagerResources)1 BridgeCmdSharedReplyData (com.sun.messaging.bridge.api.BridgeCmdSharedReplyData)1