/** * Executes the command in the executor it is currently set to. * * @param source that sent the command * @param args command arguments * @throws CommandException if the command executor is null or if {@link * Executor#execute(CommandSource, Command, CommandArguments)} throws a CommandException. */ public void process(CommandSource source, CommandArguments args) throws CommandException { // check permissions if (permission != null && !source.hasPermission(permission)) { throw new CommandException("You do not have permission to execute this command."); } args.flags().registerFlags(this.flags); // no child found, try to execute for (CommandFilter filter : filters) { filter.validate(this, source, args); } // execute a child if applicable if (children.size() > 0) { Command child = getChild(args.popString("child"), false); if (child != null) { if (executor != null) { executor.execute(source, this, args); } child.process(source, args); } else { throw args.failure("child", "Unknown child!", false); } } else { if (executor == null) { throw new CommandException("CommandDescription exists but has no set executor."); } args.flags().parse(); executor.execute(source, this, args); } }
public static <R> R execute( String url, String traceHearName, HttpRequest httpRequest, Executor<R> executor) throws IOException { if (!AuthDesc.isAuth()) { return executor.execute(); } try { httpRequest.setHeader( traceHearName, "ContextData=" + sender .beforeSend( Identification.newBuilder() .viewPoint(url) .spanType(WEBBuriedPointType.instance()) .build()) .toString()); return executor.execute(); } catch (IOException e) { sender.handleException(e); throw e; } finally { sender.afterSend(); } }
public static void run( InvocationOutputHandler outputHandler, Map<String, String> envVarsForApp, CommandLine command, File projectRoot, long timeout) throws ProjectCannotStartException { long startTime = logStartInfo(command, projectRoot); ExecuteWatchdog watchDog = new ExecuteWatchdog(timeout); Executor executor = createExecutor(outputHandler, command, projectRoot, watchDog); try { int exitValue = executor.execute(command, envVarsForApp); if (executor.isFailure(exitValue)) { String message = watchDog.killedProcess() ? "Timed out waiting for " + command : "Exit code " + exitValue + " returned from " + command; throw new ProjectCannotStartException(message); } } catch (Exception e) { String message = "Error running: " + dirPath(projectRoot) + "> " + StringUtils.join(command.toStrings(), " "); outputHandler.consumeLine(message); outputHandler.consumeLine(e.toString()); throw new ProjectCannotStartException(message, e); } logEndTime(command, startTime); }
/** * Schedules runnable task for execution. * * @param w Runnable task. * @throws GridException Thrown if any exception occurred. */ @SuppressWarnings({"CatchGenericClass", "ProhibitedExceptionThrown"}) public void execute(final GridWorker w) throws GridException { workers.add(w); try { exec.execute( new Runnable() { @Override public void run() { try { w.run(); } finally { workers.remove(w); } } }); } catch (RejectedExecutionException e) { workers.remove(w); throw new GridComputeExecutionRejectedException( "Failed to execute worker due to execution rejection.", e); } catch (RuntimeException e) { workers.remove(w); throw new GridException("Failed to execute worker due to runtime exception.", e); } catch (Error e) { workers.remove(w); throw e; } }
private void reallyStart() { synchronized (syncLock) { threadStarted = true; } if (logMINOR) Logger.minor(this, "Starting thread... " + name + " : " + runner); realExecutor.execute(runner, name); }
public void execute() throws ExecuteException { if (executor == null) { throw new ExecuteException(name + ": is not defined"); } else { executor.execute(); } }
public static void main(String[] args) throws IOException { ServerSocket socket = new ServerSocket(9001); while (true) { final Socket connection = socket.accept(); exec.execute(new ConnectionHandlerTask(connection)); } }
void processInParallel(Executor exec, List<Element> elements) { for (final Element e : elements) exec.execute( new Runnable() { public void run() { process(e); } }); }
/** * Receives users command until 'Esc' entered * * @param args */ public static void main(String[] args) { Executor e = new Executor(); Scanner input = new Scanner(System.in); String userData = "-help"; e.about(); while (!"Esc".equals(userData)) { e.execute(userData); userData = input.nextLine(); } }
/** * Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this * means all tasks submitted before this point are now completed. Usually you won't want to use * this method - it's a convenience primarily used in unit testing. If you want to wait for an * event to be called the right thing to do is usually to create a {@link * com.google.common.util.concurrent.SettableFuture} and then call set on it. You can then either * block on that future, compose it, add listeners to it and so on. */ public static void waitForUserCode() { final CountDownLatch latch = new CountDownLatch(1); USER_THREAD.execute( new Runnable() { @Override public void run() { latch.countDown(); } }); Uninterruptibles.awaitUninterruptibly(latch); }
public static void main(String[] args) { Executor ex = new GameLogExecutorNate(); try { ex.execute(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public <T> void parallelRecursive( final Executor exec, List<Node<T>> nodes, final Collection<T> results) { for (final Node<T> n : nodes) { exec.execute( new Runnable() { public void run() { results.add(n.compute()); } }); parallelRecursive(exec, n.getChildren(), results); } }
private void reallyStart() { synchronized (jobs) { if (running) { Logger.error(this, "Not reallyStart()ing: ALREADY RUNNING", new Exception("error")); return; } running = true; if (logMINOR) Logger.minor(this, "Starting thread... " + name + " : " + runner, new Exception("debug")); realExecutor.execute(runner, name); } }
/** {@inheritDoc} */ @Override public void run() { List<Grid> clientGrids = runGrid(); assert clientGrids.size() == clientNodes; int threadsCnt = clientNodes * threadsPerClient; Executor e = Executors.newFixedThreadPool(threadsCnt); for (Grid grid : clientGrids) { for (int j = 0; j < threadsPerClient; j++) e.execute(new GridJobLoadTestSubmitter(grid, taskParams, cancelRate, submitDelay)); } }
public void submitTask(final Runnable command) throws InterruptedException { semaphore.acquire(); try { exec.execute( new Runnable() { public void run() { try { command.run(); } finally { semaphore.release(); } } }); } catch (RejectedExecutionException e) { semaphore.release(); } }
public static Killer startDaemon( InvocationOutputHandler buildLogHandler, InvocationOutputHandler consoleLogHandler, Map<String, String> envVarsForApp, CommandLine command, File projectRoot, Waiter startupWaiter) { long startTime = logStartInfo(command, projectRoot); Killer watchDog = new Killer(ExecuteWatchdog.INFINITE_TIMEOUT); Executor executor = createExecutor(consoleLogHandler, command, projectRoot, watchDog); try { DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); executor.execute(command, envVarsForApp, handler); startupWaiter.or(c -> handler.hasResult()); // stop waiting if the process exist startupWaiter.blockUntilReady(); if (handler.hasResult()) { String message = "The project at " + dirPath(projectRoot) + " started but exited all too soon. Check the console log for information."; buildLogHandler.consumeLine(message); throw new ProjectCannotStartException(message); } } catch (TimeoutException te) { String message = "Built successfully, but timed out waiting for startup at " + dirPath(projectRoot); watchDog.destroyProcess(); buildLogHandler.consumeLine(message); throw new ProjectCannotStartException(message); } catch (ProjectCannotStartException pcse) { throw pcse; } catch (Exception e) { String message = "Built successfully, but error on start for " + dirPath(projectRoot); buildLogHandler.consumeLine(message); buildLogHandler.consumeLine(e.toString()); throw new ProjectCannotStartException(message, e); } logEndTime(command, startTime); return watchDog; }
public static void main(String[] args) { String job = null; String jobType = null; if (args.length > 0) { job = args[0]; } if (job == null || job.length() == 0) { m_traceLogger.info("작업명을 입력하여 주시기 바랍니다.(first | second ), Input : null"); } else if (job.equals(BLOG_BACKUP_FIRST)) { jobType = "1"; exec = new BlogBackupFirstExecutor(); } else if (job.equals(BLOG_BACKUP_SECOND)) { jobType = "3"; exec = new BlogBackupFirstExecutor(); } else { m_traceLogger.info("정의된 작업이 아닙니다.(first | second ), Input : " + job); } try { if (exec != null) { m_traceLogger.info("======================================"); m_traceLogger.info("==== " + args[0] + " job start...."); m_traceLogger.info("======================================"); exec.execute(jobType); m_traceLogger.info("======================================"); m_traceLogger.info("==== " + args[0] + " job end...."); m_traceLogger.info("======================================"); } } catch (Exception e) { m_traceLogger.info(e.getMessage()); e.printStackTrace(); System.exit(1); // 비정상 정료 } System.exit(0); // 정상 종료 }
public void run() { System.out.println("JSSE Server listening on port " + cipherTest.serverPort); Executor exec = Executors.newFixedThreadPool(cipherTest.THREADS, DaemonThreadFactory.INSTANCE); try { while (true) { final SSLSocket socket = (SSLSocket) serverSocket.accept(); socket.setSoTimeout(cipherTest.TIMEOUT); Runnable r = new Runnable() { public void run() { try { InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); handleRequest(in, out); out.flush(); socket.close(); socket.getSession().invalidate(); } catch (IOException e) { cipherTest.setFailed(); e.printStackTrace(); } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { cipherTest.setFailed(); System.out.println("Exception closing socket on server side:"); e.printStackTrace(); } } } } }; exec.execute(r); } } catch (IOException e) { cipherTest.setFailed(); e.printStackTrace(); // } }
private boolean executeInternal( final Executor executor, final StatementExecutorWrapper statementExecutorWrapper, final boolean isExceptionThrown, final Map<String, Object> dataMap) { boolean result; ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorDataMap.setDataMap(dataMap); try { result = executor.execute( statementExecutorWrapper.getStatement(), statementExecutorWrapper.getSqlExecutionUnit().getSql()); } catch (final SQLException ex) { postExecutionEventsAfterExecution( statementExecutorWrapper, EventExecutionType.EXECUTE_FAILURE, Optional.of(ex)); ExecutorExceptionHandler.handleException(ex); return false; } postExecutionEventsAfterExecution(statementExecutorWrapper); return result; }
protected void execute(Runnable runnable) { executor.execute(runnable); }
protected void execute(StackTraceElement[] launchLocation) { this.launchLocation = launchLocation; executor.execute(future()); }
private void execute(String sql) { Executor db = new Executor(this.dataSource); db.execute(sql); }
public static void post(ThreadInteractor t) { executor.execute(t); }
public void handlePacket(ClientPacket packet) { executor.execute(new ClientPacketProcessor(packet)); }
@Override public void run() { executor.execute(runnable); }
/** * @param gridName Grid instance name. Can be {@code null}. * @param exec Executor service. * @param parentLog Parent logger. */ static void runBackgroundCheck(String gridName, Executor exec, GridLogger parentLog) { assert exec != null; assert parentLog != null; final GridLogger log = parentLog.getLogger(GridDiagnostic.class); try { exec.execute( new GridWorker(gridName, "grid-diagnostic-1", log) { @Override public void body() { try { InetAddress localHost = U.getLocalHost(); if (!localHost.isReachable(REACH_TIMEOUT)) { U.warn( log, "Default local host is unreachable. This may lead to delays on " + "grid network operations. Check your OS network setting to correct it.", "Default local host is unreachable."); } } catch (IOException ignore) { U.warn( log, "Failed to perform network diagnostics. It is usually caused by serious " + "network configuration problem. Check your OS network setting to correct it.", "Failed to perform network diagnostics."); } } }); exec.execute( new GridWorker(gridName, "grid-diagnostic-2", log) { @Override public void body() { try { InetAddress localHost = U.getLocalHost(); if (localHost.isLoopbackAddress()) { U.warn( log, "Default local host is a loopback address. This can be a sign of " + "potential network configuration problem.", "Default local host is a loopback address."); } } catch (IOException ignore) { U.warn( log, "Failed to perform network diagnostics. It is usually caused by serious " + "network configuration problem. Check your OS network setting to correct it.", "Failed to perform network diagnostics."); } } }); exec.execute( new GridWorker(gridName, "grid-diagnostic-3", log) { @Override public void body() { String jdkStrLow = U.jdkString().toLowerCase(); if (jdkStrLow.contains("jrockit") && jdkStrLow.contains("1.5.")) { U.warn( log, "BEA JRockit VM ver. 1.5.x has shown problems with NIO functionality in our " + "tests that were not reproducible in other VMs. We recommend using Sun VM. Should you " + "have further questions please contact us at [email protected]", "BEA JRockit VM ver. 1.5.x is not supported."); } } }); exec.execute( new GridWorker(gridName, "grid-diagnostic-4", log) { @Override public void body() { // Sufficiently tested OS. if (!U.isSufficientlyTestedOs()) { U.warn( log, "This operating system has been tested less rigorously: " + U.osString() + ". Our team will appreciate the feedback if you experience any problems running " + "gridgain in this environment. You can always send your feedback to [email protected]", "This OS is tested less rigorously: " + U.osString()); } } }); exec.execute( new GridWorker(gridName, "grid-diagnostic-5", log) { @Override public void body() { // Fix for GG-1075. if (U.allLocalMACs() == null) U.warn( log, "No live network interfaces detected. If IP-multicast discovery is used - " + "make sure to add 127.0.0.1 as a local address.", "No live network interfaces. Add 127.0.0.1 as a local address."); } }); exec.execute( new GridWorker(gridName, "grid-diagnostic-6", log) { @Override public void body() { if (System.getProperty("com.sun.management.jmxremote") != null) { String portStr = System.getProperty("com.sun.management.jmxremote.port"); if (portStr != null) try { Integer.parseInt(portStr); return; } catch (NumberFormatException ignore) { } U.warn( log, "JMX remote management is enabled but JMX port is either not set or invalid. " + "Check system property 'com.sun.management.jmxremote.port' to make sure it specifies " + "valid TCP/IP port.", "JMX remote port is invalid - JMX management is off."); } } }); } catch (RejectedExecutionException e) { U.error( log, "Failed to start background network diagnostics check due to thread pool execution " + "rejection. In most cases it indicates a severe configuration problem with GridGain.", "Failed to start background network diagnostics.", e); } }
public Request execute() { Executor executor = new Executor(); executor.execute(this); return this; }