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 {
                resourceAdapter.start(bootstrapContext);
            } catch (ResourceAdapterInternalException e) {
                throw new OpenEJBException(e);
            }           
        } else if (service instanceof ManagedConnectionFactory) {
            ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
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

        }
        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());

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

                    resourceAdapter.stop();
                } catch (Throwable t) {
                    logger.fatal("ResourceAdapter Shutdown Failed: " + binding.getName(), t);
                }
            } else if (object instanceof org.apache.commons.dbcp.BasicDataSource) {
                logger.info("Closing DataSource: " + binding.getName());
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;
                TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(geronimoTransactionManager);
               
                // use id as default realm name if realm is not specified in service properties
                String securityRealmName = getStringProperty(serviceInfo.properties, "realm", serviceInfo.id);
                               
                SecurityContextHandler securityContextHandler = new SecurityContextHandler(securityRealmName);
                HintsContextHandler hintsContextHandler = new HintsContextHandler();
               
                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
            BootstrapContext bootstrapContext;
            if (transactionManager instanceof GeronimoTransactionManager) {
              bootstrapContext = new GeronimoBootstrapContext((GeronimoWorkManager)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 (ResourceAdapterInternalException e) {
                throw new OpenEJBException(e);
            }

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

    ResourceAdapterConfig raCfg = conn.getResourceAdapter();
   
    try {
      Class<?> raClass = raCfg.getResourceadapterClass();

      ResourceAdapter ra = (ResourceAdapter) raClass.newInstance();

      java.lang.reflect.Method init = raClass.getMethod("init", new Class[0]);

      if (init != null)
        init.invoke(ra, (Object []) null);
View Full Code Here

      }
    }

    // finally, close the resources
    for (int i = 0; i < resources.size(); i++) {
      ResourceAdapter resource = resources.get(i);

      try {
        resource.stop();
      } catch (Throwable e) {
        log.log(Level.WARNING, e.toString(), e);
      }
    }
  }
View Full Code Here

  {
    if (! _lifecycle.toStop())
      return;

    try {
      ResourceAdapter ra = _ra;

      if (ra != null)
        ra.stop();
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new StartLifecycleException(e);
    }
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

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.