public static void main(String[] args) throws InterruptedException { final Runner runner = new Runner(); Thread thread1 = new Thread( () -> { try { runner.firstThread(); } catch (InterruptedException e) { } }); Thread thread2 = new Thread( () -> { try { runner.secondThread(); } catch (InterruptedException e) { } }); thread1.start(); thread2.start(); thread1.join(); thread2.join(); runner.printCount(); }
/** Listens for client requests until stopped. */ public void run() { try { while (listener != null) { try { Socket socket = serverSocket.accept(); if (!paranoid || checkSocket(socket)) { Runner runner = getRunner(); runner.handle(socket); // new Connection (socket); } else socket.close(); } catch (Exception ex) { System.err.println("Exception in XML-RPC listener loop (" + ex + ")."); } catch (Error err) { System.err.println("Error in XML-RPC listener loop (" + err + ")."); } } } catch (Exception exception) { System.err.println("Error accepting XML-RPC connections (" + exception + ")."); } finally { System.err.println("Closing XML-RPC server socket."); try { serverSocket.close(); serverSocket = null; } catch (IOException ignore) { } } }
public static void main(String[] args) throws InterruptedException { final Runner runner = new Runner(); Thread t1 = new Thread( () -> { try { runner.firstThread(); } catch (InterruptedException e) { e.printStackTrace(); } }, "first"); Thread t2 = new Thread( () -> { try { runner.secondThread(); } catch (InterruptedException e) { e.printStackTrace(); } }, "second"); t1.start(); t2.start(); t1.join(); t2.join(); runner.finished(); }
private void doSeveralSteps() throws InterruptedException { stepNumber++; // add your code here - добавь код тут long sleepTime = (long) (1000 / owner.getSpeed()); Thread.sleep(sleepTime); System.out.println(owner.getName() + " делает шаг №" + stepNumber + "!"); }
/** Gets the snapshot of {@link SCMedItem}s that are being polled at this very moment. */ public List<SCMedItem> getItemsBeingPolled() { List<SCMedItem> r = new ArrayList<SCMedItem>(); for (Runner i : getRunners()) { r.add(i.getTarget()); } return r; }
public static void main(String[] args) throws Exception { final Runner runner = new Runner(); Thread t1 = new Thread( new Runnable() { public void run() { try { runner.firstThread(); } catch (InterruptedException ignored) { } } }); Thread t2 = new Thread( new Runnable() { public void run() { try { runner.secondThread(); } catch (InterruptedException ignored) { } } }); t1.start(); t2.start(); t1.join(); t2.join(); runner.finished(); }
@Override public void update(GameContainer container, int arg1) throws SlickException { input = container.getInput(); if (input.isKeyPressed(Input.KEY_ENTER)) { GameStart = true; } if (!player.GameOver && GameStart) { invul_frame -= 1; trap.update(v); for (int x = 0; x < 4; x++) { for (int y = 0; y < 3; y++) { walls[x][y].update(v); } } input = container.getInput(); player.update(); if (input.isKeyPressed(Input.KEY_SPACE)) { player.jump(); } if (isCollide(player, trap, invul_frame)) { player.HIT(); ; invul_frame = 30; } if (trap.getX() <= -100) { randomTrap(); } } input = container.getInput(); if (player.GameOver && input.isKeyPressed(Input.KEY_R)) { GameStart = false; container.reinit(); } }
private void doSeveralSteps() throws InterruptedException { stepNumber++; // add your code here - добавь код тут System.out.println(owner.getName() + " делает шаг №" + stepNumber + "!"); long timerDream = 1000; this.sleep(timerDream / (long) owner.getSpeed()); }
public static void testSimpleEpsilon(Automate aut) { Utilities.pass("EMPTY", Runner.accept(aut, ""), false); Utilities.pass("011", Runner.accept(aut, "011"), true); Utilities.pass("100", Runner.accept(aut, "100"), true); Utilities.pass("0111", Runner.accept(aut, "0111"), false); Utilities.pass("0", Runner.accept(aut, "0"), false); }
public static void testSimple1(Automate aut) { Utilities.pass("abc", Runner.accept(aut, "abc"), true); Utilities.pass("a", Runner.accept(aut, "a"), false); Utilities.pass("dba", Runner.accept(aut, "dba"), false); Utilities.pass("adc", Runner.accept(aut, "adc"), false); Utilities.pass("ab", Runner.accept(aut, "ab"), false); }
@GET @Path("logs/{runner:.*}/{id}") public void getLogs( @PathParam("runner") String runner, @PathParam("id") Long id, @Context HttpServletResponse httpServletResponse) throws Exception { final Runner myRunner = getRunner(runner); final RunnerProcess process = myRunner.getProcess(id); final Throwable error = process.getError(); if (error != null) { final PrintWriter output = httpServletResponse.getWriter(); httpServletResponse.setContentType("text/plain"); if (error instanceof RunnerException) { // expect ot have nice messages from our API output.write(error.getMessage()); } else { error.printStackTrace(output); } output.flush(); } else { final ApplicationLogger logger = process.getLogger(); final PrintWriter output = httpServletResponse.getWriter(); httpServletResponse.setContentType(logger.getContentType()); logger.getLogs(output); output.flush(); } }
public static void main(String[] args) { Runner runner1 = new Runner(); runner1.start(); Runner runner2 = new Runner(); runner2.start(); }
public static void main(String[] args) { // TODO Auto-generated method stub Runner runner1 = new Runner(1); runner1.start(); Runner runner2 = new Runner(2); runner2.start(); }
public Runner getRunnerByNumber(int n) { for (Runner r : runners) { if (r.getNumber() == n) { return r; } } return null; }
/** Test regular operation, including command line parameter parsing. */ @Test(timeout = 60000) // timeout after a minute. public void testDetachedMode() { LOG.info("Starting testDetachedMode()"); addTestAppender(FlinkYarnSessionCli.class, Level.INFO); Runner runner = startWithArgs( new String[] { "-j", flinkUberjar.getAbsolutePath(), "-t", flinkLibFolder.getAbsolutePath(), "-n", "1", "-jm", "768", "-tm", "1024", "--name", "MyCustomName", // test setting a custom name "--detached" }, "Flink JobManager is now running on", RunTypes.YARN_SESSION); checkForLogString("The Flink YARN client has been started in detached mode"); Assert.assertFalse("The runner should detach.", runner.isAlive()); LOG.info("Waiting until two containers are running"); // wait until two containers are running while (getRunningContainers() < 2) { sleep(500); } LOG.info("Two containers are running. Killing the application"); // kill application "externally". try { YarnClient yc = YarnClient.createYarnClient(); yc.init(yarnConfiguration); yc.start(); List<ApplicationReport> apps = yc.getApplications(EnumSet.of(YarnApplicationState.RUNNING)); Assert.assertEquals(1, apps.size()); // Only one running ApplicationReport app = apps.get(0); Assert.assertEquals("MyCustomName", app.getName()); ApplicationId id = app.getApplicationId(); yc.killApplication(id); while (yc.getApplications(EnumSet.of(YarnApplicationState.KILLED)).size() == 0) { sleep(500); } } catch (Throwable t) { LOG.warn("Killing failed", t); Assert.fail(); } LOG.info("Finished testDetachedMode()"); }
@Before public void setup() { HttpsServer server = httpsServer(port(), certificate(pathResource("cert.jks"), "mocohttps", "mocohttps")); server.response("foo"); this.runner = Runner.runner(server); runner.start(); helper = new MocoTestHelper(); }
@GET @Path("status/{runner:.*}/{id}") @Produces(MediaType.APPLICATION_JSON) public ApplicationProcessDescriptor getStatus( @PathParam("runner") String runner, @PathParam("id") Long id) throws Exception { final Runner myRunner = getRunner(runner); final RunnerProcess process = myRunner.getProcess(id); return getDescriptor(process, getServiceContext()).withRunStats(myRunner.getStats(id)); }
private Runner getRunner(String path) { Runner runner = runnerRepository.findOneByPath(path); if (runner == null) { runner = new Runner(); runner.setPath(path); return runnerRepository.save(runner); } return runner; }
public static void main(String[] args) throws InterruptedException { Runner ivanov = new Runner("Ivanov", 4); Runner petrov = new Runner("Petrov", 2); ivanov.start(); petrov.start(); Thread.sleep(2000); isStopped = true; Thread.sleep(1000); }
public void testRun() { Runner app = new Export(); app.setParams(new String[] {"export", "export.csv", "csv", "select * from t_column_group"}); try { app.run(); } catch (RunnerException e) { fail(e.getMessage()); } catch (ParamException e) { fail(e.getMessage()); } }
public boolean isCollide(Runner player, BasicTrap trap, float invul) throws SlickException { float deltaX = (player.getSizeX() + trap.getSizeX()) / 2; float deltaY = (player.getSizeY() + trap.getSizeY()) / 2; if (Math.abs(player.getX() - trap.getX()) <= deltaX && Math.abs(player.getY() - trap.getY()) <= deltaY && invul <= 0) { return true; } return false; }
public synchronized void enqueue(Task task) { queue.add(task); if (runner == null) { runnerRunning = true; runner = new Runner(this); runner.setDaemon(true); runner.start(); } else if (!runnerRunning) { runnerRunning = true; notifyAll(); } }
@GenerateLink(rel = Constants.LINK_REL_RUN) @Path("run") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ApplicationProcessDescriptor run( @Description("Parameters for run task in JSON format") RunRequest request) throws Exception { final Runner myRunner = getRunner(request.getRunner()); final RunnerProcess process = myRunner.execute(request); return getDescriptor(process, getServiceContext()) .withRunStats(myRunner.getStats(process.getId())); }
/** * Calls interrupt() on each of the running threads. * * @throws IllegalThreadStateException if threads were not started */ public synchronized void interrupt() { if (!started) throw new IllegalThreadStateException(getClass().getSimpleName() + " not started !"); for (Runner t : runners) { try { t.interrupt(); } catch (IllegalThreadStateException ex) { // t might have finished its execution ex.printStackTrace(); } } }
/** * Starts all the threads. * * @throws IllegalThreadStateException if the threads were already started. * @throws NoSuchElementException if no runnable were added to this Threads instance. */ public synchronized void start() { if (started) throw new IllegalThreadStateException(getClass().getSimpleName() + " already started !"); if (runners.isEmpty()) throw new NoSuchElementException( "No runnable were added to this " + getClass().getSimpleName()); for (Runner t : runners) { t.start(); } started = true; }
/** Do not use. Testing purposes only. */ public Result run(Runner runner) { Result result = new Result(); RunListener listener = result.createListener(); fNotifier.addFirstListener(listener); try { fNotifier.fireTestRunStarted(runner.getDescription()); runner.run(fNotifier); fNotifier.fireTestRunFinished(result); } finally { removeListener(listener); } return result; }
@GenerateLink(rel = Constants.LINK_REL_RUNNER_STATE) @GET @Path("state") @Produces(MediaType.APPLICATION_JSON) public RunnerState getRunnerState( @Required @Description("Name of the runner") @QueryParam("runner") String runner) throws Exception { final Runner myRunner = getRunner(runner); return DtoFactory.getInstance() .createDto(RunnerState.class) .withName(myRunner.getName()) .withStats(myRunner.getStats()) .withServerState(getServerState()); }
static long doTest(int id, String name, final Map<String, String> m, final String[] key) { // System.out.print(name + "\t"); Runner runner = new Runner(id, m, key); long startTime = System.currentTimeMillis(); runner.run(); long afterRun = System.currentTimeMillis(); long runTime = (afterRun - startTime); int np = runner.total; if (runner.total == runner.hashCode()) System.out.println("Useless Number" + runner.total); int sz = runner.maxsz; if (sz == runner.hashCode()) System.out.println("Useless Number" + sz); // System.out.print(" m = " + sz); return runTime; }
private Result run(Runner runner) throws InitializationError { RunNotifier notifier = new RunNotifier(); Result result = new Result(); notifier.addListener(result.createListener()); runner.run(notifier); return result; }
/** * @param browser * @param url */ public void initializeSelenium(String browser, String url) throws SAFSException { String id = getUniqueDriverID(); try { WDLibrary.startBrowser(browser, url, id, BROWSER_TIMEOUT, USE_REMOTE, BROWSER_PARMS); } catch (Throwable th) { String thmsg = "WDSPC initial session start() error: " + th.getMessage(); if (USE_REMOTE) { Log.info("WDSPC attempting to (re)start RemoteServer."); // if(WebDriverGUIUtilities.startRemoteServer()){ if (WebDriverGUIUtilities.startRemoteServer( Runner.driver().iDriver().getProjectRootDir())) { try { WDLibrary.startBrowser(browser, url, id, BROWSER_TIMEOUT, USE_REMOTE, BROWSER_PARMS); } catch (Throwable th2) { thmsg = "WDSPC second session start() error:" + th2.getMessage(); System.err.println(thmsg); Log.error(thmsg); throw new SAFSException(thmsg); } } } else { System.err.println(thmsg); Log.error(thmsg); throw new SAFSException(thmsg); } } Log.debug("Initialized browser: " + browser + " with ID: " + id); selenium = WDLibrary.getBrowserWithID(id); spcGUI.updateWindows(getWindows()); }