List of usage examples for javax.jms Session createConsumer
MessageConsumer createConsumer(Destination destination) throws JMSException;
From source file:org.apache.qpid.systest.management.jmx.ConnectionManagementTest.java
public void testProducerFlowBlocked() throws Exception { _connection = getConnection();/*from ww w . j a va 2s.co m*/ _connection.start(); String queueName = getTestQueueName(); Session session = _connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(queueName); createQueueOnBroker(session, queue); ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName); managedQueue.setFlowResumeCapacity(DEFAULT_MESSAGE_SIZE * 2l); managedQueue.setCapacity(DEFAULT_MESSAGE_SIZE * 3l); final ManagedConnection managedConnection = getConnectionMBean(); // Check that producer flow is not block before test final CompositeDataSupport rowBeforeSend = getTheOneChannelRow(managedConnection); assertFlowBlocked(rowBeforeSend, false); // Check that producer flow does not become block too soon sendMessage(session, queue, 3); final CompositeDataSupport rowBeforeFull = getTheOneChannelRow(managedConnection); assertFlowBlocked(rowBeforeFull, false); // Fourth message will over-fill the queue (but as we are not sending more messages, client thread wont't block) sendMessage(session, queue, 1); final CompositeDataSupport rowAfterFull = getTheOneChannelRow(managedConnection); assertFlowBlocked(rowAfterFull, true); // Consume two to bring the queue down to the resume capacity MessageConsumer consumer = session.createConsumer(queue); assertNotNull("Could not receive first message", consumer.receive(1000)); assertNotNull("Could not receive second message", consumer.receive(1000)); session.commit(); // Check that producer flow is no longer blocked final CompositeDataSupport rowAfterReceive = getTheOneChannelRow(managedConnection); assertFlowBlocked(rowAfterReceive, false); }
From source file:com.web.server.EJBDeployer.java
@Override public void fileChanged(FileChangeEvent arg0) throws Exception { try {//from www.j av a 2 s .com FileObject baseFile = arg0.getFile(); EJBContext ejbContext; if (baseFile.getName().getURI().endsWith(".jar")) { fileDeleted(arg0); URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config); container.inject(); Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (cls.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(baseFile.getName().getURI()); ejbContext.setJarDeployed(baseFile.getName().getBaseName()); for (Class<?> ejbInterface : cls) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put(baseFile.getName().getURI(), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(baseFile.getName().getURI()) != null) { mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(baseFile.getName().getURI(), 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("/", ".")); 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) { 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) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); System.out.println(baseFile.getName().getURI() + " Deployed"); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.web.server.EJBDeployer.java
@Override public void fileCreated(FileChangeEvent arg0) throws Exception { try {/*w w w . j a va 2 s .c o m*/ FileObject baseFile = arg0.getFile(); EJBContext ejbContext; if (baseFile.getName().getURI().endsWith(".jar")) { System.out.println(baseFile.getName().getURI()); URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config); container.inject(); Set<Class<?>> clsStateless = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (clsStateless.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(baseFile.getName().getURI()); ejbContext.setJarDeployed(baseFile.getName().getBaseName()); for (Class<?> ejbInterface : clsStateless) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put(baseFile.getName().getURI(), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(baseFile.getName().getURI()) != null) { mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(baseFile.getName().getURI(), 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("/", ".")); 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) { 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) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); } System.out.println(baseFile.getName().getURI() + " Deployed"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
/** * Creates the MessageConsumer before sending the request Message since we do not need any correlation. *///from www.ja va2 s . c o m private javax.jms.Message doSendAndReceiveWithTemporaryReplyToDestination(Destination requestDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { MessageProducer messageProducer = null; MessageConsumer messageConsumer = null; try { messageProducer = session.createProducer(requestDestination); messageConsumer = session.createConsumer(replyTo); this.sendRequestMessage(jmsRequest, messageProducer, priority); return this.receiveReplyMessage(messageConsumer); } finally { JmsUtils.closeMessageProducer(messageProducer); JmsUtils.closeMessageConsumer(messageConsumer); } }
From source file:com.web.server.EJBDeployer.java
@Override public void run() { EJBJarFileListener jarFileListener = new EJBJarFileListener(registry, this.servicesRegistryPort, jarEJBMap, jarMDBMap, jms, connectionFactory); DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener); FileObject listendir = null;//from w ww . ja v a2s. co m StandardFileSystemManager fsManager = new StandardFileSystemManager(); String[] dirsToScan = scanDirectory.split(";"); EJBContext ejbContext; try { File scanDirFile = new File(dirsToScan[0]); File[] scanJarFiles = scanDirFile.listFiles(); System.out.println("SCANDIRECTORY=" + scanDirectory); if (scanJarFiles != null) { for (File scanJarFile : scanJarFiles) { if (scanJarFile.isFile() && scanJarFile.getAbsolutePath().endsWith(".jar")) { URLClassLoader classLoader = new URLClassLoader( new URL[] { new URL("file:///" + scanJarFile.getAbsolutePath()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer .getInstance("file:///" + scanJarFile.getAbsolutePath(), config); container.inject(); Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (cls.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(scanJarFile.getAbsolutePath()); ejbContext.setJarDeployed(scanJarFile.getName()); for (Class<?> ejbInterface : cls) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(scanJarFile.getAbsolutePath()) != null) { mdbContexts = jarMDBMap.get(scanJarFile.getAbsolutePath()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"), 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("/", ".")); 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) { 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) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); System.out.println(scanJarFile.getAbsolutePath() + " Deployed"); } } } FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); fsManager.init(); for (String dir : dirsToScan) { if (dir.startsWith("ftp://")) { listendir = fsManager.resolveFile(dir, opts); } else { listendir = fsManager.resolveFile(dir); } fm.addFile(listendir); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } fm.setRecursive(true); fm.setDelay(1000); fm.start(); }
From source file:com.app.server.EJBDeployer.java
public void deployEjbJar(URL url, StandardFileSystemManager manager, ClassLoader cL) { try {/*from w w w. j a v a 2 s.co m*/ 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); }*/ } }