Search in sources :

Example 6 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class JMSDestination method getConfiguredRA.

/*  protected boolean isAConfig(String targetName) throws Exception {
                Domain domain = Globals.get(Domain.class);
                Configs configs = domain.getConfigs();
                List configsList = configs.getConfig();
                for (int i =0; i < configsList.size(); i++){
                    Config config = (Config)configsList.get(i);
                    if (targetName.equals(config.getName()))
                        return true;
                }
                return false;
                //ConfigContext con = com.sun.enterprise.admin.server.core.AdminService.getAdminService().getAdminContext().getAdminConfigContext();
                //return ServerHelper.isAConfig(con, targetName);
            } */
/*   protected JmsHost getDefaultJmsHost(JmsService jmsService){
            String defaultJmsHost = jmsService.getDefaultJmsHost();
            JmsHost jmsHost = null;
           if (defaultJmsHost == null || defaultJmsHost.equals("")) {
                 try {
                         jmsHost = jmsService.getJmsHost().get(0);
                 }catch (Exception e) {
                     ;
                 }
            } else {
                    for (JmsHost defaultHost: jmsService.getJmsHost())
                        if(defaultJmsHost.equals(defaultHost.getName()))
                            jmsHost = defaultHost;
            }
            return jmsHost;
        } */
/* protected Map<String, JmsHost> getResolvedLocalJmsHostsInCluster(String clusterName, MQAddressList list) {
             Map<String, JmsHost> map = new HashMap<String, JmsHost> ();

             Domain domain = Globals.get(Domain.class);
             Clusters clusters = domain.getClusters();
             List clusterList = clusters.getCluster();
             Cluster cluster = null;
             for (int i =0; i < clusterList.size(); i++){
                if (clusterName.equals(((Cluster)clusterList.get(i)).getName()))
                    cluster =    (Cluster)clusterList.get(i);
             }

        //final String myCluster      = ClusterHelper.getClusterByName(domainCC, clusterName).getName();
	    final Server[] buddies      = this.getServersInCluster(cluster);//ServerHelper.getServersInCluster(domainCC, myCluster);
        final Config cfg =  getConfigForServer(buddies[0]);

             final String myCluster      = ClusterHelper.getClusterByName(domainCC, clusterName).getName();
             final Server[] buddies      = ServerHelper.getServersInCluster(domainCC, myCluster);
             for (final Server as : buddies) {
             try {
                 final JmsHost copy   = getResolvedJmsHost(as);
                 map.put(as.getName(), copy);
                } catch (Exception e) {
                    // we dont add the host if we cannot get it
                    ;
                }
             }
             return map;
        } */
/*
         *  Configures an instance of MQ-RA with the connection URL passed in.
         *  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)) {
        logger.log(Level.FINE, " getConfiguredRA - set connectionURL as " + connectionURL);
    }
    if (adminuser != null) {
        Method setAdminUser = mqRAclassname.getMethod("set" + ActiveJmsResourceAdapter.ADMINUSERNAME, new Class[] { String.class });
        setAdminUser.invoke(raInstance, new Object[] { adminuser });
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, " getConfiguredRA - set admin user as " + adminuser);
        }
    }
    if (adminpasswd != null) {
        Method setAdminPasswd = mqRAclassname.getMethod("set" + ActiveJmsResourceAdapter.ADMINPASSWORD, new Class[] { String.class });
        setAdminPasswd.invoke(raInstance, new Object[] { adminpasswd });
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, " getConfiguredRA - set admin passwd as *****  ");
        }
    }
    return raInstance;
}
Also used : ActiveJmsResourceAdapter(com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter) ResourceAdapter(javax.resource.spi.ResourceAdapter) Method(java.lang.reflect.Method)

Example 7 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project cxf by apache.

the class ResourceAdapterImplTest method testConstructorWithProperties.

@Test
public void testConstructorWithProperties() throws Exception {
    Properties props = new Properties();
    ResourceAdapterImpl rai = new ResourceAdapterImpl(props);
    assertTrue("constructed with props", rai instanceof ResourceAdapterImpl);
    assertTrue("constructed with props", rai instanceof ResourceBean);
    assertTrue("constructed with props", rai instanceof ResourceAdapter);
    assertTrue("constructed with props", rai instanceof Serializable);
}
Also used : Serializable(java.io.Serializable) ResourceBean(org.apache.cxf.jca.core.resourceadapter.ResourceBean) ResourceAdapter(javax.resource.spi.ResourceAdapter) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class JMSDestination method _getMQJMXConnectorInfoForCluster.

/**
 *  Gets the <code>MQJMXConnector</code> object for a cluster. Since this code is
 *  executed in DAS, an admin API is used to resolve hostnames and ports of
 *  cluster instances for LOCAL type brokers while creating the connectionURL.
 */
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("")) {
                    jmxServiceURL = getFirstJMXServiceURL(jmxServiceURLList);
                }
            } else if (m.getName().equalsIgnoreCase("get" + JMXCONNECTORENV)) {
                jmxConnectorEnv = (Map<String, ?>) m.invoke(raInstance, new Object[] {});
            }
        }
        MQJMXConnectorInfo mqInfo = new MQJMXConnectorInfo(target, ActiveJmsResourceAdapter.getBrokerInstanceName(jmsService), jmsService.getType(), jmxServiceURL, jmxConnectorEnv);
        return mqInfo;
    } catch (Exception e) {
        e.printStackTrace();
        ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
        cre.initCause(e);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) MQAddressList(com.sun.enterprise.connectors.jms.system.MQAddressList) CommandTarget(org.glassfish.config.support.CommandTarget) Method(java.lang.reflect.Method) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) java.util(java.util) ActiveJmsResourceAdapter(com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter) ResourceAdapter(javax.resource.spi.ResourceAdapter) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost)

Example 9 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class AdministeredObjectResource method createAdministeredObject.

// called by com.sun.enterprise.naming.factory.AdministeredObjectFactory
// FIXME.  embedded??
public Object createAdministeredObject(ClassLoader jcl) throws PoolingException {
    try {
        if (jcl == null) {
            // use context class loader
            jcl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {

                public Object run() {
                    return Thread.currentThread().getContextClassLoader();
                }
            });
        }
        Object adminObject = jcl.loadClass(adminObjectClass_).newInstance();
        AccessController.doPrivileged(new SetMethodAction(adminObject, configProperties_));
        // associate ResourceAdapter if the admin-object is RAA
        if (adminObject instanceof ResourceAdapterAssociation) {
            try {
                ResourceAdapter ra = ConnectorRegistry.getInstance().getActiveResourceAdapter(resadapter_).getResourceAdapter();
                ((ResourceAdapterAssociation) adminObject).setResourceAdapter(ra);
            } catch (ResourceException ex) {
                _logger.log(Level.SEVERE, "rardeployment.assoc_failed", ex);
            }
        }
        // At this stage, administered object is instantiated, config properties applied
        // validate administered object
        // ConnectorRuntime should be available in CLIENT mode now as admin-object-factory would have bootstapped
        // connector-runtime.
        ConnectorRuntime.getRuntime().getConnectorBeanValidator().validateJavaBean(adminObject, resadapter_);
        return adminObject;
    } catch (PrivilegedActionException ex) {
        throw (PoolingException) (new PoolingException().initCause(ex));
    } catch (Exception ex) {
        throw (PoolingException) (new PoolingException().initCause(ex));
    }
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceAdapterAssociation(javax.resource.spi.ResourceAdapterAssociation) PrivilegedAction(java.security.PrivilegedAction) PrivilegedActionException(java.security.PrivilegedActionException) ResourceAdapter(javax.resource.spi.ResourceAdapter) AdminObject(com.sun.enterprise.deployment.AdminObject) ResourceException(javax.resource.ResourceException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) PrivilegedActionException(java.security.PrivilegedActionException) ResourceException(javax.resource.ResourceException) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 10 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project tomee by apache.

the class Assembler method doResourceDestruction.

private void doResourceDestruction(final String name, final String className, final Object jndiObject) {
    final ResourceBeforeDestroyed event = new ResourceBeforeDestroyed(jndiObject, name);
    SystemInstance.get().fireEvent(event);
    final Object object = event.getReplacement() == null ? jndiObject : event.getReplacement();
    if (object instanceof ResourceAdapterReference) {
        final ResourceAdapterReference resourceAdapter = (ResourceAdapterReference) object;
        try {
            logger.info("Stopping ResourceAdapter: " + name);
            if (logger.isDebugEnabled()) {
                logger.debug("Stopping ResourceAdapter: " + className);
            }
            if (resourceAdapter.pool != null && ExecutorService.class.isInstance(resourceAdapter.pool)) {
                ExecutorService.class.cast(resourceAdapter.pool).shutdownNow();
            }
            resourceAdapter.ra.stop();
        // remove associated JMX object
        } catch (final Throwable t) {
            logger.fatal("ResourceAdapter Shutdown Failed: " + name, t);
        }
        removeResourceMBean(name, "ResourceAdapter");
    } else 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);
        }
        removeResourceMBean(name, "ResourceAdapter");
    } else if (DataSourceFactory.knows(object)) {
        logger.info("Closing DataSource: " + name);
        try {
            DataSourceFactory.destroy(object);
        } catch (final Throwable t) {
        // Ignore
        }
    } else if (object instanceof ConnectorReference) {
        final ConnectorReference cr = (ConnectorReference) object;
        try {
            final ConnectionManager cm = cr.getConnectionManager();
            if (cm != null && cm instanceof AbstractConnectionManager) {
                ((AbstractConnectionManager) cm).doStop();
            }
        } catch (final Exception e) {
            logger.debug("Not processing resource on destroy: " + className, e);
        }
        removeResourceMBean(name, "ConnectionFactory");
    } else if (DestroyableResource.class.isInstance(object)) {
        try {
            DestroyableResource.class.cast(object).destroyResource();
        } catch (final RuntimeException e) {
            logger.error(e.getMessage(), e);
        }
        removeResourceMBean(name, "Resource");
    } else if (!DataSource.class.isInstance(object)) {
        removeResourceMBean(name, "Resource");
        if (logger.isDebugEnabled()) {
            logger.debug("Not processing resource on destroy: " + className);
        }
    }
}
Also used : DestroyableResource(org.apache.openejb.api.resource.DestroyableResource) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) ConnectionManager(javax.resource.spi.ConnectionManager) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ExecutorService(java.util.concurrent.ExecutorService) ResourceAdapter(javax.resource.spi.ResourceAdapter) ResourceBeforeDestroyed(org.apache.openejb.assembler.classic.event.ResourceBeforeDestroyed) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) ConnectorReference(org.apache.openejb.core.ConnectorReference) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Aggregations

ResourceAdapter (javax.resource.spi.ResourceAdapter)11 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)3 Method (java.lang.reflect.Method)3 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)2 MQAddressList (com.sun.enterprise.connectors.jms.system.MQAddressList)2 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 Serializable (java.io.Serializable)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Properties (java.util.Properties)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 DefinitionException (javax.enterprise.inject.spi.DefinitionException)2 DeploymentException (javax.enterprise.inject.spi.DeploymentException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2