Examples of CountDownLatch


Examples of java.util.concurrent.CountDownLatch

    }

    private static void refreshProjectsBlocking(GradlePluginLord gradlePluginLord, final ExecuteGradleCommandServerProtocol.ExecutionInteraction executionInteraction, int maximumWaitValue, TimeUnit maximumWaitUnits) {
        gradlePluginLord.startExecutionQueue();   //make sure its started

        final CountDownLatch complete = new CountDownLatch(1);

        GradlePluginLord.RequestObserver observer = new GradlePluginLord.RequestObserver() {
           public void executionRequestAdded( ExecutionRequest request ) {}
           public void refreshRequestAdded( RefreshTaskListRequest request )
           {
              request.setExecutionInteraction( executionInteraction );
           }
           public void aboutToExecuteRequest( Request request ) { }

           public void requestExecutionComplete( Request request, int result, String output ) {
               complete.countDown();
           }
        };

        gradlePluginLord.addRequestObserver( observer, false );   //add the observer before we add the request due to timing issues. It's possible for it to completely execute before we return from addRefreshRequestToQueue.
        Request request = gradlePluginLord.addRefreshRequestToQueue();

        //make sure we've got a request
        Assert.assertNotNull(request);

        //now wait until we're complete, but bail if we wait too long
        boolean completed;
        try {
            completed = complete.await(maximumWaitValue, maximumWaitUnits);
        } catch (InterruptedException e) {
            throw UncheckedException.asUncheckedException(e);
        }

        gradlePluginLord.removeRequestObserver( observer );
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    // Failing test for https://github.com/joewalnes/webbit/issues/29
    @Test
    @Ignore
    public void stopsServerCleanlyAlsoWhenClientsAreConnected() throws Exception {
        final CountDownLatch stopper = new CountDownLatch(1);
        final WebServer server = new NettyWebServer(Executors.newSingleThreadScheduledExecutor(), 9080).start();
        server.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                System.out.println("We got here");
                server.stop().join();
                System.out.println("But never here");
                stopper.countDown();
            }
        });
        Socket client = new Socket(InetAddress.getLocalHost(), 9080);
        OutputStream http = client.getOutputStream();
        http.write(("" +
                "GET /index.html HTTP/1.1\r\n" +
                "Host: www.example.com\r\n\r\n").getBytes("UTF-8"));
        http.flush();

        assertTrue("Server should have stopped by now", stopper.await(1000, TimeUnit.MILLISECONDS));
    }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

      /*
       * Go to sleep and wait for entry to become available.
       */
      try {
        if (resultAvailabilitySignal == null) {
          resultAvailabilitySignal = new CountDownLatch(1);
        }
        resultAvailabilitySignal.await();
       
        return getResult();
      } catch (InterruptedException e) {
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

  }

  private void parse(StreamSource source, String baseURI)
    throws IOException, RDFParseException, RDFHandlerException
  {
    CountDownLatch latch = new CountDownLatch(1);
    PipedInputStream pipe = new PipedInputStream();
    PipedOutputStream out = new PipedOutputStream(pipe);

    try {
      parse(pipe, baseURI, latch);
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

     */
    public Command(CommandType type, CommandOutput<T> output, CommandArgs args) {
        this.type   = type;
        this.output = output;
        this.args   = args;
        this.latch  = new CountDownLatch(1);
    }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        QueryModel query)
    {
      this.executor = executor;
      this.members = members;
      int count = new PatternCounter(query).count();
      this.latch = new CountDownLatch(count * members.size());
      query.visit(this);
    }
 
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    resultCount = verifyQueryResult(iter, 1);
    assertEquals("Wrong number of query results", 2, resultCount);
  }

  public void testMultiThreadedAccess() {
    final CountDownLatch latch = new CountDownLatch(1);

    Runnable runnable = new Runnable() {

      SailConnection sharedCon = con;

      public void run() {
        assertTrue(sharedCon != null);

        try {
          latch.countDown();
          latch.await();
          sharedCon.addStatement(painter, RDF.TYPE, RDFS.CLASS);

          // wait a bit to allow other thread to add stuff as well.
          Thread.sleep(500L);
          Cursor<? extends Statement> result = sharedCon.getStatements(null, null, null, true);

          int numberOfStatements = 0;
          Statement st;
          while ((st = result.next()) != null) {
            numberOfStatements++;
            assertTrue(st.getSubject().equals(painter) || st.getSubject().equals(picasso));
            assertTrue(st.getPredicate().equals(RDF.TYPE));
            assertTrue(st.getObject().equals(RDFS.CLASS) || st.getObject().equals(painter));
          }
          assertTrue("we should have retrieved statements from both threads", numberOfStatements == 2);

        }
        catch (StoreException e) {
          e.printStackTrace();
          fail(e.getMessage());
        }
        catch (InterruptedException e) {
          fail(e.getMessage());
        }

        // let this thread sleep so the other thread can invoke close()
        // first.
        try {
          Thread.sleep(1000L);

          // the connection should now be closed (by the other thread),
          // invoking any further operation should cause a
          // IllegalStateException
          sharedCon.getStatements(null, null, null, true);
          fail("expected a ConnectionClosedException");
        }
        catch (ConnectionClosedException e) {
          // do nothing, this is the expected behaviour
        }
        catch (Exception e) {
          e.printStackTrace();
          fail("expected a ConnectionClosedException");
        }
      }
    }; // end anonymous class declaration

    // execute the other thread
    Thread newThread = new Thread(runnable, "B (parallel)");
    newThread.start();

    try {
      latch.countDown();
      latch.await();
      con.addStatement(picasso, RDF.TYPE, painter);
      // let this thread sleep to enable other thread to finish its business.
      Thread.sleep(1000L);
      con.close();
    }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

     * a convenient way of keeping the main thread alive whilst gstreamer
     * processing on other threads continues.
     */
    public static void main() {
        try {
            CountDownLatch latch = quit;
            if (latch != null) {
                latch.await();
            }
        } catch (InterruptedException ex) {
        } finally {
            quit = new CountDownLatch(1);
        }
    }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

            executorService = new MainContextExecutorService(mainContext);
        } else {
            mainContext = new GMainContext();
            executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
        }
        quit = new CountDownLatch(1);
        return argv.toStringArray();
    }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

* A simple pipeline, demonstrating media tag detection
*/
public class TagFinder {
    private static final String progname = "TagFinder";
    public static void main(String[] args) {
        final CountDownLatch done = new CountDownLatch(1);
       
        //
        // Initialize the gstreamer framework, and let it interpret any command
        // line flags it is interested in.
        //
        args = Gst.init(progname, args);
       
        if (args.length < 0) {
            System.out.println("Usage: " + progname + " <filename>");
            System.exit(1);
        }
        //
        // Instead of using a playbin, it would be possible to use a pipe
        // a typefind element and a demux and wire them up manually.
        //
        final PlayBin2 pipe = new PlayBin2(progname);
        pipe.setInputFile(new File(args[0]));
        FakeSink audio = (FakeSink) ElementFactory.make("fakesink", "audio-sink");
        FakeSink video = (FakeSink) ElementFactory.make("fakesink", "video-sink");
        pipe.setAudioSink(audio);
        pipe.setVideoSink(video);
       
        pipe.getBus().connect(new Bus.TAG() {
            public void tagsFound(GstObject source, TagList tagList) {
                for (String tag : tagList.getTagNames()) {
                    System.out.println("Found tag " + tag + " = "
                            + tagList.getValue(tag, 0));
                }
            }
        });
       
        //
        // In theory, an ASYNC_DONE from the pipeline corresponds with the demux
        // completing parsing the media file
        //
        pipe.getBus().connect(new Bus.ASYNC_DONE() {
            public void asyncDone(GstObject source) {
                pipe.stop();
                done.countDown();
            }
        });
        audio.set("signal-handoffs", true);
        video.set("signal-handoffs", true);
       
        //
        // As soon as data starts to flow, it means all tags have been found
        //
        BaseSink.HANDOFF handoff = new BaseSink.HANDOFF() {
            public void handoff(BaseSink sink, Buffer buffer, Pad pad) {
                pipe.stop();
                done.countDown();
            }
        };
        audio.connect(handoff);
        video.connect(handoff);
       
        // Start the pipeline playing
        pipe.pause();
        try {
            done.await();
        } catch (InterruptedException ex) {
        }
        pipe.stop();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.