Java tutorial
package com.app.server; /*Copyright 2013 - 2015, Arun_Soundararajan (arun_srajan_2007@yahoo.com).and/or its affiliates. All files in this repository or distribution are licensed under the Apache License, Version 2.0 (the "License"); you may not use any files in this repository or distribution except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.*/ import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.net.URISyntaxException; import java.net.URL; import java.rmi.Remote; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Queue; import javax.jms.Session; import javax.jms.Topic; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.naming.Context; import javax.naming.InitialContext; import javax.resource.spi.ActivationSpec; import javax.resource.spi.ResourceAdapter; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSelectInfo; import org.apache.commons.vfs2.FileSelector; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.impl.StandardFileSystemManager; import org.apache.commons.vfs2.impl.VFSClassLoader; import org.apache.log4j.Logger; import org.hornetq.jms.server.embedded.EmbeddedJMS; import com.app.server.connector.Adapter; import com.app.server.connector.ConfigProperty; import com.app.server.connector.RARArchiveData; import com.app.server.connector.impl.MessageEndPointFactoryImpl; import ejb.annotations.Stateful; import ejb.annotations.Stateless; import ejb.container.BeanPool; import ejb.container.EJBContainer; import ejb.container.ProxyFactory; public class EJBDeployer implements EJBDeployerMBean { private Registry registry; private HashMap<String, Vector<EJBContext>> jarEJBMap = new HashMap<String, Vector<EJBContext>>(); private ConcurrentHashMap<String, ConcurrentHashMap<String, MDBContext>> jarMDBMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, MDBContext>>(); EmbeddedJMS jms; ConnectionFactory connectionFactory; Logger log = Logger.getLogger(EJBDeployer.class); private Vector deployerList; private String isdeployer; private ObjectName objName; Vector serviceList; ServerConfig serverConfig; MBeanServer mbeanServer; private int serviceRegistryPort; private InitialContext ic; private RemoteBindingInterface remoteBindingInterface; private ObjectName rarDeployerName; Object obj = null; Object obj1 = null; Object proxyobj = null; static Vector<Object> staticObjs = null; static ConcurrentHashMap<String, Vector<Object>> staticObjsEjbMap = new ConcurrentHashMap<String, Vector<Object>>(); StandardFileSystemManager fsManager; private CopyOnWriteArrayList<String> jarsDeployed = new CopyOnWriteArrayList<String>(); public boolean accept(URL url) { try { File file = new File(url.toURI()); return file.getName().toLowerCase().endsWith(".jar"); } catch (Exception e) { log.error("Syntax of the uri is incorrect " + url, e); // TODO Auto-generated catch block //e.printStackTrace(); } return false; } public void init(Vector deployerlist) { this.deployerList = deployerlist; } public String getDeployer() { return this.isdeployer; } public void setDeployer(String isdeployer) { this.isdeployer = isdeployer; } public void setObjectName(ObjectName objName) { this.objName = objName; } public ObjectName getObjectName() { return this.objName; } public void init(Vector serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) { this.serviceList = serviceList; this.serverConfig = serverConfig; this.mbeanServer = mbeanServer; this.serviceRegistryPort = Integer.parseInt(serverConfig.getServicesregistryport()); //System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); //System.setProperty(Context.PROVIDER_URL, "rmi://localhost:"+serverConfig.getServicesregistryport());; try { fsManager = new StandardFileSystemManager(); System.setProperty("java.io.tmpdir", serverConfig.getCachedir()); /*DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator);*/ fsManager.init(); registry = LocateRegistry.createRegistry(Integer.parseInt(serverConfig.getServicesregistryport())); try { ic = new InitialContext(); Context subctx = null; try { subctx = (Context) ic.lookup("java:"); } catch (Exception ex) { log.error("Error in getting the java context", ex); //ex.printStackTrace(); } if (subctx == null) { ic.createSubcontext("java:"); } remoteBindingInterface = new RemoteBindingObject(ic); Object jndilookupobj = UnicastRemoteObject.exportObject((Remote) remoteBindingInterface, this.serviceRegistryPort); //registry.rebind("RemoteBindingObject", (Remote) jndilookupobj); } catch (Exception ex) { log.error("error in registring to the remote binding object", ex); //e1.printStackTrace(); } this.jms = new EmbeddedJMS(); this.jms.start(); } catch (Exception e) { log.error("error in initialization", e); // TODO Auto-generated catch block //e.printStackTrace(); } connectionFactory = (ConnectionFactory) jms.lookup("java:/ConnectionFactory"); log.info("initialized"); } public void start() { this.deployerList.add(objName.getCanonicalName()); log.info("started"); } public void stop() { log.info("stopped"); } public void destroy() { this.deployerList.remove(this.objName.getCanonicalName()); log.info("destroyed"); } public void deploy(URL url) { deployEjbJar(url, fsManager, null); } public void deploy(URL url, StandardFileSystemManager manager, ClassLoader cL) { deployEjbJar(url, manager, cL); } public void deployEjbJar(URL url, StandardFileSystemManager manager, ClassLoader cL) { try { Vector<EJBContext> ejbContexts = null; EJBContext ejbContext; log.info(url.toURI()); ConcurrentHashMap<String, RARArchiveData> rardata = (ConcurrentHashMap<String, RARArchiveData>) mbeanServer .getAttribute(rarDeployerName, "RARArchiveDataAllAdapters"); Collection<RARArchiveData> rarcls = rardata.values(); Iterator<RARArchiveData> rarcl = rarcls.iterator(); RARArchiveData rararcdata; FileObject filetoScan = manager.resolveFile("jar:" + url.toString() + "!/"); HashSet<Class<?>>[] classes = new HashSet[] { new HashSet(), new HashSet(), new HashSet() }; VFSClassLoader jarCL; if (cL != null) { jarCL = new VFSClassLoader(new FileObject[] { filetoScan }, manager, cL); } else { jarCL = new VFSClassLoader(new FileObject[] { filetoScan }, manager, Thread.currentThread().getContextClassLoader()); } Class[] annot = new Class[] { Stateless.class, Stateful.class, MessageDriven.class }; scanJar(filetoScan, classes, annot, jarCL); Set<Class<?>> clsStateless = classes[0]; Set<Class<?>> clsStateful = classes[1]; Set<Class<?>> clsMessageDriven = classes[2]; //System.gc(); staticObjs = null; EJBContainer container = EJBContainer.getInstance(classes); container.inject(); if (clsStateless.size() > 0) { staticObjs = new Vector<Object>(); ejbContexts = new Vector<EJBContext>(); ejbContext = new EJBContext(); ejbContext.setJarPath(url.toString()); ejbContext.setJarDeployed(url.toString()); for (Class<?> ejbInterface : clsStateless) { BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); proxyobj = factory.createWithBean(obj); staticObjs.add(proxyobj); Object unicastobj = UnicastRemoteObject.exportObject((Remote) proxyobj, 0); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { // registry.unbind(remoteBinding); ic.bind("java:/" + remoteBinding, (Remote) unicastobj); ejbContext.put(remoteBinding, obj.getClass()); //registry.rebind(remoteBinding, (Remote)unicastobj); } // registry.rebind("name", (Remote) obj); } ejbContexts.add(ejbContext); jarEJBMap.put(url.toString(), ejbContexts); } if (clsStateful.size() > 0) { if (staticObjs == null) { staticObjs = new Vector<Object>(); } if (ejbContexts == null) { ejbContexts = new Vector<EJBContext>(); } ejbContext = new EJBContext(); ejbContext.setJarPath(url.toString()); ejbContext.setJarDeployed(url.toString()); StatefulBeanObject statefulBeanObject = null; for (Class<?> ejbInterface : clsStateful) { BeanPool.getInstance().create(ejbInterface); obj1 = ejbInterface.newInstance(); if (statefulBeanObject == null) { statefulBeanObject = new StatefulBeanObject(obj1, url.toString()); } else { statefulBeanObject.addStatefulSessionBeanObject(obj1); } //System.out.println(obj1); staticObjs.add(statefulBeanObject); /*Object unicastobj1 = UnicastRemoteObject.exportObject( (Remote) obj1, 0);*/ String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + statefulBeanObject); if (remoteBinding != null) { // registry.unbind(remoteBinding); ic.bind("java:/" + remoteBinding, statefulBeanObject); ejbContext.put(remoteBinding, statefulBeanObject.getClass()); //registry.rebind(remoteBinding, (Remote)unicastobj1); } // registry.rebind("name", (Remote) obj); } ejbContexts.add(ejbContext); jarEJBMap.put(url.toString(), ejbContexts); } if (clsMessageDriven.size() > 0) { MDBContext mdbContext = null; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(url.toString()) != null) { mdbContexts = jarMDBMap.get(url.toString()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(url.toString(), mdbContexts); MDBContext mdbContextOld; for (Class<?> mdbBean : clsMessageDriven) { String classwithpackage = mdbBean.getName(); //System.out.println("class package" + classwithpackage); classwithpackage = classwithpackage.replace("/", "."); //System.out.println("classList:" // + classwithpackage.replace("/", ".")); final Class mdbBeanCls = mdbBean; try { if (!classwithpackage.contains("$")) { // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); // System.out.println(); if (!mdbBean.isInterface()) { Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations(); if (classServicesAnnot != null) { Adapter adapter = null; ActivationConfigProperty[] activationConfigProp = null; for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof Adapter) { adapter = (Adapter) classServicesAnnot[annotcount]; } else if (classServicesAnnot[annotcount] instanceof MessageDriven) { MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount]; activationConfigProp = messageDrivenAnnot.activationConfig(); mdbContext = new MDBContext(); mdbContext.setMdbName(messageDrivenAnnot.name()); } } if (adapter != null) { /*if(rarcl.hasNext()){ rararcdata=rardata.get(rarDeployerName); rararcdata=rarcl.next(); //classLoader = new VFSClassLoader(rararcdata.getVfsClassLoader().getFileObjects(),rararcdata.getFsManager(),classLoader); FileObject[] fileObjectArray=rararcdata.getVfsClassLoader().getFileObjects(); //urlset.addAll(ClasspathHelper.forClassLoader(rararcdata.getVfsClassLoader())); for(FileObject fileObject:fileObjectArray){ fileObjects.add(fileObject.getURL()); //urlset.add(fileObject.getURL()); //System.out.println(Vfs.fromURL(fileObject.getURL()).getFiles().iterator().next().getRelativePath()); } classLoader = new URLClassLoader(fileObjects.toArray(new URL[fileObjects.size()]),Thread.currentThread().getContextClassLoader()); }*/ RARArchiveData rarArchiveData = (RARArchiveData) mbeanServer.invoke( rarDeployerName, "getRARArchiveData", new Object[] { adapter.adapterName() }, new String[] { String.class.getName() }); if (rarArchiveData == null) throw new Exception("RAR Adapter " + adapter.adapterName() + " Not found in deploy folder"); Class resourceAdapterClass = rarArchiveData.getResourceAdapterClass(); final ResourceAdapter resourceAdapter = (ResourceAdapter) resourceAdapterClass .newInstance(); Class activationSpecClass = rarArchiveData.getActivationspecclass(); final ActivationSpec activationSpec = (ActivationSpec) activationSpecClass .newInstance(); Vector<ConfigProperty> configProperties = rarArchiveData.getConfigPropery(); Integer configPropertyInteger; Long configPropertyLong; Boolean configPropertyBoolean; Method method; if (configProperties != null) { for (ConfigProperty configProperty : configProperties) { String property = configProperty.getConfigpropertyname(); property = (property.charAt(0) + "").toUpperCase() + property.substring(1); Class propertytype = Class .forName(configProperty.getConfigpropertytype()); try { method = activationSpecClass.getMethod("set" + property, propertytype); if (propertytype == String.class) { method.invoke(activationSpec, configProperty.getConfigpropertyvalue()); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } else if (propertytype == Integer.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyInteger = new Integer( configProperty.getConfigpropertyvalue()); try { method.invoke(activationSpec, configPropertyInteger); } catch (Exception ex) { method.invoke(activationSpec, configPropertyInteger.intValue()); } ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } else if (propertytype == Long.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyLong = new Long( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyLong); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } else if (propertytype == Boolean.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyBoolean = new Boolean( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyBoolean); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } } catch (Exception ex) { try { if (propertytype == Integer.class) { method = activationSpecClass.getMethod("set" + property, int.class); if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, int.class); configPropertyInteger = new Integer( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyInteger.intValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } else if (propertytype == Long.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, long.class); configPropertyLong = new Long( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyLong.longValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } else if (propertytype == Boolean.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, boolean.class); configPropertyBoolean = new Boolean( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyBoolean.booleanValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } catch (Exception ex1) { ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } //log.error("Could not set Configuration for rar activation spec", ex); } } } for (ActivationConfigProperty activationConfig : activationConfigProp) { String property = activationConfig.propertyName(); property = (property.charAt(0) + "").toUpperCase() + property.substring(1); try { method = activationSpecClass.getMethod("set" + property, String.class); method.invoke(activationSpec, activationConfig.propertyValue()); } catch (Exception ex) { try { method = activationSpecClass.getMethod("set" + property, boolean.class); method.invoke(activationSpec, new Boolean(activationConfig.propertyValue())); } catch (Exception ex1) { method = activationSpecClass.getMethod("set" + property, Boolean.class); method.invoke(activationSpec, new Boolean(activationConfig.propertyValue())); } } } final Class listenerClass = rarArchiveData.getMessagelistenertype(); ClassLoader cCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread() .setContextClassLoader(resourceAdapter.getClass().getClassLoader()); resourceAdapter .start(new com.app.server.connector.impl.BootstrapContextImpl()); MessageEndPointFactoryImpl messageEndPointFactoryImpl = new MessageEndPointFactoryImpl( listenerClass, mdbBeanCls.newInstance(), jarCL); resourceAdapter.endpointActivation(messageEndPointFactoryImpl, activationSpec); Thread.currentThread().setContextClassLoader(cCL); if (mdbContext != null) { mdbContext.setResourceAdapter(resourceAdapter); mdbContext.setMessageEndPointFactory(messageEndPointFactoryImpl); mdbContext.setActivationSpec(activationSpec); mdbContexts.put(mdbContext.getMdbName(), mdbContext); } /*new Thread(){ public void run(){ try { resourceAdapter.endpointActivation(new com.app.server.connector.impl.MessageEndPointFactoryImpl(listenerClass, mdbBeanCls.newInstance(),raCl), activationSpec); } catch ( Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start();*/ } else { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof MessageDriven) { MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount]; ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot .activationConfig(); mdbContext = new MDBContext(); mdbContext.setMdbName(messageDrivenAnnot.name()); for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) { if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATIONTYPE)) { mdbContext.setDestinationType( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATION)) { mdbContext.setDestination( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.ACKNOWLEDGEMODE)) { mdbContext.setAcknowledgeMode( activationConfigProperty.propertyValue()); } } if (mdbContext.getDestinationType().equals(Queue.class.getName())) { mdbContextOld = null; if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts.get(mdbContext.getMdbName()); if (mdbContextOld != null && mdbContext.getDestination() .equals(mdbContextOld.getDestination())) { throw new Exception( "Only one MDB can listen to destination:" + mdbContextOld.getDestination()); } } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Queue queue = (Queue) jms.lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext .getAcknowledgeMode().equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session.createConsumer(queue); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Queue=" + queue); } else if (mdbContext.getDestinationType() .equals(Topic.class.getName())) { if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts.get(mdbContext.getMdbName()); if (mdbContextOld.getConsumer() != null) mdbContextOld.getConsumer().setMessageListener(null); if (mdbContextOld.getSession() != null) mdbContextOld.getSession().close(); if (mdbContextOld.getConnection() != null) mdbContextOld.getConnection().close(); } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Topic topic = (Topic) jms.lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext .getAcknowledgeMode().equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session.createConsumer(topic); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Topic=" + topic); } } } } } } } } catch (Exception e) { log.error("Error : ", e); // TODO Auto-generated catch block //e.printStackTrace(); } } } if (staticObjs != null) { staticObjsEjbMap.put(url.toString(), staticObjs); } this.jarsDeployed.add(url.toURI().toString()); log.info(url.toString() + " Deployed"); } catch (Exception ex) { log.error("Error in deploying the jar file: " + url, ex); //ex.printStackTrace(); } finally { /*if(classLoader!=null){ try { classLoader.close(); } catch (Exception e) { log.error("error in closing the classloader", e); // TODO Auto-generated catch block //e.printStackTrace(); } ClassLoaderUtil.closeClassLoader(classLoader); }*/ } } public void scanJar(FileObject jarFile, HashSet<Class<?>>[] classanotwith, Class[] annot, ClassLoader cL) throws FileSystemException { //FileObject[] childs=jarFile.getChildren(); //for(FileObject child:childs){ FileObject[] classes = jarFile.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo arg0) throws Exception { return arg0.getFile().getName().getBaseName().endsWith(".class"); } @Override public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { // TODO Auto-generated method stub return true; } }); //} int index = 0; for (FileObject cls : classes) { try { Class<?> clz = cL.loadClass(cls.getURL().toURI().toString() .replace(jarFile.getURL().toURI().toString(), "").replace("/", ".").replace(".class", "")); index = 0; for (Class annotclz : annot) { if (clz.getAnnotation(annotclz) != null) { classanotwith[index].add(clz); } index++; } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void ConfigResourceAdapter(Class resourceAdapterClass, Class propertytype, ResourceAdapter resourceAdapter, String property, ConfigProperty configProperty) { try { Method method = resourceAdapterClass.getMethod("set" + property, propertytype); if (propertytype == String.class) { method.invoke(resourceAdapter, configProperty.getConfigpropertyvalue()); } else if (propertytype == Integer.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue().equalsIgnoreCase("")) { Integer configPropertyInteger = new Integer(configProperty.getConfigpropertyvalue()); method.invoke(resourceAdapter, configPropertyInteger); } } else if (propertytype == Long.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue().equalsIgnoreCase("")) { Long configPropertyLong = new Long(configProperty.getConfigpropertyvalue()); method.invoke(resourceAdapter, configPropertyLong); } } else if (propertytype == Boolean.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue().equalsIgnoreCase("")) { Boolean configPropertyBoolean = new Boolean(configProperty.getConfigpropertyvalue()); method.invoke(resourceAdapter, configPropertyBoolean); } } } catch (Exception ex1) { ex1.printStackTrace(); } } public void undeploy(URL url) { try { //System.out.println(jarEJBMap.get(url.toString())); Vector<Object> objs = staticObjsEjbMap.remove(url.toString()); if (objs != null) { objs.clear(); } Vector<EJBContext> ejbContexts = jarEJBMap.get(url.toString()); if (ejbContexts != null && ejbContexts.size() > 0) { for (EJBContext ejbContext : ejbContexts) { if (ejbContext != null) { HashMap<String, Class> bindings = ejbContext.getRemoteBindings(); Set<String> remoteBindings = bindings.keySet(); Iterator<String> remoteBinding = remoteBindings.iterator(); while (remoteBinding.hasNext()) { String binding = (String) remoteBinding.next(); Object unbindstatefulObjs = ic.lookup("java:/" + binding); if (unbindstatefulObjs instanceof StatefulBeanObject) { Vector<Object> StatefulBeanObjects = StatefulBeanObject.statefulSessionBeanObjectMap .get(url.toString()); StatefulBeanObject.statefulSessionBeanObjectMap.remove(url.toString()); StatefulBeanObjects.clear(); } ic.unbind("java:/" + binding); System.out.println("unregistering the class" + bindings.get(binding)); } jarEJBMap.remove(url.toString()); } } } ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(url.toString()); MDBContext mdbContext; if (mdbContexts != null) { Iterator<String> mdbnames = mdbContexts.keySet().iterator(); while (mdbnames.hasNext()) { String mdbname = mdbnames.next(); mdbContext = mdbContexts.get(mdbname); if (mdbContext.getResourceAdapter() != null) { mdbContext.getResourceAdapter().endpointDeactivation(mdbContext.getMessageEndPointFactory(), mdbContext.getActivationSpec()); mdbContext.getResourceAdapter().stop(); } if (mdbContext.getConsumer() != null) { mdbContext.getConsumer().setMessageListener(null); mdbContext.getConsumer().close(); } if (mdbContext.getSession() != null) mdbContext.getSession().close(); if (mdbContext.getConnection() != null) mdbContext.getConnection().close(); mdbContexts.remove(mdbname); } jarMDBMap.remove(url.toString()); } log.info(url.toString() + " UnDeployed"); } catch (Exception ex) { log.error("Error in undeploying the package " + url, ex); //ex.printStackTrace(); } } public String getRarDeployerName() { return this.rarDeployerName.getCanonicalName(); } public void setRarDeployerName(String rarDeployerName) { try { this.rarDeployerName = new ObjectName(rarDeployerName); } catch (Exception e) { log.error("Error in creatnig object name " + rarDeployerName, e); // TODO Auto-generated catch block //e.printStackTrace(); } } @Override public CopyOnWriteArrayList<String> getJarsDeployed() { // TODO Auto-generated method stub return this.jarsDeployed; } }