Package javax.resource.spi

Examples of javax.resource.spi.ResourceAdapter


                    adminUserName = jmsHost.getAdminUserName();
                    adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
                } else {
                    logger.log(Level.FINE, " _getMQJMXConnectorInfo, using default jms admin user and password ");
                }
                ResourceAdapter raInstance = getConfiguredRA(mqRAClassName,
                            connectionURL, adminUserName, adminPassword);
                   String jmxServiceURL = null, jmxServiceURLList = null;
                   Map<String, ?> jmxConnectorEnv = null;
                   Method[] methds = raInstance.getClass().getMethods();
                   for (int i = 0; i < methds.length; i++) {
                       Method m = methds[i];
               if (m.getName().equalsIgnoreCase("get" + JMXSERVICEURLLIST)){
                           jmxServiceURLList = (String)m.invoke(raInstance, new Object[]{});
                       } else if (m.getName().equalsIgnoreCase("get" + JMXCONNECTORENV)){
View Full Code Here


          */
         protected  MQJMXConnectorInfo _getMQJMXConnectorInfoForCluster(
                         String target, JmsService jmsService, Class mqRAClassName, ServerContext serverContext)
                         throws ConnectorRuntimeException {
            // Create a new RA instance.
             ResourceAdapter raInstance = null;
             // Set the ConnectionURL
            MQAddressList list = null;
             try {
                 if (jmsService.getType().equalsIgnoreCase(ActiveJmsResourceAdapter.REMOTE)) {
                     list = getDefaultAddressList(jmsService);
                 } else {
                     list = new MQAddressList();
                     CommandTarget ctarget = this.getTypeForTarget(target);
                     if (ctarget == CommandTarget.CLUSTER)
                     {
                         Server[] servers = list.getServersInCluster(target);
                         if (servers != null && servers.length > 0)
                            list.setInstanceName(servers[0].getName());
                     } else if (ctarget == CommandTarget.CLUSTERED_INSTANCE ){
                         list.setInstanceName(target);
                     }
                     String domainurl  = serverContext.getServerConfigURL();
                     java.util.Map<String,JmsHost> hostMap =  list.getResolvedLocalJmsHostsInMyCluster(true);

                     if ( hostMap.size() == 0 ) {
                         String msg = localStrings.getLocalString("mqjmx.no_jms_hosts", "No JMS Hosts Configured");
                         throw new ConnectorRuntimeException(msg);

                     }


                     for (JmsHost host : hostMap.values()) {
                         list.addMQUrl(host);
                     }
                 }

              String connectionUrl = list.toString();
              String adminUserName = null;
              String adminPassword = null;
              JmsHost jmsHost = list.getDefaultJmsHost(jmsService);
              if (jmsHost != null){// && jmsHost.isEnabled()) {
                  adminUserName = jmsHost.getAdminUserName();
                  adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
              } else {
                  logger.log(Level.FINE, " _getMQJMXConnectorInfo, using default jms admin user and password ");
              }
               raInstance = getConfiguredRA(mqRAClassName, connectionUrl,
                                           adminUserName, adminPassword);
             } catch (Exception e) {
                 e.printStackTrace();
                 ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
                 cre.initCause(e);
                 throw cre;
             }

             try {
                 String jmxServiceURL = null, jmxServiceURLList = null;
                 Map<String, ?> jmxConnectorEnv = null;
                 Method[] methds = raInstance.getClass().getMethods();
                 for (int i = 0; i < methds.length; i++) {
                     Method m = methds[i];
                     if (m.getName().equalsIgnoreCase("get" + JMXSERVICEURLLIST)){
                         jmxServiceURLList = (String)m.invoke(raInstance, new Object[]{});
                         if (jmxServiceURLList != null && !jmxServiceURLList.trim().equals("")){
View Full Code Here

         *  This configured RA is then used to obtain the JMXServiceURL/JMXServiceURLList
         */
        protected ResourceAdapter getConfiguredRA(Class mqRAclassname,
                                                  String connectionURL, String adminuser,
                                                  String adminpasswd) throws Exception {
            ResourceAdapter raInstance = (ResourceAdapter) mqRAclassname.newInstance();
            Method setConnectionURL = mqRAclassname.getMethod(
                           "set" + ActiveJmsResourceAdapter.CONNECTION_URL,
                            new Class[] { String.class});
            setConnectionURL.invoke(raInstance, new Object[] {connectionURL});
            logger.log(Level.FINE, " getConfiguredRA - set connectionURL as " + connectionURL);
View Full Code Here

        }
        while (namingEnumeration != null && namingEnumeration.hasMoreElements()) {
            Binding binding = namingEnumeration.nextElement();
            Object object = binding.getObject();
            if (object instanceof ResourceAdapter) {
                ResourceAdapter resourceAdapter = (ResourceAdapter) object;
                try {
                    logger.info("Stopping ResourceAdapter: " + binding.getName());
                    resourceAdapter.stop();
                } catch (Exception e) {
                    logger.fatal("ResourceAdapter Shutdown Failed: " + binding.getName(), e);
                }
            }
        }
View Full Code Here

        Object service = serviceRecipe.create();


        // Java Connector spec ResourceAdapters and ManagedConnectionFactories need special activation
        if (service instanceof ResourceAdapter) {
            ResourceAdapter resourceAdapter = (ResourceAdapter) service;

            // Create a thead pool for work manager
            int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
            Executor threadPool;
            if (threadPoolSize <= 0) {
                threadPool = Executors.newCachedThreadPool(new ResourceAdapterThreadFactory(serviceInfo.id));
            } else {
                threadPool = Executors.newFixedThreadPool(threadPoolSize, new ResourceAdapterThreadFactory(serviceInfo.id));
            }

            // WorkManager: the resource adapter can use this to dispatch messages or perform tasks
            WorkManager workManager;
            if (transactionManager instanceof GeronimoTransactionManager) {
                GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
                workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, geronimoTransactionManager);
            } else {
                workManager = new SimpleWorkManager(threadPool);
            }


            // BootstrapContext: wraps the WorkMananger and XATerminator
            BootstrapContext bootstrapContext;
            if (transactionManager instanceof XATerminator) {
                bootstrapContext = new SimpleBootstrapContext(workManager, (XATerminator) transactionManager);
            } else {
                bootstrapContext = new SimpleBootstrapContext(workManager);
            }

            // start the resource adapter
            try {
                logger.debug("createResource.startingResourceAdapter", serviceInfo.id, service.getClass().getName());
                resourceAdapter.start(bootstrapContext);
            } catch (ResourceAdapterInternalException e) {
                throw new OpenEJBException(e);
            }

            Map<String, Object> unset = serviceRecipe.getUnsetProperties();
View Full Code Here

            activeResourceAdapterName = defaultResourceAdapterServiceInjectedValue.getValue().getDefaultResourceAdapterName();
        else
            activeResourceAdapterName = resourceAdapterName;
        final ActivationSpec activationSpec = getEndpointDeployer().createActivationSpecs(activeResourceAdapterName, messageListenerInterface, activationProps, getDeploymentClassLoader());
        final MessageDrivenComponent component = new MessageDrivenComponent(this, messageListenerInterface, activationSpec);
        final ResourceAdapter resourceAdapter = this.resourceAdapterInjectedValue.getValue();
        component.setResourceAdapter(resourceAdapter);
        return component;
    }
View Full Code Here

        return resources;
    }

    private static void destroyResource(final String name, final String className, final Object object) {
        if (object instanceof ResourceAdapter) {
            final ResourceAdapter resourceAdapter = (ResourceAdapter) object;
            try {
                logger.info("Stopping ResourceAdapter: " + name);

                if (logger.isDebugEnabled()) {
                    logger.debug("Stopping ResourceAdapter: " + className);
                }

                resourceAdapter.stop();
            } catch (final Throwable t) {
                logger.fatal("ResourceAdapter Shutdown Failed: " + name, t);
            }
        } else if (DataSourceFactory.knows(object)) {
            logger.info("Closing DataSource: " + name);
View Full Code Here

            } // else proxy would be useless
        }

        // Java Connector spec ResourceAdapters and ManagedConnectionFactories need special activation
        if (service instanceof ResourceAdapter) {
            final ResourceAdapter resourceAdapter = (ResourceAdapter) service;

            // Create a thead pool for work manager
            final int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
            final Executor threadPool;
            if (threadPoolSize <= 0) {
                logger.warning("Thread pool for '" + serviceInfo.id + "' is (unbounded), consider setting a size using: " + serviceInfo.id + ".QueueSize=[size]");
                threadPool = Executors.newCachedThreadPool(new DaemonThreadFactory(serviceInfo.id + "-worker-"));
            } else {
                threadPool = new ExecutorBuilder()
                    .size(threadPoolSize)
                    .prefix(serviceInfo.id)
                    .threadFactory(new DaemonThreadFactory(serviceInfo.id + "-worker-"))
                    .build(new Options(serviceInfo.properties, SystemInstance.get().getOptions()));
                logger.info("Thread pool size for '" + serviceInfo.id + "' is (" + threadPoolSize + ")");
            }

            // WorkManager: the resource adapter can use this to dispatch messages or perform tasks
            final WorkManager workManager;
            if (GeronimoTransactionManager.class.isInstance(transactionManager)) {
                final GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
                final TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(geronimoTransactionManager);

                // use id as default realm name if realm is not specified in service properties
                final String securityRealmName = getStringProperty(serviceInfo.properties, "realm", serviceInfo.id);

                final SecurityContextHandler securityContextHandler = new SecurityContextHandler(securityRealmName);
                final HintsContextHandler hintsContextHandler = new HintsContextHandler();

                final Collection<WorkContextHandler> workContextHandlers = new ArrayList<WorkContextHandler>();
                workContextHandlers.add(txWorkContextHandler);
                workContextHandlers.add(securityContextHandler);
                workContextHandlers.add(hintsContextHandler);

                workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, workContextHandlers);
            } else {
                workManager = new SimpleWorkManager(threadPool);
            }

            // BootstrapContext: wraps the WorkMananger and XATerminator
            final BootstrapContext bootstrapContext;
            if (transactionManager instanceof GeronimoTransactionManager) {
                bootstrapContext = new GeronimoBootstrapContext(GeronimoWorkManager.class.cast(workManager),
                    (GeronimoTransactionManager) transactionManager,
                    (GeronimoTransactionManager) transactionManager);
            } else if (transactionManager instanceof XATerminator) {
                bootstrapContext = new SimpleBootstrapContext(workManager, (XATerminator) transactionManager);
            } else {
                bootstrapContext = new SimpleBootstrapContext(workManager);
            }

            // start the resource adapter
            try {
                logger.debug("createResource.startingResourceAdapter", serviceInfo.id, service.getClass().getName());
                resourceAdapter.start(bootstrapContext);
            } catch (final ResourceAdapterInternalException e) {
                throw new OpenEJBException(e);
            }

            final Map<String, Object> unset = serviceRecipe.getUnsetProperties();
View Full Code Here

    }


    //GBeanLifecycle implementation
    public void activate(final MessageEndpointFactory messageEndpointFactory) throws ResourceException {
        ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter();
        if (resourceAdapter == null) {
            resourceAdapterWrapper.registerResourceAdapterAssociation(activationSpec);
        }
        resourceAdapterWrapper.endpointActivation(messageEndpointFactory, activationSpec);
    }
View Full Code Here

        }
        resourceAdapterWrapper.endpointActivation(messageEndpointFactory, activationSpec);
    }

    public void deactivate(final MessageEndpointFactory messageEndpointFactory) {
        ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter();
        if (resourceAdapter != null) {
            resourceAdapterWrapper.endpointDeactivation(messageEndpointFactory, activationSpec);
        } else {
            //this should never happen, activation spec should have been registered with r.a.
            throw new IllegalStateException("ActivationSpec was never registered with ResourceAdapter");
View Full Code Here

TOP

Related Classes of javax.resource.spi.ResourceAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.