List of usage examples for java.util.concurrent ConcurrentHashMap get
public V get(Object key)
From source file:org.apache.stratos.rest.endpoint.api.StratosApiV41Utils.java
/** * This method is to validate the application definition to have unique aliases among its groups * * @param applicationDefinition - the application definition * @throws RestAPIException//from www. j a v a 2s.c om */ private static void validateGroupsInApplicationDefinition(ApplicationBean applicationDefinition) throws RestAPIException { ConcurrentHashMap<String, CartridgeGroupReferenceBean> groupsInApplicationDefinition = new ConcurrentHashMap<String, CartridgeGroupReferenceBean>(); boolean groupParentHasDeploymentPolicy = false; if ((applicationDefinition.getComponents().getGroups() != null) && (!applicationDefinition.getComponents().getGroups().isEmpty())) { //This is to validate the top level groups in the application definition for (CartridgeGroupReferenceBean group : applicationDefinition.getComponents().getGroups()) { if (groupsInApplicationDefinition.get(group.getAlias()) != null) { String message = "Cartridge group alias exists more than once: [group-alias] " + group.getAlias(); throw new RestAPIException(message); } // Validate top level group deployment policy with cartridges if (group.getCartridges() != null) { if (group.getDeploymentPolicy() != null) { groupParentHasDeploymentPolicy = true; } validateCartridgesForDeploymentPolicy(group.getCartridges(), groupParentHasDeploymentPolicy); } groupsInApplicationDefinition.put(group.getAlias(), group); if (group.getGroups() != null) { //This is to validate the groups aliases recursively validateGroupsRecursively(groupsInApplicationDefinition, group.getGroups(), groupParentHasDeploymentPolicy); } } } if ((applicationDefinition.getComponents().getCartridges() != null) && (!applicationDefinition.getComponents().getCartridges().isEmpty())) { validateCartridgesForDeploymentPolicy(applicationDefinition.getComponents().getCartridges(), false); } }
From source file:com.web.server.WebServer.java
/** * This method obtains the content executor which executes the executor services * @param deployDirectory/*from w ww .j ava 2s. c om*/ * @param resource * @param httpHeaderClient * @param serverdigester * @return byte[] */ public byte[] ObtainContentExecutor(String deployDirectory, String resource, HttpHeaderClient httpHeaderClient, Digester serverdigester, Hashtable urlClassLoaderMap, ConcurrentHashMap servletMapping, com.web.server.HttpSessionServer session) { //System.out.println("In content Executor"); String[] resourcepath = resource.split("/"); //System.out.println("createDigester1"); Method method = null; //System.out.println("createDigester2"); ////System.out.println(); com.web.server.Executors serverconfig; if (resourcepath.length > 1) { ////System.out.println(resource); try { ClassLoader oldCL = null; String urlresource = ObtainUrlFromResource(resourcepath); try { //System.out.println(servletMapping); //System.out.println(deployDirectory+"/"+resourcepath[1]); HttpSessionServer httpSession; logger.info(deployDirectory + "/" + resourcepath[1] + " " + servletMapping.get(deployDirectory + "/" + resourcepath[1])); if (servletMapping.get(deployDirectory + "/" + resourcepath[1]) != null) { WebAppConfig webAppConfig = (WebAppConfig) servletMapping .get(deployDirectory + "/" + resourcepath[1]); webAppConfig = webAppConfig.clone(); webAppConfig.setWebApplicationAbsolutePath(deployDirectory + "/" + resourcepath[1]); WebClassLoader customClassLoader = null; Class customClass = null; customClassLoader = (WebClassLoader) urlClassLoaderMap .get(deployDirectory + "/" + resourcepath[1]); oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(customClassLoader); ConcurrentHashMap servletMappingsURL = webAppConfig.getServletMappingURL(); Enumeration urlPattern = servletMappingsURL.keys(); while (urlPattern.hasMoreElements()) { String pattern = (String) urlPattern.nextElement(); Pattern r = Pattern.compile(pattern.replace("*", "(.*)")); Matcher m = r.matcher(urlresource); if (m.find()) { urlresource = pattern; break; } } LinkedHashMap<String, Vector<FilterMapping>> filterMappings = webAppConfig .getFilterMappingURL(); Set<String> filterMappingKeys = filterMappings.keySet(); Iterator<String> filterMappingRoller = filterMappingKeys.iterator(); Vector<FilterMapping> filterMapping = null; while (filterMappingRoller.hasNext()) { String pattern = (String) filterMappingRoller.next(); Pattern r = Pattern.compile(pattern.replace("*", "(.*)")); Matcher m = r.matcher(urlresource); if (m.find()) { filterMapping = filterMappings.get(pattern); break; } } if (servletMappingsURL.get(urlresource) != null) { ServletMapping servletMappings = (ServletMapping) servletMappingsURL.get(urlresource); ConcurrentHashMap servlets = webAppConfig.getServlets(); Servlets servlet = (Servlets) servlets.get(servletMappings.getServletName()); HttpServlet httpServlet = null; System.out.println("Session " + session); if (session.getAttribute("SERVLETNAME:" + deployDirectory + "/" + resourcepath[1] + servletMappings.getServletName()) != null) { httpServlet = (HttpServlet) session.getAttribute("SERVLETNAME:" + deployDirectory + "/" + resourcepath[1] + servletMappings.getServletName()); httpServlet.init(); } else { Class servletClass = customClassLoader.loadClass(servlet.getServletClass()); httpServlet = (HttpServlet) servletClass.newInstance(); httpServlet.init(new WebServletConfig(servlet.getServletName().trim(), webAppConfig, customClassLoader)); httpServlet.init(); session.setAttribute("SERVLETNAME:" + deployDirectory + "/" + resourcepath[1] + servletMappings.getServletName(), httpServlet); //ClassLoaderUtil.closeClassLoader(customClassLoader); } if (httpHeaderClient.getHttpMethod().trim().toUpperCase().equals("GET") || httpHeaderClient.getHttpMethod().trim().toUpperCase().equals("POST")) { Response response = new Response(httpHeaderClient); StringBuffer servletPath = new StringBuffer(); if (resourcepath.length > 1) { int pathcount = 0; for (String servPath : resourcepath) { if (pathcount > 1) { servletPath.append("/"); servletPath.append(servPath); } pathcount++; } } String servletpath = servletPath.toString(); if (servletpath.length() == 0) servletpath = "/"; Request request = new Request(httpHeaderClient, session, servletpath, customClassLoader); if (filterMapping != null) { WebFilterChain webFilterChain = new WebFilterChain(httpServlet, webAppConfig, filterMapping, customClassLoader); webFilterChain.doFilter(request, response); } else { httpServlet.service(request, response); } //System.out.println("RESPONSE="+new String(response.getResponse())); //httpServlet.destroy(); response.flushBuffer(); return response.getResponse(); } //httpServlet.destroy(); } else { if (customClassLoader != null) { Map map = customClassLoader.classMap; if (map.get(urlresource) != null) { Class jspBaseCls = customClassLoader.loadClass((String) map.get(urlresource)); HttpJspBase jspBase = (HttpJspBase) jspBaseCls.newInstance(); WebServletConfig servletConfig = new WebServletConfig(); servletConfig.getServletContext().setAttribute( "org.apache.tomcat.InstanceManager", new WebInstanceManager(urlresource)); //servletConfig.getServletContext().setAttribute(org.apache.tomcat.InstanceManager, arg1); jspBase.init(servletConfig); jspBase._jspInit(); Response response = new Response(httpHeaderClient); StringBuffer servletPath = new StringBuffer(); if (resourcepath.length > 1) { int pathcount = 0; for (String servPath : resourcepath) { if (pathcount > 1) { servletPath.append("/"); servletPath.append(servPath); } pathcount++; } } String servletpath = servletPath.toString(); if (servletpath.length() == 0) servletpath = "/"; jspBase._jspService( new Request(httpHeaderClient, session, servletpath, customClassLoader), response); jspBase.destroy(); response.flushBuffer(); return response.getResponse(); } } } } } catch (Exception ex) { ex.printStackTrace(); } finally { if (oldCL != null) { Thread.currentThread().setContextClassLoader(oldCL); } } File file = new File(deployDirectory + "/" + resourcepath[1] + "/WEB-INF/executor-config.xml"); if (!file.exists()) { return null; } WebClassLoader customClassLoader = (WebClassLoader) urlClassLoaderMap .get(deployDirectory + "/" + resourcepath[1]); Class customClass = null; if ((file.isFile() && file.exists())) { synchronized (serverdigester) { serverconfig = (com.web.server.Executors) serverdigester.parse(file); } ConcurrentHashMap urlMap = serverconfig.getExecutorMap(); //System.out.println("ObtainUrlFromResource1"); //logger.info("urlresource"+urlresource); Executor executor = (Executor) urlMap.get(urlresource); //System.out.println("ObtainUrlFromResource2"+executor); //System.out.println("custom class Loader1"+urlClassLoaderMap); //System.out.println("custom class Loader2"+customClassLoader); //System.out.println("CUSTOM CLASS lOADER path"+deployDirectory+"/"+resourcepath[1]); ////System.out.println("custom class loader" +customClassLoader); if (executor != null && customClassLoader != null) { customClass = customClassLoader.loadClass(executor.getExecutorclass()); ExecutorInterface executorInstance = (ExecutorInterface) customClass.newInstance(); Object buffer = null; if (httpHeaderClient.getHttpMethod().trim().toUpperCase().equals("GET")) { buffer = executorInstance.doGet(httpHeaderClient); } else if (httpHeaderClient.getHttpMethod().trim().toUpperCase().equals("POST")) { buffer = executorInstance.doPost(httpHeaderClient); } if (executor.getResponseResource() != null) { httpHeaderClient.setExecutorBuffer(buffer); //System.out.println("Method:"+httpHeaderClient.getHttpMethod()); String resourceClass = (String) customClassLoader.getClassMap() .get(executor.getResponseResource().trim()); customClass = customClassLoader.loadClass(resourceClass); HttpJspBase jspBase = (HttpJspBase) customClass.newInstance(); WebServletConfig servletConfig = new WebServletConfig(); servletConfig.getServletContext().setAttribute("org.apache.tomcat.InstanceManager", new WebInstanceManager(urlresource)); //servletConfig.getServletContext().setAttribute(org.apache.tomcat.InstanceManager, arg1); jspBase.init(servletConfig); jspBase._jspInit(); Response response = new Response(httpHeaderClient); jspBase._jspService(new Request(httpHeaderClient, session, null, customClassLoader), response); jspBase.destroy(); response.flushBuffer(); return response.getResponse(); } return buffer.toString().getBytes(); } } else if (customClassLoader != null) { //System.out.println("url resource"+urlresource); String resourceClass = (String) customClassLoader.getClassMap().get(urlresource); //System.out.println(resourceClass); //System.out.println(customClassLoader.getClassMap()); if (resourceClass == null) return null; customClass = customClassLoader.loadClass(resourceClass); ExecutorInterface executorInstance = (ExecutorInterface) customClass.newInstance(); Object buffer = executorInstance.doGet(httpHeaderClient); return buffer.toString().getBytes(); } ////System.out.println("executor resource 1"); //Object buffer = method.invoke(customClass.newInstance(), new Object[]{httpHeaderClient}); // //logger.info(buffer.toString()); } catch (IOException | SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } /*catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } */catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
From source file:com.web.server.EARDeployer.java
/** * This method configures the executor services from the jar file. * /*from www. j av a2 s .c o m*/ * @param jarFile * @param classList * @throws FileSystemException */ public void deployExecutorServicesEar(String earFileName, FileObject earFile, StandardFileSystemManager fsManager) throws FileSystemException { try { System.out.println("EARFILE NAMEs=" + earFileName); CopyOnWriteArrayList<FileObject> fileObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>(); ConcurrentHashMap jarClassListMap = new ConcurrentHashMap(); CopyOnWriteArrayList<String> classList; obtainUrls(earFile, earFile, fileObjects, jarClassListMap, warObjects, fsManager); VFSClassLoader customClassLoaderBaseLib = new VFSClassLoader( fileObjects.toArray(new FileObject[fileObjects.size()]), fsManager, Thread.currentThread().getContextClassLoader()); VFSClassLoader customClassLoader = null; Set keys = jarClassListMap.keySet(); Iterator key = keys.iterator(); FileObject jarFileObject; ConcurrentHashMap classLoaderPath = new ConcurrentHashMap(); filesMap.put(earFileName, classLoaderPath); for (FileObject warFileObj : warObjects) { if (warFileObj.getName().getBaseName().endsWith(".war")) { //logger.info("filePath"+filePath); String filePath = scanDirectory + "/" + warFileObj.getName().getBaseName(); log.info(filePath); String fileName = warFileObj.getName().getBaseName(); WebClassLoader classLoader = new WebClassLoader(new URL[] {}); log.info(classLoader); warDeployer.deleteDir( new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")))); new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs(); log.info(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); urlClassLoaderMap.put( deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")), classLoader); classLoaderPath.put(warFileObj.getName().getBaseName(), deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); warDeployer.extractWar(new File(filePath), classLoader); if (exec != null) { exec.shutdown(); } new File(scanDirectory + "/" + warFileObj.getName().getBaseName()).delete(); exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS); } } for (int keyCount = 0; keyCount < keys.size(); keyCount++) { jarFileObject = (FileObject) key.next(); { classList = (CopyOnWriteArrayList<String>) jarClassListMap.get(jarFileObject); customClassLoader = new VFSClassLoader(jarFileObject, fsManager, customClassLoaderBaseLib); this.urlClassLoaderMap.put( scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName(), customClassLoader); classLoaderPath.put(jarFileObject.getName().getBaseName(), scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName()); for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount).substring(0, classList.get(classCount).indexOf(".class")); classwithpackage = classwithpackage.replace("/", "."); // System.out.println("classList:"+classwithpackage.replace("/",".")); try { if (!classwithpackage.contains("$")) { /*System.out.println("EARFILE NAME="+fileName); System.out .println(scanDirectory + "/" + fileName + "/" + jarFileObject.getName() .getBaseName()); System.out.println(urlClassLoaderMap);*/ Class executorServiceClass = customClassLoader.loadClass(classwithpackage); Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof RemoteCall) { RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount]; //registry.unbind(remoteCall.servicename()); System.out.println(remoteCall.servicename().trim()); try { for (int count = 0; count < 2; count++) { RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject .exportObject( (Remote) executorServiceClass.newInstance(), 0); registry.rebind(remoteCall.servicename().trim(), reminterface); } } catch (Exception ex) { ex.printStackTrace(); } } } } // System.out.println(executorServiceClass.newInstance()); // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); // System.out.println(); Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo.setExecutorServicesClass(executorServiceClass); executorServiceInfo.setMethod(method); executorServiceInfo.setMethodParams(method.getParameterTypes()); // System.out.println("serice name=" // + executorServiceAnnot // .servicename()); // System.out.println("method info=" // + executorServiceInfo); // System.out.println(method); // if(servicesMap.get(executorServiceAnnot.servicename())==null)throw // new Exception(); executorServiceMap.put(executorServiceAnnot.servicename(), executorServiceInfo); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } jarFileObject.close(); } for (FileObject fobject : fileObjects) { fobject.close(); } System.out.println("Channel unlocked"); earFile.close(); fsManager.closeFileSystem(earFile.getFileSystem()); // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.pari.nm.modules.jobs.PcbImportJob.java
private void populateVoIPPhones(String voipPhoneList) { try {// ww w . j av a 2s . c om InputStream fin = new ByteArrayInputStream(voipPhoneList.getBytes()); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.parse(fin); Element docRoot = doc.getDocumentElement(); if (!docRoot.getTagName().equals("VoipPhoneList")) { throw new Exception("Invalid format. Expecting: VoipPhoneList, found " + docRoot.getTagName()); } HashMap<Integer, ArrayList<VoipPhone>> phonesMap = new HashMap<Integer, ArrayList<VoipPhone>>(); ConcurrentHashMap<String, Integer> custIpMap = CustomerManager.getInstance() .getCustomerIpMap(customerId); List<Element> phoneElementList = XMLUtil.getFirstLevelChildElementsByTagName(docRoot, "VoipPhone"); if ((phoneElementList != null) && (phoneElementList.size() > 0) && (custIpMap != null) && (custIpMap.size() > 0)) { for (Element voipPhoneElem : phoneElementList) { VoipPhone phone = new VoipPhone(); String ipAddress = XMLUtil.getChildText(voipPhoneElem, "IpAddress"); if (ipAddress != null) { phone.setIpAddress(ipAddress.trim()); } String phoneModel = XMLUtil.getChildText(voipPhoneElem, "PhoneModel"); if (phoneModel != null) { phone.setModel(phoneModel.trim()); } String vendorName = XMLUtil.getChildText(voipPhoneElem, "VendorName"); if (vendorName != null) { phone.setVendorName(vendorName.trim()); } String macAddress = XMLUtil.getChildText(voipPhoneElem, "MACAddress"); if (macAddress != null) { phone.setMacAddress(macAddress.trim()); } String switchInterface = XMLUtil.getChildText(voipPhoneElem, "SwitchInterface"); if (switchInterface != null) { phone.setSwitchInterface(switchInterface.trim()); } String serialNumber = XMLUtil.getChildText(voipPhoneElem, "SerialNumber"); if (serialNumber != null) { phone.setSerialNumber(serialNumber.trim()); } String userName = XMLUtil.getChildText(voipPhoneElem, "UserName"); if (userName != null) { phone.setUserName(userName.trim()); } String extension = XMLUtil.getChildText(voipPhoneElem, "UserName"); if (extension != null) { phone.setPhoneNumber(extension.trim()); } String switchIpAddress = XMLUtil.getChildText(voipPhoneElem, "SwitchIpAddress"); Integer deviceId = custIpMap.get(switchIpAddress); if ((deviceId != null) && (deviceId.intValue() != -1)) { phone.setSwitchNodeId(deviceId); ArrayList<VoipPhone> phonesList = phonesMap.get(deviceId); if (phonesList == null) { phonesList = new ArrayList<VoipPhone>(); phonesMap.put(deviceId, phonesList); } phonesList.add(phone); } } } if (phonesMap.size() > 0) { try { VOIPDBHelper.saveVOIPPhones(customerId, instanceId, phonesMap); } catch (Exception ex) { logger.warn("Error while saving VOIP Phones for the customer: " + customerId + " instance=" + instanceId, ex); } } } catch (Exception ex) { logger.warn( "Error while saving VOIP Phones for the customer: " + customerId + " instance=" + instanceId, ex); } }
From source file:diffhunter.Indexer.java
public void Make_Index(Database hashdb, String file_name, String read_gene_location) throws FileNotFoundException, IOException { Set_Parameters();/*from w w w . ja v a 2 s . co m*/ //System.out.print("Sasa"); ConcurrentHashMap<String, Map<Integer, Integer>> dic_gene_loc_count = new ConcurrentHashMap<>(); ArrayList<String> lines_from_bed_file = new ArrayList<>(); BufferedReader br = new BufferedReader(new FileReader(file_name)); String line = br.readLine(); List<String> toks = Arrays.asList(line.split("\t")); lines_from_bed_file.add(line); String last_Seen_chromosome = toks.get(0).replace("chr", ""); line = br.readLine(); lines_from_bed_file.add(line); toks = Arrays.asList(line.split("\t")); String new_chromosome = toks.get(0).replace("chr", ""); while (((line = br.readLine()) != null) || lines_from_bed_file.size() > 0) { if (line != null) { toks = Arrays.asList(line.split("\t")); new_chromosome = toks.get(0).replace("chr", ""); } // process the line. if (line == null || !new_chromosome.equals(last_Seen_chromosome)) { System.out.println("Processing chromosome" + "\t" + last_Seen_chromosome); last_Seen_chromosome = new_chromosome; lines_from_bed_file.parallelStream().forEach(content -> { List<String> inner_toks = Arrays.asList(content.split("\t")); //WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING //STRAND column count should be changed. String strand = inner_toks.get(5); String chromosome_ = inner_toks.get(0).replace("chr", ""); if (!dic_Loc_gene.get(strand).containsKey(chromosome_)) { return; } Integer start_loc = Integer.parseInt(inner_toks.get(1)); Integer end_loc = Integer.parseInt(inner_toks.get(2)); List<Interval<String>> res__ = dic_Loc_gene.get(strand).get(chromosome_).getIntervals(start_loc, end_loc); //IntervalTree<String> pot_gene_name=new IntervalTree<>(res__); // for (int z = 0; z < pot_gene_name.Intervals.Count; z++) //{ for (int z = 0; z < res__.size(); z++) { dic_gene_loc_count.putIfAbsent(res__.get(z).getData(), new HashMap<>()); String gene_symbol = res__.get(z).getData(); Integer temp_gene_start_loc = dic_genes.get(gene_symbol).start_loc; Integer temp_gene_end_loc = dic_genes.get(gene_symbol).end_loc; if (start_loc < temp_gene_start_loc) { start_loc = temp_gene_start_loc; } if (end_loc > temp_gene_end_loc) { end_loc = temp_gene_end_loc; } synchronized (dic_synchrinzer_genes.get(gene_symbol)) { for (int k = start_loc; k <= end_loc; k++) { Integer value_inside = 0; value_inside = dic_gene_loc_count.get(gene_symbol).get(k); dic_gene_loc_count.get(gene_symbol).put(k, value_inside == null ? 1 : (value_inside + 1)); } } } }); /* List<string> keys_ = dic_gene_loc_count.Keys.ToList(); List<string> alt_keys = new List<string>();// dic_gene_loc_count.Keys.ToList(); for (int i = 0; i < keys_.Count; i++) { Dictionary<int, int> dicccc_ = new Dictionary<int, int>(); dic_gene_loc_count[keys_[i]] = new Dictionary<int, int>(dic_gene_loc_count[keys_[i]].Where(x => x.Value >= 2).ToDictionary(x => x.Key, x => x.Value)); if (dic_gene_loc_count[keys_[i]].Count == 0) { dic_gene_loc_count.TryRemove(keys_[i], out dicccc_); continue; } hashdb.Put(Get_BDB(keys_[i]), Get_BDB_Dictionary(dic_gene_loc_count[keys_[i]])); alt_keys.Add(keys_[i]); dic_gene_loc_count.TryRemove(keys_[i], out dicccc_); }*/ ArrayList<String> keys_ = new ArrayList<>(dic_gene_loc_count.keySet()); ArrayList<String> alt_keys = new ArrayList<>(); for (int i = 0; i < keys_.size(); i++) { //LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(dic_gene_loc_count.get(keys_.get(i))); LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(); /*tmep_map = */ dic_gene_loc_count.get(keys_.get(i)).entrySet().stream().filter(p -> p.getValue() >= 2) .sorted(Comparator.comparing(E -> E.getKey())) .forEach((entry) -> tmep_map.put(entry.getKey(), entry.getValue()));//.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())); if (tmep_map.isEmpty()) { dic_gene_loc_count.remove(keys_.get(i)); continue; } //Map<Integer, Integer> tmep_map1 = new LinkedHashMap<>(); //tmep_map1=sortByKey(tmep_map); //tmep_map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())).forEach((entry) -> tmep_map1.put(entry.getKey(), entry.getValue())); //BerkeleyDB_Box box=new BerkeleyDB_Box(); hashdb.put(null, BerkeleyDB_Box.Get_BDB(keys_.get(i)), BerkeleyDB_Box.Get_BDB_Dictionary(tmep_map)); alt_keys.add(keys_.get(i)); dic_gene_loc_count.remove(keys_.get(i)); //dic_gene_loc_count.put(keys_.get(i),tmep_map); } hashdb.sync(); int a = 1111; /* hashdb.Sync(); File.AppendAllLines("InputDB\\" + Path.GetFileNameWithoutExtension(file_name) + "_genes.txt", alt_keys); //total_lines_processed_till_now += lines_from_bed_file.Count; //worker.ReportProgress(total_lines_processed_till_now / count_); lines_from_bed_file.Clear(); if (!reader.EndOfStream) { lines_from_bed_file.Add(_line_); } last_Seen_chromosome = new_choromosome;*/ lines_from_bed_file.clear(); if (line != null) { lines_from_bed_file.add(line); } Path p = Paths.get(file_name); file_name = p.getFileName().toString(); BufferedWriter output = new BufferedWriter(new FileWriter((Paths .get(read_gene_location, FilenameUtils.removeExtension(file_name) + ".txt").toString()), true)); for (String alt_key : alt_keys) { output.append(alt_key); output.newLine(); } output.close(); /*if (((line = br.readLine()) != null)) { lines_from_bed_file.add(line); toks=Arrays.asList(line.split("\t")); new_chromosome=toks.get(0).replace("chr", ""); }*/ //last_Seen_chromosome=new_chromosome; } else if (new_chromosome.equals(last_Seen_chromosome)) { lines_from_bed_file.add(line); } } br.close(); hashdb.sync(); hashdb.close(); }
From source file:com.web.server.WebServer.java
/** * This method forms the http response//from ww w .ja v a 2 s .c o m * @param responseCode * @param httpHeader * @param content * @return */ private byte[] formHttpResponseHeader(int responseCode, HttpHeaderServer httpHeader, byte[] content, ConcurrentHashMap<String, HttpCookie> httpCookies) { StringBuffer buffer = new StringBuffer(); String colon = ": "; String crlf = "\r\n"; if (responseCode == 200) { buffer.append("HTTP/1.1 200 OK"); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.DATE); buffer.append(colon); buffer.append(httpHeader.getDate()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.SERVER); buffer.append(colon); buffer.append(httpHeader.getServer()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.CONTENT_TYPE); buffer.append(colon); buffer.append(httpHeader.getContentType()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.CONTENT_LENGTH); buffer.append(colon); buffer.append(httpHeader.getContentLength()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.LAST_MODIFIED); buffer.append(colon); buffer.append(httpHeader.getLastModified()); if (httpCookies != null) { Iterator<String> cookieNames = httpCookies.keySet().iterator(); HttpCookie httpCookie; for (; cookieNames.hasNext();) { String cookieName = cookieNames.next(); httpCookie = (HttpCookie) httpCookies.get(cookieName); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.SETCOOKIE); buffer.append(colon); buffer.append(httpCookie.getKey()); buffer.append("="); buffer.append(httpCookie.getValue()); if (httpCookie.getExpires() != null) { buffer.append("; "); buffer.append(HttpHeaderServerParamNames.SETCOOKIEEXPIRES); buffer.append("="); buffer.append(httpCookie.getExpires()); } } } } else if (responseCode == 404) { buffer.append("HTTP/1.1 404 Not Found"); } buffer.append(crlf); buffer.append(crlf); byte[] byt1 = buffer.toString().getBytes(); byte[] byt2 = new byte[byt1.length + content.length + crlf.length() * 2]; /////System.out.println("Header="+new String(byt1)); for (int count = 0; count < byt1.length; count++) { byt2[count] = byt1[count]; } for (int count = 0; count < content.length; count++) { byt2[count + byt1.length] = content[count]; } for (int count = 0; count < crlf.length() * 2; count++) { byt2[count + byt1.length + content.length] = (byte) crlf.charAt(count % 2); } ////System.out.println("Header with content="+new String(byt2)); /*try { buffer.append(new String(content, "UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return byt2; }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, boolean listall) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }/*w w w .j a v a 2 s.c om*/ boolean done = false; int i = 0; while (i < rec.size() && !done) { res.append("<" + tablename + ">"); en = columns.keys(); while (en.hasMoreElements()) { String cname = ((String) en.nextElement()).toLowerCase(); String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o instanceof com.mysql.jdbc.Blob) { //byte[] b = BufferedInputStreamToString(((com.mysql.jdbc.Blob)o).getBinaryStream()).getBytes(); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + cname + ">"); } else { res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + o + "]]></" + cname + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1) { res.append("<" + cname + " type=\"String\"><![CDATA[" + stripNonValidChars(rec.getString(cname)) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DATE") || type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || (type != null && type.toUpperCase().equals("YEAR"))) { res.append("<" + cname + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + cname + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + cname + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + cname + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + cname + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(cname)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(cname)+">"); throw new Exception(cname + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">\n"); if (!listall) { done = true; } else { i++; rec.next(); } } } return new String(res.substring(0).getBytes("UTF8")); }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, FlexElement idelement) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }/*w ww. ja v a2 s . co m*/ res.append("<" + tablename + ">"); en = columns.keys(); String cname = ""; FlexElement aliascolumn = null; while (en.hasMoreElements()) { aliascolumn = null; cname = ""; cname = (String) en.nextElement(); String objectField = ""; aliascolumn = (FlexElement) idelement.getElementByName(cname.trim(), false); if (aliascolumn == null) { objectField = cname; } else { if (aliascolumn.getAttribute("alias") == null) { objectField = cname; } else { objectField = aliascolumn.getAttribute("alias").getValue(); } } String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o != null) { //System.out.print(cname+")type:"+type+" "+o.getClass()); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + objectField + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + objectField + ">"); } else { res.append("<" + objectField + " type=\"byte[]\"><![CDATA[]]></" + objectField + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1 || type.toUpperCase().equals("YEAR")) { res.append("<" + objectField + " type=\"String\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || type.toUpperCase().equals("DATE") || type.toUpperCase().equals("TIME")) { res.append("<" + objectField + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + objectField + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + objectField + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + objectField + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + objectField + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(objectField)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(objectField)+">"); throw new Exception(objectField + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">"); } //System.out.println(">>>1:"+res.toString()); return new String(res.substring(0).getBytes("UTF8")); }
From source file:com.web.server.EJBDeployer.java
@Override public void fileChanged(FileChangeEvent arg0) throws Exception { try {//from w w w . j a v 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 {/*from ww w .j a v a2s .c om*/ 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(); } }