List of usage examples for java.util.concurrent ConcurrentHashMap keys
public Enumeration<K> keys()
From source file:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java
/** * Rescue a given workflow einstance//from w w w . jav a 2 s. c o m */ public void doRescue(ActionRequest request, ActionResponse response) throws PortletException { if (UserQuotaUtils.getInstance().userQuotaIsFull(request.getRemoteUser())) { request.setAttribute("msg", "portal.RealWorkflowPortlet.quotaisoverfull"); } else { if (WorkflowInfo(request, response)) { doList(request, response); try { Vector errorJobPidList = new Vector(); String portalID = PropertyLoader.getInstance().getProperty("service.url"); String userID = request.getRemoteUser(); String workflowID = request.getParameter("workflow"); System.out.println( "doRescue portalID:" + portalID + " userID:" + userID + " workflowID:" + workflowID); WorkflowData wData = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID); String runtimeID = "" + wData.getEinstanceID(); System.out.println("doRescue portalID:" + portalID + " userID:" + userID + " workflowID:" + workflowID + " runtimeID:" + runtimeID); // // 23 = running/error int wfStatus = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID) .getRuntime(runtimeID).getStatus(); if (23 == wfStatus) { // running workflow statusz beirasa... PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID) .getRuntime(runtimeID).setStatus("5", 0); } else { // resuming workflow statusz beirasa... PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID) .getRuntime(runtimeID).setStatus("29", 0); } // ConcurrentHashMap tmp = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID) .getRuntime(runtimeID).getJobsStatus(); Enumeration enm0 = tmp.keys(); int ts; while (enm0.hasMoreElements()) { Object key0 = enm0.nextElement(); Enumeration enm1 = ((ConcurrentHashMap) tmp.get(key0)).keys(); while (enm1.hasMoreElements()) { Object key1 = enm1.nextElement(); ts = ((JobStatusData) ((ConcurrentHashMap) tmp.get(key0)).get(key1)).getStatus(); if (ts == 25 || ts == 21 || ts == 22 || ts == 7 || ts == 15 || ts == 13 || ts == 12) { // beirja az init statuszt... // PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID).getRuntime(runtimeID).addJobbStatus((String) key0, (String) key1, "1", "", 0); // kitorli a jobot a nyilvantartasbol... PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID) .getRuntime(runtimeID).removeJobStatus((String) key0, (String) key1); // storage takaritashoz ki kell gyujteni a jobID/jobPID-eket ComDataBean comDataBean = new ComDataBean(); comDataBean.setJobID((String) key0); comDataBean.setJobPID((String) key1); errorJobPidList.addElement(comDataBean); } } } new WorkflowRescueThread(portalID, userID, workflowID, runtimeID, "" + wfStatus, errorJobPidList); request.setAttribute("msg", "portal.EasyWorkflowPortlet.doRescue"); } catch (Exception e) { request.setAttribute("msg", "portal.EasyWorkflowPortlet.doRescue.error"); e.printStackTrace(); } } } }
From source file:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java
/** * Workflow submit/*w w w. jav a2 s.c o m*/ */ public void doSubmit(ActionRequest request, ActionResponse response) throws PortletException { if (UserQuotaUtils.getInstance().userQuotaIsFull(request.getRemoteUser())) { request.setAttribute("msg", "portal.RealWorkflowPortlet.quotaisoverfull"); } else { if (WorkflowInfo(request, response)) { doList(request, response); ConcurrentHashMap runTimesData = PortalCacheService.getInstance().getUser(request.getRemoteUser()) .getWorkflow(request.getParameter("workflow")).getAllRuntimeInstance(); Enumeration keys = runTimesData.keys(); int ts; while (keys.hasMoreElements()) {//abort all einstance String key = (String) keys.nextElement();//rtid if (((WorkflowRunTime) runTimesData.get(key)).getText().equals("einstance")) { // ((WorkflowRunTime) runTimesData.get(key)).; if ((((WorkflowRunTime) runTimesData.get(key)).getStatus() == 5) || (((WorkflowRunTime) runTimesData.get(key)).getStatus() == 2)) { ((WorkflowRunTime) runTimesData.get(key)).setStatus("22", 0); ConcurrentHashMap tmp = PortalCacheService.getInstance() .getUser(request.getRemoteUser()).getWorkflow(request.getParameter("workflow")) .getRuntime(key).getJobsStatus(); Enumeration enm0 = tmp.keys(); while (enm0.hasMoreElements()) { Object key0 = enm0.nextElement(); Enumeration enm1 = ((Hashtable) tmp.get(key0)).keys(); while (enm1.hasMoreElements()) { Object key1 = enm1.nextElement(); ts = ((JobStatusData) ((Hashtable) tmp.get(key0)).get(key1)).getStatus(); if (!(ts == 6) || (ts == 7) || (ts == 21) || (ts == 1)) { PortalCacheService.getInstance().getUser(request.getRemoteUser()) .getWorkflow(request.getParameter("workflow")).getRuntime(key) .addJobbStatus((String) key0, (String) key1, "22", "", 0); } } } System.out.println("abort EINSTANCE " + key); new WorkflowAbortThread(request.getRemoteUser(), request.getParameter("workflow"), key); } System.out.println("delete EINSTANCE " + key); RealWorkflowUtils.getInstance().deleteWorkflowInstance(request.getRemoteUser(), request.getParameter("workflow"), key); } } int max = Integer.parseInt(PropertyLoader.getInstance().getProperty("repeat.submit.workflow")); for (int i = 0; i < max; i++) { new WorkflowSubmitThread( PortalCacheService.getInstance().getUser(request.getRemoteUser()) .getWorkflow(request.getParameter("workflow")), request.getRemoteUser(), einstance, request.getParameter("wfchg_type")); } request.setAttribute("msg", "portal.EasyWorkflowPortlet.doSubmit"); } } }
From source file:com.web.server.WebServer.java
/** * This method obtains the content executor which executes the executor services * @param deployDirectory/* w ww . j av a2 s.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.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 w w . ja va 2 s.c o 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.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 ww .j a va 2 s . co m 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")); }