List of usage examples for java.util Stack push
public E push(E item)
From source file:com.datatorrent.stram.plan.physical.PhysicalPlan.java
/** * * @param dag//from w w w .ja v a 2 s. co m * @param ctx */ public PhysicalPlan(LogicalPlan dag, PlanContext ctx) { this.dag = dag; this.ctx = ctx; this.maxContainers = Math.max(dag.getMaxContainerCount(), 1); LOG.debug("Max containers: {}", this.maxContainers); Stack<OperatorMeta> pendingNodes = new Stack<OperatorMeta>(); // Add logging operators for streams if not added already updatePersistOperatorStreamCodec(dag); for (OperatorMeta n : dag.getAllOperators()) { pendingNodes.push(n); } while (!pendingNodes.isEmpty()) { OperatorMeta n = pendingNodes.pop(); if (this.logicalToPTOperator.containsKey(n)) { // already processed as upstream dependency continue; } boolean upstreamDeployed = true; for (Map.Entry<InputPortMeta, StreamMeta> entry : n.getInputStreams().entrySet()) { StreamMeta s = entry.getValue(); boolean delay = entry.getKey().getValue(LogicalPlan.IS_CONNECTED_TO_DELAY_OPERATOR); // skip delay sources since it's going to be handled as downstream if (!delay && s.getSource() != null && !this.logicalToPTOperator.containsKey(s.getSource().getOperatorMeta())) { pendingNodes.push(n); pendingNodes.push(s.getSource().getOperatorMeta()); upstreamDeployed = false; break; } } if (upstreamDeployed) { addLogicalOperator(n); } } updatePartitionsInfoForPersistOperator(dag); // assign operators to containers int groupCount = 0; Set<PTOperator> deployOperators = Sets.newHashSet(); for (Map.Entry<OperatorMeta, PMapping> e : logicalToPTOperator.entrySet()) { for (PTOperator oper : e.getValue().getAllOperators()) { if (oper.container == null) { PTContainer container = getContainer((groupCount++) % maxContainers); if (!container.operators.isEmpty()) { LOG.warn( "Operator {} shares container without locality contraint due to insufficient resources.", oper); } Set<PTOperator> inlineSet = oper.getGrouping(Locality.CONTAINER_LOCAL).getOperatorSet(); if (!inlineSet.isEmpty()) { // process inline operators for (PTOperator inlineOper : inlineSet) { setContainer(inlineOper, container); } } else { setContainer(oper, container); } deployOperators.addAll(container.operators); } } } for (PTContainer container : containers) { updateContainerMemoryWithBufferServer(container); container.setRequiredVCores(getVCores(container.getOperators())); } for (Map.Entry<PTOperator, Operator> operEntry : this.newOpers.entrySet()) { initCheckpoint(operEntry.getKey(), operEntry.getValue(), Checkpoint.INITIAL_CHECKPOINT); } // request initial deployment ctx.deploy(Collections.<PTContainer>emptySet(), Collections.<PTOperator>emptySet(), Sets.newHashSet(containers), deployOperators); this.newOpers.clear(); this.deployOpers.clear(); this.undeployOpers.clear(); }
From source file:kilim.analysis.BasicBlock.java
public ArrayList<BasicBlock> getSubBlocks() throws KilimException { if (subBlocks == null) { if (!hasFlag(IS_SUBROUTINE)) return null; subBlocks = new ArrayList<BasicBlock>(10); Stack<BasicBlock> stack = new Stack<BasicBlock>(); this.setFlag(SUB_BLOCK); stack.add(this); while (!stack.isEmpty()) { BasicBlock b = stack.pop();/*from ww w. jav a2 s.c om*/ subBlocks.add(b); if (b.lastInstruction() == JSR) { // add the following block, but not its target BasicBlock follower = b.getFollowingBlock(); if (!follower.hasFlag(SUB_BLOCK)) { follower.setFlag(SUB_BLOCK); stack.push(follower); } continue; } for (BasicBlock succ : b.successors) { if (succ == this) { throw new KilimException("JSRs looping back to themselves are not supported"); } if (!succ.hasFlag(SUB_BLOCK)) { succ.setFlag(SUB_BLOCK); stack.push(succ); } } } Collections.sort(subBlocks); } return subBlocks; }
From source file:com.unboundid.scim.sdk.FilterParser.java
/** * Read a filter expression./*w w w . j ava2 s .c om*/ * * @return The SCIM filter. */ private SCIMFilter readFilter() { final Stack<Node> expressionStack = new Stack<Node>(); // Employ the shunting-yard algorithm to parse into reverse polish notation, // where the operands are filter components and the operators are the // logical AND and OR operators. This algorithm ensures that operator // precedence and parentheses are respected. final List<Node> reversePolish = new ArrayList<Node>(); for (String word = readWord(); word != null; word = readWord()) { if (word.equalsIgnoreCase("and") || word.equalsIgnoreCase("or")) { final OperatorNode currentOperator; if (word.equalsIgnoreCase("and")) { currentOperator = new OperatorNode(SCIMFilterType.AND, markPos); } else { currentOperator = new OperatorNode(SCIMFilterType.OR, markPos); } while (!expressionStack.empty() && (expressionStack.peek() instanceof OperatorNode)) { final OperatorNode previousOperator = (OperatorNode) expressionStack.peek(); if (previousOperator.getPrecedence() < currentOperator.getPrecedence()) { break; } reversePolish.add(expressionStack.pop()); } expressionStack.push(currentOperator); } else if (word.equals("(")) { expressionStack.push(new LeftParenthesisNode(markPos)); } else if (word.equals(")")) { while (!expressionStack.empty() && !(expressionStack.peek() instanceof LeftParenthesisNode)) { reversePolish.add(expressionStack.pop()); } if (expressionStack.empty()) { final String msg = String.format( "No opening parenthesis matching closing " + "parenthesis at position %d", markPos); throw new IllegalArgumentException(msg); } expressionStack.pop(); } else { rewind(); final int pos = currentPos; final SCIMFilter filterComponent = readFilterComponent(); reversePolish.add(new FilterNode(filterComponent, pos)); } } while (!expressionStack.empty()) { final Node node = expressionStack.pop(); if (node instanceof LeftParenthesisNode) { final String msg = String.format( "No closing parenthesis matching opening " + "parenthesis at position %d", node.getPos()); throw new IllegalArgumentException(msg); } reversePolish.add(node); } // Evaluate the reverse polish notation to create a single complex filter. final Stack<FilterNode> filterStack = new Stack<FilterNode>(); for (final Node node : reversePolish) { if (node instanceof OperatorNode) { final FilterNode rightOperand = filterStack.pop(); final FilterNode leftOperand = filterStack.pop(); final OperatorNode operatorNode = (OperatorNode) node; if (operatorNode.getFilterType().equals(SCIMFilterType.AND)) { final SCIMFilter filter = SCIMFilter.createAndFilter( Arrays.asList(leftOperand.getFilterComponent(), rightOperand.getFilterComponent())); filterStack.push(new FilterNode(filter, leftOperand.getPos())); } else { final SCIMFilter filter = SCIMFilter.createOrFilter( Arrays.asList(leftOperand.getFilterComponent(), rightOperand.getFilterComponent())); filterStack.push(new FilterNode(filter, leftOperand.getPos())); } } else { filterStack.push((FilterNode) node); } } if (filterStack.size() == 0) { final String msg = String.format("Empty filter expression"); throw new IllegalArgumentException(msg); } else if (filterStack.size() > 1) { final String msg = String.format("Unexpected characters at position %d", expressionStack.get(1).pos); throw new IllegalArgumentException(msg); } return filterStack.get(0).filterComponent; }
From source file:de.tudarmstadt.ukp.wikipedia.parser.mediawiki.ModularParser.java
private void parseTemplates(SpanManager sm, List<Span> resolvedTemplateSpans, List<ResolvedTemplate> resolvedTemplates, ParsedPage pp) { sm.manageList(resolvedTemplateSpans); int pos = -2; Stack<Integer> templateOpenTags = new Stack<Integer>(); while ((pos = sm.indexOf("{{", pos + 2)) != -1) { if (sm.length() > pos + 3 && sm.charAt(pos + 2) == '{' && sm.charAt(pos + 3) != '{') { pos++;/* ww w .j a va 2 s .co m*/ } templateOpenTags.push(pos); } while (!templateOpenTags.empty()) { int templateOpenTag = templateOpenTags.pop(); int templateCloseTag = sm.indexOf("}}", templateOpenTag); if (templateCloseTag == -1) { continue; } int templateOptionTag = sm.indexOf("|", templateOpenTag, templateCloseTag); int templateNameEnd; List<String> templateOptions; if (templateOptionTag != -1) { templateNameEnd = templateOptionTag; templateOptions = tokenize(sm, templateOptionTag + 1, templateCloseTag, "|"); } else { templateNameEnd = templateCloseTag; templateOptions = new ArrayList<String>(); } Span ts = new Span(templateOpenTag, templateCloseTag + 2); Template t = new Template(ts, encodeWikistyle(sm.substring(templateOpenTag + 2, templateNameEnd).trim()), templateOptions); if (calculateSrcSpans) { t.setSrcSpan(new SrcSpan(sm.getSrcPos(templateOpenTag), sm.getSrcPos(templateCloseTag + 2))); } t.setPos(ts); ResolvedTemplate rt = templateParser.parseTemplate(t, pp); resolvedTemplateSpans.add(ts); resolvedTemplates.add(rt); sm.replace(ts, rt.getPreParseReplacement()); } if (resolvedTemplateSpans.isEmpty()) { sm.removeManagedList(resolvedTemplateSpans); } }
From source file:fsi_admin.JFsiTareas.java
public synchronized void respaldarServidor(Calendar fecha, PrintWriter out) { try {// ww w . j a v a 2 s .c o m String path = "/usr/local/forseti/log/RESP-FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".log"; FileWriter filewri = new FileWriter(path, true); PrintWriter pw = new PrintWriter(filewri); if (out != null) { out.println("----------------------------------------------------------------------------<br>"); out.println("RESPALDANDO LA BASE DE DATOS PRINCIPAL: FORSETI_ADMIN Y ARCHIVOS " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.println("----------------------------------------------------------------------------<br>"); out.flush(); } pw.println("----------------------------------------------------------------------------"); pw.println("RESPALDANDO LA BASE DE DATOS PRINCIPAL: FORSETI_ADMIN Y ARCHIVOS " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.println("----------------------------------------------------------------------------"); pw.flush(); if (respaldos.equals("NC")) { if (out != null) { out.println( "PRECAUCION: La variable RESPALDOS (ruta para los archivos de respaldo) no est definida... No se puede generar<br>"); out.flush(); } pw.println( "PRECAUCION: La variable RESPALDOS (ruta para los archivos de respaldo) no est definida... No se puede generar"); pw.flush(); return; } if (tomcat.equals("NC")) { if (out != null) { out.println( "PRECAUCION: La variable TOMCAT (ruta de instalacin de tomcat) no est definida... No se puede generar"); out.flush(); } pw.println( "PRECAUCION: La variable TOMCAT (ruta de instalacin de tomcat) no est definida... No se puede generar"); pw.flush(); return; } JFsiScript sc = new JFsiScript(); sc.setVerbose(true); String ERROR = "", RES = ""; try { JAdmVariablesSet var = new JAdmVariablesSet(null); var.ConCat(true); var.m_Where = "ID_Variable = 'VERSION'"; var.Open(); String vers = var.getAbsRow(0).getVAlfanumerico(); File dir = new File(respaldos, "FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm")); dir.mkdir(); // Primero Agrega el archivo de version para este servidor File version = new File(respaldos + "/" + "FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/forseti.version"); FileWriter fw = new FileWriter(version); fw.write(vers); fw.close(); File diremp = new File(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"), "emp"); diremp.mkdir(); //System.out.println(dir.getAbsolutePath()); String CONTENT = ""; CONTENT += "rsync -av --stats /usr/local/forseti/act " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; CONTENT += "rsync -av --stats /usr/local/forseti/bin " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; CONTENT += "rsync -av --stats /usr/local/forseti/log " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; CONTENT += "rsync -av --stats /usr/local/forseti/pac " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; CONTENT += "rsync -av --stats /usr/local/forseti/rec " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; CONTENT += "rsync -av --stats " + tomcat + "/webapps/ROOT.war " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "\n"; sc.setContent(CONTENT); System.out.println(CONTENT); RES = sc.executeCommand(); ERROR += sc.getError(); if (!ERROR.equals("")) { if (out != null) { pw.println("ERROR al respaldar en RSYNC: " + ERROR + "<br>"); pw.flush(); } pw.println("ERROR al respaldar en RSYNC: " + ERROR); pw.flush(); } else { if (out != null) { out.println("El respaldo de los archivos se genero con xito en: " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "<br>"); out.flush(); } pw.println("El respaldo de los archivos se genero con xito en: " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm")); pw.flush(); } if (out != null) { out.println("FINALIZANDO RESPALDO DE ARCHIVOS FORSETI_ADMIN: " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.flush(); } pw.println("FINALIZANDO RESPALDO DE ARCHIVOS FORSETI_ADMIN: " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.flush(); RES = ""; ERROR = ""; CONTENT = "PGUSER=forseti PGPASSWORD=" + JUtil.getPASS() + " pg_dump --host=" + JUtil.getADDR() + " --port=" + JUtil.getPORT() + " --file=" + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".dump FORSETI_ADMIN"; sc.setContent(CONTENT); //System.out.println(CONTENT); RES = sc.executeCommand(); ERROR += sc.getError(); //Ahora genera el Archivo Base64 if (!ERROR.equals("")) { //System.out.println(ERROR); if (out != null) { out.println("ERROR al crear el respaldo de la base de datos principal: " + ERROR + "<br>"); out.flush(); } pw.println("ERROR al crear el respaldo de la base de datos principal: " + ERROR); pw.flush(); } else { if (RES.equals("")) { if (out != null) { out.println( "El respaldo de la base de datos principal se gener con xito como archivo .dump dentro de este directurio"); out.flush(); } pw.println( "El respaldo de la base de datos principal se gener con xito como archivo .dump dentro de este directurio"); pw.flush(); } else { if (out != null) { out.println("RESPUESTA PG_DUMP: " + RES + "<br>"); out.flush(); } pw.println("RESPUESTA PG_DUMP: " + RES); pw.flush(); } } ////////////////////////////////////////// if (out != null) { out.println("FINALIZANDO RESPALDO DE LA BASE DE DATOS: FORSETI_ADMIN " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.flush(); } pw.println("FINALIZANDO RESPALDO DE LA BASE DE DATOS: FORSETI_ADMIN " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.flush(); } catch (Throwable e) { if (out != null) { out.println("ERROR Throwable:<br>"); e.printStackTrace(out); out.flush(); } pw.println("ERROR Throwable:"); e.printStackTrace(pw); pw.flush(); } JBDSSet set = new JBDSSet(null); set.ConCat(true); set.m_OrderBy = "ID_BD ASC"; set.Open(); for (int i = 0; i < set.getNumRows(); i++) { if (!set.getAbsRow(i).getSU().equals("3")) // La base de datos esta corrupta, se debe eliminar { out.println("La siguiente base de datos esta corrupta y se debe eliminar: " + set.getAbsRow(i).getNombre() + "<br>"); out.flush(); pw.println("La siguiente base de datos esta corrupta y se debe eliminar: " + set.getAbsRow(i).getNombre()); pw.flush(); continue; } else respaldarEmpresa(set, i, fecha, out, pw); } if (out != null) { out.println( "Generando el archivo zip... Esto puede tardar demasiado tiempo, hay que ser pacientes<br>"); out.flush(); } pw.println("Generando el archivo zip..."); pw.flush(); JZipUnZipUtil azip = new JZipUnZipUtil(); azip.zipFolder(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"), respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".zip"); if (out != null) { out.println("Eliminando carpeta de respaldo...<br>"); out.flush(); } pw.println("Eliminando carpeta de respaldo..."); pw.flush(); //Borra los archivos del respaldo File dirbd = new File(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm")); File[] currList; Stack<File> stack = new Stack<File>(); stack.push(dirbd); while (!stack.isEmpty()) { if (stack.lastElement().isDirectory()) { currList = stack.lastElement().listFiles(); if (currList.length > 0) { for (File curr : currList) { stack.push(curr); } } else { stack.pop().delete(); } } else { stack.pop().delete(); } } if (out != null) { out.println("--------------- FIN DEL RESPALDO " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + " ---------------<br>"); out.flush(); } pw.println("--------------- FIN DEL RESPALDO " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + " ---------------"); pw.flush(); pw.close(); } catch (IOException e) { if (out != null) { out.println("OCURRIERON ERRORES DE IOException<br>"); e.printStackTrace(out); out.flush(); } System.out.println("OCURRIERON ERRORES DE IOException<br>"); e.printStackTrace(System.out); } catch (Exception e) { if (out != null) { out.println("OCURRIERON ERRORES DE Exception<br>"); e.printStackTrace(out); out.flush(); } System.out.println("OCURRIERON ERRORES DE Exception<br>"); e.printStackTrace(System.out); } }
From source file:org.apache.tajo.engine.planner.LogicalPlanner.java
public LogicalNode visitInsert(PlanContext context, Stack<Expr> stack, Insert expr) throws PlanningException { stack.push(expr); LogicalNode subQuery = super.visitInsert(context, stack, expr); stack.pop();/*from w w w . j a v a 2 s . co m*/ InsertNode insertNode = context.queryBlock.getNodeFromExpr(expr); insertNode.setOverwrite(expr.isOverwrite()); insertNode.setSubQuery(subQuery); if (expr.hasTableName()) { // INSERT (OVERWRITE) INTO TABLE ... return buildInsertIntoTablePlan(context, insertNode, expr); } else if (expr.hasLocation()) { // INSERT (OVERWRITE) INTO LOCATION ... return buildInsertIntoLocationPlan(context, insertNode, expr); } else { throw new IllegalStateException("Invalid Query"); } }
From source file:fsi_admin.JFsiTareas.java
public synchronized void respaldarEmpresa(JBDSSet set, int ind, Calendar fecha, PrintWriter out, PrintWriter prntwri) {/*w ww.j ava2 s . co m*/ try { //Primero respalda emp/NOMBRE/ String nombre = set.getAbsRow(ind).getNombre(); String path = "/usr/local/forseti/log/RESP-" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".log"; PrintWriter pw; if (prntwri == null) pw = new PrintWriter(new FileWriter(path, true)); else pw = prntwri; if (out != null) { out.println("----------------------------------------------------------------------------<br>"); out.println("RESPALDANDO LA BASE DE DATOS Y ARCHIVOS EMP: " + nombre.substring(6) + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.println("----------------------------------------------------------------------------<br>"); out.flush(); } pw.println("----------------------------------------------------------------------------"); pw.println("RESPALDANDO LA BASE DE DATOS Y ARCHIVOS EMP: " + nombre.substring(6) + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.println("----------------------------------------------------------------------------"); pw.flush(); if (respaldos.equals("NC")) { if (out != null) { out.println( "PRECAUCION: La variable RESPALDOS (ruta para los archivos de respaldo) no est definida... No se puede generar<br>"); out.flush(); } pw.println( "PRECAUCION: La variable RESPALDOS (ruta para los archivos de respaldo) no est definida... No se puede generar"); pw.flush(); return; } JFsiScript sc = new JFsiScript(); sc.setVerbose(true); String ERROR = ""; try { File dir; //System.out.println(dir.getAbsolutePath()); String CONTENT; JAdmVariablesSet var = new JAdmVariablesSet(null); var.ConCat(3); var.setBD(nombre); var.m_Where = "ID_Variable = 'VERSION'"; var.Open(); String vers = var.getAbsRow(0).getVAlfanumerico(); if (prntwri == null) { dir = new File(respaldos, (nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"))); dir.mkdir(); // Primero Agrega el archivo de version para esta empresa File version = new File(respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/forseti.version"); FileWriter fw = new FileWriter(version); fw.write(vers); fw.close(); CONTENT = "rsync -av --stats /usr/local/forseti/emp/" + nombre.substring(6) + " " + respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"); } else { dir = new File(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"), (nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"))); dir.mkdir(); // Primero Agrega el archivo de version para esta empresa File version = new File(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/forseti.version"); FileWriter fw = new FileWriter(version); fw.write(vers); fw.close(); CONTENT = "rsync -av --stats /usr/local/forseti/emp/" + nombre.substring(6) + " " + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"); } sc.setContent(CONTENT); //System.out.println(CONTENT); String RES = sc.executeCommand(); ERROR += sc.getError(); if (!ERROR.equals("")) { if (out != null) { out.println("ERROR al respaldar en RSYNC: " + ERROR + "<br>"); out.flush(); } pw.println("ERROR al respaldar en RSYNC: " + ERROR); pw.flush(); } else { if (out != null) { out.println("El respaldo de los archivos se gener con xito en: " + respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "<br>"); out.flush(); } pw.println("El respaldo de los archivos se gener con xito en: " + respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm")); pw.flush(); } if (out != null) { out.println("FINALIZANDO RESPALDO DE ARCHIVOS EMP: " + nombre.substring(6) + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.println( "Comenzando el respaldo de la base de datos... Esto puede tardar muchos minutos, incluso horas (dependiendo de la cantidad de informacin) hay que ser pacientes<br>"); out.flush(); } pw.println("FINALIZANDO RESPALDO DE ARCHIVOS EMP: " + nombre.substring(6) + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.flush(); ERROR = ""; if (prntwri == null) CONTENT = "PGUSER=forseti PGPASSWORD=" + JUtil.getPASS() + " pg_dump --host=" + JUtil.getADDR() + " --port=" + JUtil.getPORT() + " --file=" + respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".dump --no-owner " + nombre; else CONTENT = "PGUSER=forseti PGPASSWORD=" + JUtil.getPASS() + " pg_dump --host=" + JUtil.getADDR() + " --port=" + JUtil.getPORT() + " --file=" + respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".dump --no-owner " + nombre; sc.setContent(CONTENT); //System.out.println(CONTENT); RES = sc.executeCommand(); ERROR += sc.getError(); if (!ERROR.equals("")) { //System.out.println(ERROR); if (out != null) { out.println("ERROR al crear el respaldo de la base de datos: " + ERROR + "<br>"); out.flush(); } pw.println("ERROR al crear el respaldo de la base de datos: " + ERROR); pw.flush(); } else { if (RES.equals("")) { if (out != null) { out.println( "El respaldo de la base de datos se gener con xito como archivo .dump dentro de este directorio<br>"); out.flush(); } pw.println( "El respaldo de la base de datos se gener con xito como archivo .dump dentro de este directorio"); pw.flush(); } else { if (out != null) { out.println("RESPUESTA PG_DUMP: " + RES + "<br>"); out.flush(); } pw.println("RESPUESTA PG_DUMP: " + RES); pw.flush(); } } if (out != null) { out.println("FINALIZANDO RESPALDO DE LA BASE DE DATOS: " + nombre + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss") + "<br>"); out.flush(); } pw.println("FINALIZANDO RESPALDO DE LA BASE DE DATOS: " + nombre + " " + JUtil.obtFechaTxt(new Date(), "HH:mm:ss")); pw.flush(); File file; if (prntwri == null) file = new File(respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".conf"); else file = new File(respaldos + "/FORSETI_ADMIN-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".conf"); String conf = "id_bd|" + set.getAbsRow(ind).getID_BD() + "\n" + "nombre|" + set.getAbsRow(ind).getNombre() + "\n" + "usuario|" + set.getAbsRow(ind).getUsuario() + "\n" + "password|" + set.getAbsRow(ind).getPassword() + "\n" + "fechaalta|" + JUtil.obtFechaSQL(set.getAbsRow(ind).getFechaAlta()) + "\n" + "compania|" + set.getAbsRow(ind).getCompania() + "\n" + "direccion|" + set.getAbsRow(ind).getDireccion() + "\n" + "poblacion|" + set.getAbsRow(ind).getPoblacion() + "\n" + "cp|" + set.getAbsRow(ind).getCP() + "\n" + "mail|" + set.getAbsRow(ind).getMail() + "\n" + "web|" + set.getAbsRow(ind).getWeb() + "\n" + "su|" + set.getAbsRow(ind).getSU() + "\n" + "rfc|" + set.getAbsRow(ind).getRFC() + "\n" + "cfd|" + set.getAbsRow(ind).getCFD() + "\n" + "cfd_calle|" + set.getAbsRow(ind).getCFD_Calle() + "\n" + "cfd_noext|" + set.getAbsRow(ind).getCFD_NoExt() + "\n" + "cfd_noint|" + set.getAbsRow(ind).getCFD_NoInt() + "\n" + "cfd_colonia|" + set.getAbsRow(ind).getCFD_Colonia() + "\n" + "cfd_localidad|" + set.getAbsRow(ind).getCFD_Localidad() + "\n" + "cfd_municipio|" + set.getAbsRow(ind).getCFD_Municipio() + "\n" + "cfd_estado|" + set.getAbsRow(ind).getCFD_Estado() + "\n" + "cfd_pais|" + set.getAbsRow(ind).getCFD_Pais() + "\n" + "cfd_cp|" + set.getAbsRow(ind).getCFD_CP() + "\n" + "cfd_regimenfiscal|" + set.getAbsRow(ind).getCFD_RegimenFiscal(); FileWriter fconf = new FileWriter(file); fconf.write(conf); fconf.close(); if (out != null) { out.println( "El respaldo de la configuracin se gener con xito como archivo .conf en este directorio<br>"); out.flush(); } pw.println( "El respaldo de la configuracin se gener con xito como archivo .conf en este directorio"); pw.flush(); if (prntwri == null) { if (out != null) { out.println("Generando el archivo zip...<br>"); out.flush(); } pw.println("Generando el archivo zip..."); pw.flush(); JZipUnZipUtil azip = new JZipUnZipUtil(); azip.zipFolder(respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm"), respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm") + ".zip"); if (out != null) { out.println("Eliminando carpeta de respaldo<br>"); out.flush(); } pw.println("Eliminando carpeta de respaldo..."); pw.flush(); //Borra los archivos del respaldo File dirbd = new File( respaldos + "/" + nombre + "-" + JUtil.obtFechaTxt(fecha, "yyyy-MM-dd-HH-mm")); File[] currList; Stack<File> stack = new Stack<File>(); stack.push(dirbd); while (!stack.isEmpty()) { if (stack.lastElement().isDirectory()) { currList = stack.lastElement().listFiles(); if (currList.length > 0) { for (File curr : currList) { stack.push(curr); } } else { stack.pop().delete(); } } else { stack.pop().delete(); } } } } catch (Throwable e) { if (out != null) { out.println("ERROR Throwable:<br>"); e.printStackTrace(out); out.flush(); } pw.println("ERROR Throwable:\n"); e.printStackTrace(pw); pw.flush(); } if (out != null) { out.println("----------------------------- FIN DEL RESPALDO: " + nombre + " ----------------------------------<br>"); out.flush(); } pw.println("----------------------------- FIN DEL RESPALDO: " + nombre + " ----------------------------------"); pw.flush(); if (prntwri == null) pw.close(); } catch (IOException e) { if (out != null) { out.println("OCURRIERON ERRORES AL ABRIR O COPIAR ARCHIVOS<br>"); e.printStackTrace(out); out.flush(); } e.printStackTrace(System.out); } }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java
private ParserPair handleGroup(InputStream contentStream, Stack<Map<String, Integer>> state, StringBuilder text, RTFDocument document) throws IOException { int c = contentStream.read(); char ch = NULL_CHAR; ParserPair pair = null;/*from w w w . j a va 2s . co m*/ String groupName = null; while (c != -1) { ch = (char) c; if (!Character.isWhitespace(ch)) { break; } else { c = contentStream.read(); } } if (ch == BACKSLASH) { pair = handleControl(contentStream, safeState(state)); c = pair.fChar; groupName = pair.fString; } else { groupName = " "; } if (in(groupName, IGNORE_GROUPS)) { c = skipGroup(contentStream, c); } else { Map<String, Integer> oldState = safeState(state); reset(oldState, text, document); Map<String, Integer> newState = new HashMap<String, Integer>(oldState); newState.put(UNICOUNT, oldState.get(UNICOUNT)); state.push(newState); resetNew(text, newState, document); handleControlCommand(groupName, text, newState, document); } return new ParserPair(c, groupName); }
From source file:com.ricemap.spateDB.core.RTree.java
/** * Searches the RTree starting from the given start position. This is either * a node number or offset of an element. If it's a node number, it performs * the search in the subtree rooted at this node. If it's an offset number, * it searches only the object found there. It is assumed that the * openQuery() has been called before this function and that endQuery() will * be called afterwards.// w w w . j a va 2 s . c om * * @param query_mbr * @param output * @param start * - where to start searching * @param end * - where to end searching. Only used when start is an offset of * an object. * @return * @throws IOException */ protected int searchColumnar(Shape query_shape, ResultCollector<Writable> output, int start, int end, String field) throws IOException { if (output == null) { throw new RuntimeException("Output is NULL"); } //build search field int fieldOffset = 0; int fieldSize = -1; FIELD_TYPE fieldType = FIELD_TYPE.NULL; //get fields Field[] fields = stockObject.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(field)) { if (fields[i].getType().equals(Integer.TYPE)) { fieldSize = 4; fieldType = FIELD_TYPE.Integer; } else if (fields[i].getType().equals(Long.TYPE)) { fieldSize = 8; fieldType = FIELD_TYPE.Long; } else if (fields[i].getType().equals(Double.TYPE)) { fieldSize = 8; fieldType = FIELD_TYPE.Double; } else { //throw new RuntimeException("Unsupported type: " + fields[i].getType()); } break; } else { if (fields[i].getType().equals(Integer.TYPE)) { fieldOffset += elementCount * 4; } else if (fields[i].getType().equals(Long.TYPE) || fields[i].getType().equals(Double.TYPE)) { fieldOffset += elementCount * 8; } else { //throw new RuntimeException("Unsupported type: " + fields[i].getType()); } } } Prism query_mbr = query_shape.getMBR(); int resultSize = 0; // Special case for an empty tree if (height == 0) return 0; Stack<Integer> toBeSearched = new Stack<Integer>(); // Start from the given node toBeSearched.push(start); if (start >= nodeCount) { toBeSearched.push(end); } Prism node_mbr = new Prism(); // Holds one data line from tree data Text line = new Text2(); while (!toBeSearched.isEmpty()) { int searchNumber = toBeSearched.pop(); int mbrsToTest = searchNumber == 0 ? 1 : degree; if (searchNumber < nodeCount) { long nodeOffset = NodeSize * searchNumber; structure.seek(nodeOffset); int dataOffset = structure.readInt(); for (int i = 0; i < mbrsToTest; i++) { node_mbr.readFields(structure); int lastOffset = (searchNumber + i) == nodeCount - 1 ? elementCount - 1 : structure.readInt(); if (query_mbr.contains(node_mbr)) { // The node is full contained in the query range. // Save the time and do full scan for this node // Checks if this node is the last node in its level // This can be easily detected because the next node in // the level // order traversal will be the first node in the next // level // which means it will have an offset less than this // node if (lastOffset <= dataOffset) lastOffset = elementCount; data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + elementCount * IndexUnitSize + fieldOffset + dataOffset * fieldSize); for (int j = 0; j < lastOffset - dataOffset; j++) { switch (fieldType) { case Integer: output.collect(new IntWritable(data.readInt())); break; case Long: output.collect(new LongWritable(data.readLong())); break; case Double: output.collect(new DoubleWritable(data.readDouble())); break; default: output.collect( new Point3d(data.readDouble(), data.readDouble(), data.readDouble())); break; } resultSize++; } } else if (query_mbr.isIntersected(node_mbr)) { // Node partially overlaps with query. Go deep under // this node if (searchNumber < nonLeafNodeCount) { // Search child nodes toBeSearched.push((searchNumber + i) * degree + 1); } else { // Search all elements in this node //toBeSearched.push(dataOffset); // Checks if this node is the last node in its level // This can be easily detected because the next node // in the level // order traversal will be the first node in the // next level // which means it will have an offset less than this // node if (lastOffset <= dataOffset) lastOffset = elementCount; //toBeSearched.push(lastOffset); data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + dataOffset * IndexUnitSize); boolean report[] = new boolean[lastOffset - dataOffset]; Point3d point = new Point3d(); for (int j = 0; j < lastOffset - dataOffset; j++) { point.t = data.readDouble(); point.x = data.readDouble(); point.y = data.readDouble(); if (point.isIntersected(query_shape)) { report[j] = true; } else report[j] = false; } data.seek(treeStartOffset + TreeHeaderSize + nodeCount * NodeSize + elementCount * IndexUnitSize + fieldOffset + dataOffset * fieldSize); for (int j = 0; j < lastOffset - dataOffset; j++) { if (report[j]) { switch (fieldType) { case Integer: output.collect(new IntWritable(data.readInt())); break; case Long: output.collect(new LongWritable(data.readLong())); break; case Double: output.collect(new DoubleWritable(data.readDouble())); break; default: output.collect(new Point3d(data.readDouble(), data.readDouble(), data.readDouble())); break; } resultSize++; } } } } dataOffset = lastOffset; } } else { LOG.error("searchNumber > nodeCount, something is wrong"); int firstOffset, lastOffset; // Search for data items (records) lastOffset = searchNumber; firstOffset = toBeSearched.pop(); data.seek(firstOffset + treeStartOffset); LineReader lineReader = new LineReader(data); while (firstOffset < lastOffset) { firstOffset += lineReader.readLine(line); stockObject.fromText(line); if (stockObject.isIntersected(query_shape)) { resultSize++; if (output != null) output.collect(stockObject); } } } } return resultSize; }
From source file:net.servicefixture.fitnesse.FixtureTemplateCreator.java
/** * Adds the tablerow to the test table./*from w w w . j a v a2 s. com*/ * @param ancestors * * @param string * @param returnType */ private void addTableRowsForType(Stack<Class> ancestors, String prefix, Class type, boolean isSetRow) { if (ReflectionUtils.isLowestLevelType(type)) { writeLine(prefix + "|" + (isSetRow ? ReflectionUtils.getDefaultValue(type) : "") + "|"); return; } //If the type is an abstract type, generate rows for all of its subclasses. if (ReflectionUtils.isAbstractType(type)) { Class[] subClasses = ReflectionUtils.findSubClasses(type); for (int i = 0; i < subClasses.length; i++) { if (isSetRow) { writeLine(prefix + "|" + TreeParser.CLASS_TYPE_PREFIX + subClasses[i].getName() + TreeParser.CLASS_TYPE_SUFFIX + "|"); } else { writeLine(prefix + ".class.name|" + subClasses[i].getName() + "|"); } addTableRowsForType(ancestors, prefix, subClasses[i], isSetRow); } return; } //Handles regular type Map<String, Class> attributes = ReflectionUtils.getAttributes(type); for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { String attributeName = (String) iter.next(); Class attributeType = (Class) attributes.get(attributeName); if (ReflectionUtils.isLowestLevelType(attributeType)) { //size is the reserved word for common jexl library, call the getter method instead. if ("size".equals(attributeName) && !isSetRow) { attributeName = "getSize()"; } writeLine(prefix + "." + attributeName + "|" + (isSetRow ? ReflectionUtils.getDefaultValue(attributeType) : "") + "|"); } else { if (ancestors.contains(attributeType)) { writeLine(prefix + "." + attributeName + "|" + (isSetRow ? "${nil.object}" : "") + "|"); } else { ancestors.push(attributeType); addTableRowsForType(ancestors, prefix + "." + attributeName, attributeType, isSetRow); ancestors.pop(); } } } }