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