Package javax.resource.spi

Examples of javax.resource.spi.ResourceAdapter


                // no resource adapters were created
            }
            while (namingEnumeration != null && namingEnumeration.hasMoreElements()) {
                Binding binding = namingEnumeration.nextElement();
                Object object = binding.getObject();
                ResourceAdapter resourceAdapter = (ResourceAdapter) object;
                try {
                    resourceAdapter.stop();
                } catch (Exception e) {
                    logger.fatal("ResourceAdapter Shutdown Failed: "+binding.getName(), e);
                }
            }
        } catch (Throwable 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;

            // resource adapters only work with a geronimo transaction manager
            if (!(transactionManager instanceof GeronimoTransactionManager)) {
                throw new OpenEJBException("The use of a resource adapter requires a Geronimo transaction manager");
            }
            GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;

            // create a thead pool
            int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
            if (threadPoolSize <= 0) throw new IllegalArgumentException("threadPoolSizes <= 0: " + threadPoolSize);
            Executor threadPool = Executors.newFixedThreadPool(threadPoolSize, new ResourceAdapterThreadFactory(serviceInfo.id));

            // create a work manager which the resource adapter can use to dispatch messages or perform tasks
            WorkManager workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, geronimoTransactionManager);

            // wrap the work mananger and transaction manager in a bootstrap context (connector spec thing)
            BootstrapContext bootstrapContext = new GeronimoBootstrapContext(workManager, geronimoTransactionManager);

            // 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

        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

        }

    }

    private void addResourceAdapter(ResourceAdapterWrapper resourceAdapterWrapper) {
        ResourceAdapter resourceAdapter = resourceAdapterWrapper.getResourceAdapter();
        if (resourceAdapter == null) {
            return;
        }
        if (registeredResouceAdapters.contains(resourceAdapterWrapper.getName())) {
            // already registered
            return;
        }
        registeredResouceAdapters.add(resourceAdapterWrapper.getName());
       
        Map<String, String> listenerToActivationSpecMap = resourceAdapterWrapper.getMessageListenerToActivationSpecMap();
        if (listenerToActivationSpecMap == null) {
            return;
        }

        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        try {
            for (Map.Entry<String, String> entry : listenerToActivationSpecMap.entrySet()) {
                String messageListenerInterface = entry.getKey();
                String activationSpecClass = entry.getValue();

                // only process RA if not previously processed
                String containerName = getResourceAdapterId(resourceAdapterWrapper) + "-" + messageListenerInterface;
                if (processedResourceAdapterWrappers.putIfAbsent(containerName,  resourceAdapterWrapper) == null) {
                    try {
                        // get default mdb config
                        ContainerInfo containerInfo = configurationFactory.configureService(MdbContainerInfo.class, containerName, null, null, "Container");
                        containerInfo.id = containerName;
                        containerInfo.displayName = containerName;

                        // set ra specific properties
                        containerInfo.properties.put("MessageListenerInterface",
                                resourceAdapter.getClass().getClassLoader().loadClass(messageListenerInterface));
                        containerInfo.properties.put("ActivationSpecClass",
                                resourceAdapter.getClass().getClassLoader().loadClass(activationSpecClass));
                        containerInfo.properties.put("ResourceAdapter", resourceAdapter);
                        containerInfo.properties.put("TxRecovery", true);
                        // create the container
                        assembler.createContainer(containerInfo);
View Full Code Here

    }

    public void testSetWrongResourceAdapterThrowException() throws Exception {
        TestableAssociatedManagedConnectionFactoryImpl mci =
            new TestableAssociatedManagedConnectionFactoryImpl();
        ResourceAdapter rai = EasyMock.createMock(ResourceAdapter.class);
        try {
            mci.setResourceAdapter(rai);
            fail("exception expected");
        } catch (ResourceException re) {
            assertTrue("wrong ResourceAdapter set", re.getMessage().indexOf("ResourceAdapterImpl") != -1);
View Full Code Here

        }

    }

    private void addResourceAdapter(ResourceAdapterWrapper resourceAdapterWrapper) {
        ResourceAdapter resourceAdapter = resourceAdapterWrapper.getResourceAdapter();
        if (resourceAdapter == null) {
            return;
        }
        if (registeredResouceAdapters.contains(resourceAdapterWrapper.getName())) {
            // already registered
            return;
        }
        registeredResouceAdapters.add(resourceAdapterWrapper.getName());
       
        Map<String, String> listenerToActivationSpecMap = resourceAdapterWrapper.getMessageListenerToActivationSpecMap();
        if (listenerToActivationSpecMap == null) {
            return;
        }

        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        try {
            for (Map.Entry<String, String> entry : listenerToActivationSpecMap.entrySet()) {
                String messageListenerInterface = entry.getKey();
                String activationSpecClass = entry.getValue();

                // only process RA if not previously processed
                String containerName = getResourceAdapterId(resourceAdapterWrapper) + "-" + messageListenerInterface;
                if (processedResourceAdapterWrappers.putIfAbsent(containerName,  resourceAdapterWrapper) == null) {
                    try {
                        // get default mdb config
                        ContainerInfo containerInfo = configurationFactory.configureService(MdbContainerInfo.class, containerName, null, null, "Container");
                        containerInfo.id = containerName;
                        containerInfo.displayName = containerName;
                        properties = (properties == null)?new Properties():properties;                       
                        String instanceLimit = (String)properties.get(containerName + "." + "InstanceLimit");                                               
                        if(instanceLimit != null){
                            containerInfo.properties.put("InstanceLimit", instanceLimit);
                        }

                        // set ra specific properties
                        containerInfo.properties.put("MessageListenerInterface",
                                resourceAdapter.getClass().getClassLoader().loadClass(messageListenerInterface));
                        containerInfo.properties.put("ActivationSpecClass",
                                resourceAdapter.getClass().getClassLoader().loadClass(activationSpecClass));
                        containerInfo.properties.put("ResourceAdapter", resourceAdapter);
                       // containerInfo.properties.put("TxRecovery", true);
                        // create the container
                        assembler.createContainer(containerInfo);
View Full Code Here

                } else {
                    if (logger.isLoggable(Level.FINE)) {
                        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);
                     }
                     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 {
                  if (logger.isLoggable(Level.FINE)) {
                      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});
            if (logger.isLoggable(Level.FINE)) {
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.