Search in sources :

Example 1 with InvalidClientIDException

use of jakarta.jms.InvalidClientIDException in project openmq by eclipse-ee4j.

the class JMSBridge method openConnection.

public static Connection openConnection(Object cf, int maximumAttempts, long attemptInterval, String username, String password, String logstr, Object caller, EventListener l, Logger logger, boolean doReconnect) throws Exception {
    if (l.hasEventOccurred()) {
        throw new JMSException("" + l.occurredEvent());
    }
    int maxAttempts = maximumAttempts;
    Connection conn = null;
    int attempts = 0;
    Exception ee = null;
    int invalidClientIDExceptionCnt = 0;
    do {
        if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedException(_jbr.getKString(_jbr.X_OPENCONNECTION_INTERRUPTED, cf.toString(), caller.toString()));
        }
        if (attempts > 0 && attemptInterval > 0) {
            Thread.sleep(attemptInterval);
        }
        try {
            String[] param = { (username == null ? "" : "[" + username + "]"), cf.toString(), caller.toString() };
            if (cf instanceof XAConnectionFactory) {
                logger.log(Level.INFO, _jbr.getString(_jbr.I_CREATING_XA_CONN, param));
                if (username == null) {
                    conn = ((XAConnectionFactory) cf).createXAConnection();
                } else {
                    conn = ((XAConnectionFactory) cf).createXAConnection(username, password);
                }
            } else {
                logger.log(Level.INFO, _jbr.getString(_jbr.I_CREATING_CONN, param));
                if (username == null) {
                    conn = ((ConnectionFactory) cf).createConnection();
                } else {
                    conn = ((ConnectionFactory) cf).createConnection(username, password);
                }
            }
            return conn;
        } catch (JMSException e) {
            attempts++;
            ee = e;
            Exception le = e.getLinkedException();
            if (e instanceof InvalidClientIDException) {
                invalidClientIDExceptionCnt++;
            }
            if (e instanceof JMSSecurityException || le instanceof JMSSecurityException || (e instanceof InvalidClientIDException && invalidClientIDExceptionCnt > 1)) {
                String[] eparam = { logstr, caller.toString(), attempts + "(" + attemptInterval + ")" };
                _logger.log(Level.SEVERE, _jbr.getKString(_jbr.W_EXCEPTION_CREATING_CONN, eparam), e);
                throw e;
            }
            String[] eparam = { logstr, caller.toString(), attempts + "(" + attemptInterval + "): " + e.getMessage() + (le == null ? "" : " - " + le.getMessage()) };
            _logger.log(Level.WARNING, _jbr.getKString(_jbr.W_EXCEPTION_CREATING_CONN, eparam));
            if (!doReconnect && (maxAttempts > 1 || maxAttempts < 0)) {
                throw new ProviderConnectException("Failed to connect to " + cf + ": " + e.getMessage() + (le == null ? "" : " - " + le.getMessage()));
            }
        }
    } while ((maxAttempts < 0 || attempts < maxAttempts) && !l.hasEventOccurred());
    if (l.hasEventOccurred()) {
        throw new JMSException("" + l.occurredEvent());
    }
    throw ee;
}
Also used : InvalidClientIDException(jakarta.jms.InvalidClientIDException) JMSSecurityException(jakarta.jms.JMSSecurityException) XAConnection(jakarta.jms.XAConnection) Connection(jakarta.jms.Connection) XAConnectionFactory(jakarta.jms.XAConnectionFactory) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) InvalidClientIDException(jakarta.jms.InvalidClientIDException) JMSSecurityException(jakarta.jms.JMSSecurityException)

Example 2 with InvalidClientIDException

use of jakarta.jms.InvalidClientIDException in project openmq by eclipse-ee4j.

the class ConnectionAdapter method _setClientIDForContext.

/**
 * Set clientID to the specified value, bypassing any checks as to whether calling setClientID is allowed at this time
 */
@Override
public void _setClientIDForContext(String clientID) {
    _loggerJC.entering(_className, "_setClientIDForContext()", clientID);
    checkClosed2();
    try {
        xac._setClientID(clientID);
    } catch (InvalidClientIDException ice) {
        throw new MQInvalidClientIDRuntimeException(ice);
    } catch (JMSException e) {
        throw new MQRuntimeException(e);
    }
}
Also used : InvalidClientIDException(jakarta.jms.InvalidClientIDException) MQInvalidClientIDRuntimeException(com.sun.messaging.jms.MQInvalidClientIDRuntimeException) JMSException(jakarta.jms.JMSException) MQRuntimeException(com.sun.messaging.jms.MQRuntimeException)

Aggregations

InvalidClientIDException (jakarta.jms.InvalidClientIDException)2 JMSException (jakarta.jms.JMSException)2 MQInvalidClientIDRuntimeException (com.sun.messaging.jms.MQInvalidClientIDRuntimeException)1 MQRuntimeException (com.sun.messaging.jms.MQRuntimeException)1 Connection (jakarta.jms.Connection)1 JMSSecurityException (jakarta.jms.JMSSecurityException)1 XAConnection (jakarta.jms.XAConnection)1 XAConnectionFactory (jakarta.jms.XAConnectionFactory)1 IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1