List of usage examples for java.util Stack Stack
public Stack()
From source file:com.pinterest.rocksplicator.controller.tasks.ChainedTask.java
@Override public void process(Context ctx) throws Exception { long id = ctx.getId(); final String cluster = ctx.getCluster(); final String worker = ctx.getWorker(); final TaskQueue taskQueue = ctx.getTaskQueue(); Stack<TaskBase> tasks = new Stack<>(); tasks.push(getParameter().getT2());//w w w.j ava 2s . c om tasks.push(getParameter().getT1()); while (!tasks.isEmpty()) { TaskBase taskBase = tasks.pop(); AbstractTask task = TaskFactory.getWorkerTask(taskBase); if (task == null) { taskQueue.failTask(id, "Failed to instantiate task " + taskBase.name); return; } else if (task instanceof ChainedTask) { ChainedTask chainedTask = (ChainedTask) task; tasks.push(chainedTask.getParameter().getT2()); tasks.push(chainedTask.getParameter().getT1()); } else { LocalAckTaskQueue lq = new LocalAckTaskQueue(taskQueue); ctx = new Context(id, cluster, lq, worker); try { task.process(ctx); } catch (Exception ex) { LOG.error("Unexpected exception from task: {} in task chain.", task.getName(), ex); lq.failTask(id, ex.getMessage()); } LocalAckTaskQueue.State state = lq.getState(); if (state.state == LocalAckTaskQueue.State.StateName.UNFINISHED) { LOG.error("Task {} finished processing without ack", id); return; } else if (state.state == LocalAckTaskQueue.State.StateName.FAILED) { LOG.error("Task {} failed with reason: {}. Abort the task chain.", id, state.output); taskQueue.failTask(id, state.output); return; } else if (tasks.isEmpty()) { LOG.info("Finished processing chained task"); taskQueue.finishTask(id, state.output); return; } long nextId = taskQueue.finishTaskAndEnqueueRunningTask(id, state.output, tasks.peek(), worker); if (nextId < 0) { LOG.error("Failed to finish task {} and enqueue new task {}", id, tasks.peek()); return; } else { id = nextId; } } } }
From source file:com.itmanwuiso.checksums.FileDuplicateChecker.java
private static void prepare(int cores, String storageFile) { checksumPool = new ChecksumWorkerPoolImpl(cores * 2 + 5); storage = new SaveResultDAOFile(writers); folderStack = recursive ? new Stack<File>() : null; writers = new LinkedList<ResultWriter>(); // System.out = new QuitePrinter(System.out); }
From source file:roboguice.calculator.view.TickerTapeView.java
public void refresh() { Stack<String> lines = new Stack<String>(); String digitAccumulator = stack.getDigitAccumulator(); // Include the current number that the user is typing in the display if (digitAccumulator.length() > 0) lines.push(digitAccumulator);//from w ww.ja v a 2s.c om // Include up to 3 lines of stack for (int i = 0; lines.size() < 3 && i < stack.size(); ++i) lines.push(stack.get(stack.size() - i - 1).toString()); // Convert to text String text = ""; for (String line : lines) text = line + "\n" + text + "\n"; setText(text.trim()); }
From source file:com.glaf.batch.job.BatchJob.java
public void execute(JobExecution execution) { IJobService jobService = ContextFactory.getBean("jobService"); if (execution.getSteps() != null && !execution.getSteps().isEmpty()) { List<StepExecution> steps = execution.getSteps(); Collections.sort(steps);//from w w w. j a va 2 s . c o m /** * ?? */ Stack<StepExecution> stack = new Stack<StepExecution>(); for (int i = steps.size() - 1; i >= 0; i--) { stack.push(steps.get(i)); } while (!stack.empty()) { StepExecution step = stack.peek(); if (!jobService.stepExecutionCompleted(step.getJobStepKey())) { boolean success = false; int retry = 0; while (retry < 3 && !success) { retry++; try { jobService.startStepExecution(step.getJobStepKey()); if (StringUtils.isNotEmpty(step.getJobClass())) { Object object = ClassUtils.instantiateObject(step.getJobClass()); if (object instanceof IStep) { IStep ix = (IStep) object; ix.execute(step); if (jobService.stepExecutionCompleted(step.getJobStepKey())) { /** * ???? */ stack.pop(); success = true; retry = Integer.MAX_VALUE; break; } } } } catch (Exception ex) { ex.printStackTrace(); } } if (!success) { throw new RuntimeException( step.getStepKey() + " " + step.getStepName() + " execute failed."); } } } } }
From source file:name.martingeisse.common.util.ContextAwareXmlWriter.java
/** * Initializes the context stack if not yet done. *//*from w w w . j a va 2 s . c o m*/ private final void lazyInitializeContextStack() { if (contextStack == null) { contextStack = new Stack<Object>(); } }
From source file:com.anrisoftware.sscontrol.core.groovy.groovyloader.ScriptBuilder.java
public ScriptBuilder() { this.delegate = new Stack<Proxy>(); }
From source file:cat.albirar.framework.sets.impl.SetBuilderDefaultImpl.java
/** * Unique constructor.//from w w w. ja v a 2 s . com * @param rootModel The root model to build the {@link ISet}. <b>required</b> * @throws IllegalArgumentException If the {@code rootModel} is null */ public SetBuilderDefaultImpl(Class<? extends T> rootModel) { Assert.notNull(rootModel, "The rootModel argument is required"); this.rootModel = rootModel; pathStack = new Stack<ModelDescriptor>(); properties = new Vector<String>(); currentModelDescriptor = new ModelDescriptor(rootModel); // The root always on bottom of stack pathStack.push(currentModelDescriptor); }
From source file:org.openremote.server.route.SubflowRoute.java
public static void pushOntoCorrelationStack(Map<String, Object> headers, String identifier) { // Create or get existing stack from headers @SuppressWarnings("unchecked") Stack<String> subflowCorrelationStack = hasCorrelationStack(headers) ? (Stack<String>) headers.get(SUBFLOW_CORRELATION_STACK) : new Stack<>(); LOG.debug("Pushing identifier'" + identifier + "' onto correlation stack: " + subflowCorrelationStack); subflowCorrelationStack.push(identifier); LOG.debug("Setting correlation stack header: " + subflowCorrelationStack); headers.put(SUBFLOW_CORRELATION_STACK, subflowCorrelationStack); }
From source file:name.martingeisse.reporting.renderer.HtmlRenderer.java
/** * Renders the specified document./*from w w w .j a va 2s. c o m*/ * @param document the document to render * @param outputFile the output file to write to */ public void render(Document document, File outputFile) { try { this.outputFile = outputFile; this.out = new PrintWriter(outputFile, "utf-8"); this.sectionStack = new Stack<Section>(); this.resourceCounter = 0; render(document); this.out.flush(); this.out.close(); this.out = null; this.outputFile = outputFile; this.sectionStack = null; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java
public void startDocument() { subsEx = null;/* w ww . jav a2 s . c om*/ response = new SubsonicResponse(); response.setEntryList(new ArrayList<Entry>()); stack = new Stack<ArrayList<Entry>>(); stack.push(response.getEntryList()); }