Search in sources :

Example 1 with JMSService

use of com.sun.messaging.jmq.jmsservice.JMSService 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 JMSService

use of com.sun.messaging.jmq.jmsservice.JMSService in project openmq by eclipse-ee4j.

the class BrokerInstanceImpl method getJMSService.

/**
 * Return a JMSService that can be used to create legacy RADirect connections to this broker
 */
@Override
public JMSService getJMSService() {
    // This string is also hardcoded in
    // com.sun.messaging.jmq.jmsserver.management.mbeans.BrokerConfig.hasDirectConnections() and
    // com.sun.messaging.jmq.jmsserver.data.handlers.admin.ShutdownHandler.hasDirectConnections()
    String DEFAULT_DIRECTMODE_SERVICE_NAME = "jmsdirect";
    JMSService jmsService = getJMSService(DEFAULT_DIRECTMODE_SERVICE_NAME);
    if (jmsService != null) {
        return (jmsService);
    }
    /*
         * If "jmsdirect" is not available, loop through all services
         */
    List serviceNames = ServiceManager.getAllServiceNames();
    Iterator iter = serviceNames.iterator();
    while (iter.hasNext()) {
        jmsService = getJMSService((String) iter.next());
        if (jmsService != null) {
            return (jmsService);
        }
    }
    return (null);
}
Also used : Iterator(java.util.Iterator) List(java.util.List) JMSService(com.sun.messaging.jmq.jmsservice.JMSService)

Example 3 with JMSService

use of com.sun.messaging.jmq.jmsservice.JMSService in project openmq by eclipse-ee4j.

the class BrokerInstanceImpl method getJMSService.

private JMSService getJMSService(String serviceName) throws IllegalStateException {
    ServiceManager sm = Globals.getServiceManager();
    Service svc;
    IMQService imqSvc;
    IMQDirectService imqDirectSvc;
    if (sm == null) {
        return (null);
    }
    svc = sm.getService(serviceName);
    if (svc == null) {
        return (null);
    }
    if (!(svc instanceof IMQService)) {
        return (null);
    }
    imqSvc = (IMQService) svc;
    if (!imqSvc.isDirect()) {
        return (null);
    }
    if (!(imqSvc instanceof IMQDirectService)) {
        return (null);
    }
    imqDirectSvc = (IMQDirectService) imqSvc;
    return imqDirectSvc.getJMSService();
}
Also used : IMQDirectService(com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService) ServiceManager(com.sun.messaging.jmq.jmsserver.service.ServiceManager) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService) JMSService(com.sun.messaging.jmq.jmsservice.JMSService) IMQDirectService(com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService) Service(com.sun.messaging.jmq.jmsserver.service.Service) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService)

Example 4 with JMSService

use of com.sun.messaging.jmq.jmsservice.JMSService in project openmq by eclipse-ee4j.

the class JMSRA_BrokerProcess method getJMSService.

/**
 * Return the named JMS Service that supports 'DIRECT' in-JVM Java EEJMS clients.
 *
 * @param serviceName The name of the service to return
 *
 * @throws IllegalStateException if the broker is already stopped
 */
@Override
public JMSService getJMSService(String serviceName) throws IllegalStateException {
    ServiceManager sm = Globals.getServiceManager();
    Service svc;
    IMQService imqSvc;
    IMQDirectService imqDirectSvc;
    if (sm == null) {
        return (null);
    }
    svc = sm.getService(serviceName);
    if (svc == null) {
        return (null);
    }
    if (!(svc instanceof IMQService)) {
        return (null);
    }
    imqSvc = (IMQService) svc;
    if (!imqSvc.isDirect()) {
        return (null);
    }
    if (!(imqSvc instanceof IMQDirectService)) {
        return (null);
    }
    imqDirectSvc = (IMQDirectService) imqSvc;
    return imqDirectSvc.getJMSService();
}
Also used : IMQDirectService(com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService) ServiceManager(com.sun.messaging.jmq.jmsserver.service.ServiceManager) JMSService(com.sun.messaging.jmq.jmsservice.JMSService) IMQDirectService(com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService) Service(com.sun.messaging.jmq.jmsserver.service.Service) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService) IMQService(com.sun.messaging.jmq.jmsserver.service.imq.IMQService)

Example 5 with JMSService

use of com.sun.messaging.jmq.jmsservice.JMSService in project openmq by eclipse-ee4j.

the class JMSRA_BrokerProcess method getJMSService.

/**
 * Return the default JMS Service that supports 'DIRECT' in-JVM Java EE JMS clients.
 *
 * @throws IllegalStateException if the broker is already stopped
 */
@Override
public JMSService getJMSService() throws IllegalStateException {
    JMSService jmsService = getJMSService(DEFAULT_DIRECTMODE_SERVICE_NAME);
    if (jmsService != null) {
        return (jmsService);
    }
    /*
         * If "jmsdirect" is not available, loop through all services
         */
    List serviceNames = ServiceManager.getAllServiceNames();
    Iterator iter = serviceNames.iterator();
    while (iter.hasNext()) {
        jmsService = getJMSService((String) iter.next());
        if (jmsService != null) {
            return (jmsService);
        }
    }
    return (null);
}
Also used : Iterator(java.util.Iterator) List(java.util.List) JMSService(com.sun.messaging.jmq.jmsservice.JMSService)

Aggregations

JMSService (com.sun.messaging.jmq.jmsservice.JMSService)5 Service (com.sun.messaging.jmq.jmsserver.service.Service)2 ServiceManager (com.sun.messaging.jmq.jmsserver.service.ServiceManager)2 IMQDirectService (com.sun.messaging.jmq.jmsserver.service.imq.IMQDirectService)2 IMQService (com.sun.messaging.jmq.jmsserver.service.imq.IMQService)2 Iterator (java.util.Iterator)2 List (java.util.List)2 NotSupportedException (jakarta.resource.NotSupportedException)1 ResourceException (jakarta.resource.ResourceException)1 NamingException (javax.naming.NamingException)1