Search in sources :

Example 1 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class EndpointConsumer method _init.

protected void _init() throws ResourceException {
    if (!this.ra.getInAppClientContainer()) {
        AccessController.doPrivileged(new PrivilegedAction<Object>() {

            @Override
            public Object run() {
                System.setProperty("imq.DaemonThreads", "true");
                return null;
            }
        });
    // System.setProperty("imq.DaemonThreads", "true");
    }
    // ask the activation spec whether this endpoint should use RADirect
    // it will return true if the RA is configured to use RADirect and we haven't overridden addressList in the activation
    // spec
    useRADirect = this.aSpec.useRADirect();
    Object cfObj = null;
    String connectionFactoryLookup = aSpec.getConnectionFactoryLookup();
    if (connectionFactoryLookup != null) {
        try {
            cfObj = Util.jndiLookup(connectionFactoryLookup);
        } catch (NamingException e) {
            String errorMessage = "MQRA:EC:Invalid connectionFactoryLookup " + connectionFactoryLookup + " configured in ActivationSpec of MDB for no JNDI name found";
            throw new ResourceException(errorMessage, e);
        }
    }
    // Configure connection factory
    if (useRADirect) {
        JMSService jmsservice = this.ra._getJMSService();
        this.dcf = new com.sun.messaging.jms.ra.DirectConnectionFactory(jmsservice, null);
        if (cfObj != null) {
            DirectConnectionFactory cfd = (DirectConnectionFactory) cfObj;
            ManagedConnectionFactory mcf = cfd.getMCF();
            cfd.setMCF(mcf);
            aSpec.setMCF(mcf);
        }
        this.username = this.aSpec.getUserName();
        this.password = this.aSpec.getPassword();
    } else {
        xacf = new com.sun.messaging.XAConnectionFactory();
        try {
            if (cfObj != null) {
                ConnectionFactoryAdapter cfa = (ConnectionFactoryAdapter) cfObj;
                ManagedConnectionFactory mcf = cfa.getMCF();
                aSpec.setMCF(mcf);
            }
            // get addressList from activation spec or (suitably adjusted) from the resource adapter
            this.xacf.setProperty(ConnectionConfiguration.imqAddressList, aSpec._AddressList());
            // get addressListBehavior from activation spec or resource adapter
            xacf.setProperty(ConnectionConfiguration.imqAddressListBehavior, aSpec.getAddressListBehavior());
            // get username from activation spec or resource adapter
            this.xacf.setProperty(ConnectionConfiguration.imqDefaultUsername, aSpec.getUserName());
            // get password from activation spec or resource adapter
            this.xacf.setProperty(ConnectionConfiguration.imqDefaultPassword, aSpec.getPassword());
            // get addressListIterations from activation spec or resource adapter
            xacf.setProperty(ConnectionConfiguration.imqAddressListIterations, Integer.toString(aSpec.getAddressListIterations()));
            // get reconnectAttempts from activation spec or resource adapter
            this.xacf.setProperty(ConnectionConfiguration.imqReconnectAttempts, Integer.toString(aSpec.getReconnectAttempts()));
            // get reconnectEnabled from activation spec
            this.xacf.setProperty(ConnectionConfiguration.imqReconnectEnabled, Boolean.toString(aSpec.getReconnectEnabled()));
            // get reconnectInterval from activation spec or resource adapter
            this.xacf.setProperty(ConnectionConfiguration.imqReconnectInterval, Integer.toString(aSpec.getReconnectInterval()));
            // configure xacf with any additional connection factory properties defined in the activation spec
            setAdditionalConnectionFactoryProperties(aSpec.getOptions());
        } catch (JMSException jmse) {
            System.err.println("MQRA:EC:constr:Exception setting connection factory properties: " + jmse.getMessage());
        }
    }
    this.onMessageMethod = this.ra._getOnMessageMethod();
    this.exRedeliveryAttempts = this.aSpec.getEndpointExceptionRedeliveryAttempts();
    this.exRedeliveryInterval = this.aSpec.getEndpointExceptionRedeliveryInterval();
    this.mName = this.aSpec.getMdbName();
    this.selector = this.aSpec.getMessageSelector();
    this.subscriptionName = this.aSpec.getSubscriptionName();
    String cId = this.aSpec.getClientId();
    if ((cId != null) && !("".equals(cId)) && (cId.length() > 0)) {
        this.clientId = cId;
    } else {
        this.clientId = null;
    }
    try {
        this.isDeliveryTransacted = this.endpointFactory.isDeliveryTransacted(this.onMessageMethod);
    } catch (NoSuchMethodException ex) {
    // Assume delivery is non-transacted
    // Fix to throw NotSupportedException on activation
    // ex.printStackTrace();
    }
    setDestinationType();
    if (this.destinationType == ClientConstants.DESTINATION_TYPE_TOPIC) {
        // Will throw NotSupportedException if clientId not set properly
        setIsDurable();
    }
    checkSubscriptionScopeAndClientId();
    if (this.isDurable) {
        if (this.clientId == null && aSpec.getSubscriptionScope() == null) {
            // automatically generate client identifier
            if (aSpec._getGroupName() != null) {
                this.clientId = aSpec._getGroupName() + "{m:" + mName + "}";
            } else {
                this.clientId = "{m:" + mName + "}";
            }
        }
    } else {
        if ((aSpec._isNoAckDeliverySet()) && (this.destination instanceof com.sun.messaging.Topic) && (!this.isDeliveryTransacted)) {
            this.noAckDelivery = true;
        }
        if (aSpec._isInClusteredContainerSet()) {
            if (this.clientId == null && aSpec.getSubscriptionScope() == null) {
                if ((mName == null) || ("".equals(mName))) {
                    throw new NotSupportedException("MQRA:EC:Error:Clustered Message Consumer requires" + " non-null clientID OR mdbName:clientID=" + this.clientId + ":mdbName=" + mName);
                } else {
                    // set effective clientId from mName
                    if (aSpec._getGroupName() != null) {
                        this.clientId = aSpec._getGroupName() + "{m:" + mName + "}";
                    } else {
                        this.clientId = "{m:" + mName + "}";
                    }
                }
            }
        }
    }
    if (this.useRADirect) {
        this.createDirectMessageConsumer();
    } else {
        this.createRemoteMessageConsumer();
    }
}
Also used : JMSService(com.sun.messaging.jmq.jmsservice.JMSService) NamingException(javax.naming.NamingException) ResourceException(jakarta.resource.ResourceException) NotSupportedException(jakarta.resource.NotSupportedException)

Example 2 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class EndpointConsumer method stopRemoteMessageConsumer.

/**
 * Stops a consumer and connections associated with this EndpointConsumer
 */
public void stopRemoteMessageConsumer() throws Exception {
    stopping = true;
    synchronized (this) {
        com.sun.messaging.jmq.jmsclient.SessionImpl mqsess;
        // System.out.println("MQRA:EC:stopMessageConsumer()");
        if (msgConsumer != null) {
            try {
                if (msgListener != null) {
                    mqsess = xas;
                    // System.out.println("MQRA:EC:stopMessageConsumer:_stopFromRA:sessionId="+mqsess.getBrokerSessionID());
                    mqsess._stopFromRA();
                    // System.out.println("MQRA:EC:stopMessageConsumer:_stopFromRA-done/wfOMRs");
                    msgListener.waitForAllOnMessageRunners();
                    // System.out.println("MQRA:EC:stopMessageConsumer:wfOMRs-done/releaseOMRs");
                    msgListener.releaseOnMessageRunners();
                    // System.out.println("MQRA:EC:stopMessageConsumer:Done releasing OMRs/session.close()");
                    xas.close();
                // System.out.println("MQRA:EC:stopMessageConsumer:Done session.close()");
                }
            // System.out.println("MQRA:EC:stopMessageConsumer:_stopFromRA");
            // ////// <---((com.sun.messaging.jmq.jmsclient.SessionImpl)xas)._stopFromRA();
            // System.out.println("MQRA:EC:stopMessageConsumer:done _stopFromRA");
            // System.out.println("MQRA:EC:stopMessageConsumer:closing msgConsumer");
            // ///////////// msgConsumer.close();
            // System.out.println("MQRA:EC:stopMessageConsumer:closed msgConsumer...........................");
            } catch (JMSException jmse) {
                ResourceException re = new ResourceException("MQRA:EC:Error on closing MessageConsumer");
                re.initCause(jmse);
                throw re;
            }
        }
        if (xac != null) {
            try {
                xac.close();
            } catch (JMSException jmse) {
                ResourceException re = new ResourceException("MQRA:EC:Error closing JMS Connection");
                re.initCause(jmse);
                throw re;
            }
        }
    }
}
Also used : ResourceException(jakarta.resource.ResourceException)

Example 3 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class EndpointConsumer method createRemoteMessageConsumer.

/**
 * Creates a MessageConsumer associated with this EndpointConsumer after validating the passed in ActivationSpec
 * parameter. The MessageConsumer delivers the messages to a MessageEndpoint manufactured using the
 * MessageEndpointFactory passed in.
 */
private void createRemoteMessageConsumer() throws ResourceException {
    try {
        xac = (com.sun.messaging.jmq.jmsclient.XAConnectionImpl) xacf.createXAConnection();
        if (// This should never happen
        xac == null)
            throw new ResourceException("MQRA:EC:Error:createRemoteMessageConsumer failed: cannot create XAConnection");
        if ((aSpec._isInClusteredContainerSet())) {
            xac.setRANamespaceUID(aSpec._getRAUID());
        }
        _loggerIM.fine("MQRA:EC:createRemoteMessageConsumer setting clientID to " + this.clientId);
        if (this.clientId != null) {
            xac.setClientID(this.clientId);
        }
        xac.setExceptionListener(this);
        xac.setEventListener(this);
    } catch (JMSException jmse) {
        if (xac != null) {
            try {
                xac.close();
            } catch (JMSException jmsecc) {
            }
            xac = null;
        }
        if (logRCFailures) {
            jmse.printStackTrace();
        }
        throw new NotSupportedException("MQRA:EC:Error:createRemoteMessageConsumer failed:aborting due to:" + jmse.getMessage(), jmse);
    }
    // success
    try {
        if (this.isDurable) {
            this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        } else {
            if (noAckDelivery) {
                this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(com.sun.messaging.jms.Session.NO_ACKNOWLEDGE);
            } else {
                this.xas = (com.sun.messaging.jmq.jmsclient.XASessionImpl) xac.createSession(false, Session.CLIENT_ACKNOWLEDGE);
            }
        }
        xas._setRAEndpointSession();
        if (aSpec.getSubscriptionScope() != null) {
            subscriptionName = getSubscriptionName();
            if (this.isDurable) {
                msgConsumer = xas.createSharedDurableConsumer((Topic) destination, subscriptionName, aSpec.getMessageSelector());
            } else {
                msgConsumer = xas.createSharedConsumer((Topic) destination, subscriptionName, aSpec.getMessageSelector());
            }
        } else {
            if (this.isDurable) {
                msgConsumer = xas.createDurableSubscriber((Topic) destination, aSpec.getSubscriptionName(), aSpec.getMessageSelector(), false);
            } else {
                msgConsumer = xas.createConsumer(destination, aSpec.getMessageSelector());
                // test to see if Queue is enabled for more than one consumer when InClustered true
                if (destination instanceof jakarta.jms.Queue && aSpec._isInClusteredContainerSet()) {
                    // Fail activation if it is not
                    try {
                        msgConsumer2 = xas.createConsumer(destination, aSpec.getMessageSelector());
                        msgConsumer2.close();
                        msgConsumer2 = null;
                    } catch (JMSException jmse) {
                        try {
                            xac.close();
                        } catch (JMSException jmsecc) {
                        // System.out.println("MQRA:EC:closed xac on conn creation exception-"+jmsecc.getMessage());
                        }
                        xac = null;
                        throw new NotSupportedException("MQRA:EC:Error clustering multiple consumers on Queue:\n" + jmse.getMessage(), jmse);
                    }
                }
            }
        }
        msgListener = new MessageListener(this, this.endpointFactory, aSpec);
        // System.out.println("MQRA:EC:Created msgListener");
        // msgConsumer.setMessageListener(new MessageListener(this, epFactory, spec));
        msgConsumer.setMessageListener(msgListener);
        // System.out.println("MQRA:EC:Set msgListener");
        // System.out.println("MQRA:EC:Starting Connection");
        xac.start();
        updateFactoryConsumerTables(this.endpointFactory);
    } catch (JMSException jmse) {
        if (xac != null) {
            try {
                xac.close();
            } catch (JMSException jmsecc) {
            // System.out.println("MQRA:EC:closed xac on conn creation exception-"+jmsecc.getMessage());
            }
            xac = null;
        }
        throw new NotSupportedException("MQRA:EC:Error creating Remote Message Consumer:\n" + jmse.getMessage(), jmse);
    }
}
Also used : jakarta.jms(jakarta.jms) ResourceException(jakarta.resource.ResourceException) NotSupportedException(jakarta.resource.NotSupportedException)

Example 4 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class LocalTransaction method commit.

/**
 * Commit a local transaction
 */
@Override
public synchronized void commit() throws ResourceException {
    // System.out.println("MQRA:LT:commit()");
    try {
        if (!xac._isClosed()) {
            xac.getProtocolHandler().commit(transactionID, -1, null);
        } else {
            ResourceException re = new EISSystemException("MQRA:LT:commitTransaction exception:Connection is closed");
            throw re;
        }
    } catch (Exception ex) {
        ResourceException re = new EISSystemException("MQRA:LT:commit exception:" + ex.getMessage());
        re.initCause(ex);
        throw re;
    } finally {
        mc.setLTActive(false);
        started = false;
        active = false;
    }
}
Also used : EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException) EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException)

Example 5 with ResourceException

use of jakarta.resource.ResourceException in project openmq by eclipse-ee4j.

the class DirectLocalTransaction method rollback.

/**
 * Rollback a local transaction
 */
@Override
public synchronized void rollback() throws ResourceException {
    // System.out.println("MQRA:LT:rollback()");
    try {
        if (!dc.isClosed()) {
            this.dc._rollbackTransaction("DirectLocalTransaction.rollback()", this.transactionID);
        } else {
            ResourceException re = new EISSystemException("MQRA:LT:rillbackTransaction exception:Connection is closed");
            throw re;
        }
    } catch (Exception ex) {
        ResourceException re = new EISSystemException("MQRA:LT:rollback exception:" + ex.getMessage());
        re.initCause(ex);
        throw re;
    } finally {
        mc.setLTActive(false);
        started = false;
        active = false;
    }
}
Also used : EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException) EISSystemException(jakarta.resource.spi.EISSystemException) ResourceException(jakarta.resource.ResourceException)

Aggregations

ResourceException (jakarta.resource.ResourceException)14 EISSystemException (jakarta.resource.spi.EISSystemException)6 NotSupportedException (jakarta.resource.NotSupportedException)4 JMSException (jakarta.jms.JMSException)2 NamingException (javax.naming.NamingException)2 JMSService (com.sun.messaging.jmq.jmsservice.JMSService)1 jakarta.jms (jakarta.jms)1 InvalidPropertyException (jakarta.resource.spi.InvalidPropertyException)1 ResourceAdapter (jakarta.resource.spi.ResourceAdapter)1 ResourceAdapterInternalException (jakarta.resource.spi.ResourceAdapterInternalException)1 UnavailableException (jakarta.resource.spi.UnavailableException)1 MessageEndpoint (jakarta.resource.spi.endpoint.MessageEndpoint)1