List of usage examples for java.util.concurrent BlockingQueue add
boolean add(E e);
From source file:com.kurento.kmf.media.PlateDetectorFilterTest.java
@Test public void testEventPlateDetected() throws InterruptedException { final BlockingQueue<PlateDetectedEvent> events = new ArrayBlockingQueue<PlateDetectedEvent>(1); detector.addPlateDetectedListener(new MediaEventListener<PlateDetectedEvent>() { @Override/*w ww . j av a2 s . c o m*/ public void onEvent(PlateDetectedEvent event) { events.add(event); } }); player.connect(detector); player.play(); PlateDetectedEvent event = events.poll(7, SECONDS); Assert.assertNotNull(event); }
From source file:com.kurento.kmf.media.PlayerEndpointTest.java
@Test public void testEventEndOfStream() throws InterruptedException { final BlockingQueue<EndOfStreamEvent> events = new ArrayBlockingQueue<EndOfStreamEvent>(1); player.addEndOfStreamListener(new MediaEventListener<EndOfStreamEvent>() { @Override/* w w w.j av a2 s.c o m*/ public void onEvent(EndOfStreamEvent event) { events.add(event); } }); player.play(); Assert.assertNotNull(events.poll(7, SECONDS)); }
From source file:io.cloudslang.lang.systemtests.TriggerFlows.java
public ScoreEvent runSync(CompilationArtifact compilationArtifact, Map<String, ? extends Serializable> userInputs, Set<SystemProperty> systemProperties) { final BlockingQueue<ScoreEvent> finishEvent = new LinkedBlockingQueue<>(); ScoreEventListener finishListener = new ScoreEventListener() { @Override/*from w w w . j av a 2 s .c o m*/ public synchronized void onEvent(ScoreEvent event) throws InterruptedException { finishEvent.add(event); } }; slang.subscribeOnEvents(finishListener, FINISHED_EVENTS); slang.run(compilationArtifact, userInputs, systemProperties); try { ScoreEvent event = finishEvent.take(); if (event.getEventType().equals(ScoreLangConstants.SLANG_EXECUTION_EXCEPTION)) { LanguageEventData languageEvent = (LanguageEventData) event.getData(); throw new RuntimeException(languageEvent.getException()); } slang.unSubscribeOnEvents(finishListener); return event; } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:com.kurento.kmf.media.HttpGetEndpointAsyncTest.java
/** * Checks that the getUrl method does not return an empty string * //from w ww . j av a 2 s. co m * @throws InterruptedException */ @Test public void testMethodGetUrl() throws InterruptedException { final BlockingQueue<String> events = new ArrayBlockingQueue<String>(1); httpEp.getUrl(new Continuation<String>() { @Override public void onSuccess(String result) { events.add(result); } @Override public void onError(Throwable cause) { throw new KurentoMediaFrameworkException(cause); } }); String url = events.poll(500, MILLISECONDS); Assert.assertTrue(!(url == null || url.isEmpty())); }
From source file:com.kurento.kmf.media.PointerDetectorFilterTest.java
/** * Test if a {@link PointerDetectorFilter} can be created in the KMS. The * filter is pipelined with a {@link PlayerEndpoint}, which feeds video to * the filter. This test depends on the correct behaviour of the player and * its events./*from w w w . j a va 2s . c o m*/ * * @throws InterruptedException */ @Test public void testPointerDetectorFilter() throws InterruptedException { player.connect(filter); filter.addWindow(new PointerDetectorWindowMediaParam("goal", 50, 50, 150, 150)); final BlockingQueue<WindowInEvent> events = new ArrayBlockingQueue<WindowInEvent>(1); filter.addWindowInListener(new MediaEventListener<WindowInEvent>() { @Override public void onEvent(WindowInEvent event) { events.add(event); } }); player.play(); Assert.assertNotNull(events.poll(20, SECONDS)); player.stop(); }
From source file:gridool.taskqueue.sender.SenderResponseTaskQueue.java
@Override public void onResponse(@Nonnull String jobId, @Nonnull GridTaskResult result) { final BlockingQueue<GridTaskResult> queue = queueMap.get(jobId); if (queue != null) { if (LOG.isDebugEnabled()) { LOG.debug("Received a GridTaskResponseMessage for a task: " + result.getTaskId() + " of Job [" + jobId + "] that was executed locally"); }//from w ww . j a v a2 s .c om queue.add(result); } else { LOG.error("SenderResponseQueue is not found for a task: " + result.getTaskId() + " of Job [" + jobId + "] that was executed locally"); } }
From source file:st.happy_camper.flume.twitter.TwitterStreamingConnection.java
/** * @param name/* w ww . j a va2 s.co m*/ * @param password * @param connectionTimeout * @throws IOException */ public TwitterStreamingConnection(String name, String password, int connectionTimeout, String[] trackedKeyword) throws IOException { httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(10 * 1000); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(name, password)); StringBuilder content = new StringBuilder(""); for (String t : trackedKeyword) { content.append(t); content.append(","); } postContent = content.toString(); doOpen(); Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { return new Thread(runnable, "TwitterStreamingConnection"); } }).execute(new Runnable() { @Override public void run() { BlockingQueue<String> queue = TwitterStreamingConnection.this.queue; String line; while ((line = readLine()) != null) { queue.add(line); } } }); }
From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java
private static Stream<WidgetVarLocation> findWidgetVars(Path sourceDirectory, String sourcePattern, ThreadPoolExecutor threadPool) throws IOException { BlockingQueue<WidgetVarLocation> pipe = new LinkedBlockingQueue<>(); List<Future<?>> futures = new ArrayList<>(); Files.walkFileTree(sourceDirectory, new FileActionVisitor(sourceDirectory, sourcePattern, sourceFile -> futures.add(threadPool.submit(() -> { try (BufferedReader br = Files.newBufferedReader(sourceFile, StandardCharsets.UTF_8)) { int lineNr = 0; String line;/*from w ww . ja va2 s .c o m*/ while ((line = br.readLine()) != null) { lineNr++; if (line.contains("widgetVar=\"")) { int startIndex = line.indexOf("widgetVar=\"") + "widgetVar=\"".length(); int endIndex = line.indexOf('"', startIndex); String var = line.substring(startIndex, endIndex); WidgetVarLocation widgetVar = new WidgetVarLocation(var, sourceFile, lineNr, startIndex, line); pipe.add(widgetVar); } } } catch (IOException ex) { throw new RuntimeException(ex); } })))); return StreamSupport.stream(new PipeSpliterator(pipe, futures), true); }
From source file:com.kurento.kmf.media.test.HttpGetEndpointTest.java
/** * Test for {@link MediaSessionTerminatedEvent} * * @throws InterruptedException/*w w w . ja v a2 s . c o m*/ * @throws IOException * @throws ClientProtocolException */ @Test public void testEventMediaSessionTerminated() throws InterruptedException, ClientProtocolException, IOException { final PlayerEndpoint player = pipeline.newPlayerEndpoint(URL_SMALL).build(); HttpGetEndpoint httpEP = pipeline.newHttpGetEndpoint().terminateOnEOS().build(); player.connect(httpEP); httpEP.addMediaSessionStartedListener(new MediaEventListener<MediaSessionStartedEvent>() { @Override public void onEvent(MediaSessionStartedEvent event) { player.play(); } }); final BlockingQueue<MediaSessionTerminatedEvent> events = new ArrayBlockingQueue<>(1); httpEP.addMediaSessionTerminatedListener(new MediaEventListener<MediaSessionTerminatedEvent>() { @Override public void onEvent(MediaSessionTerminatedEvent event) { events.add(event); } }); try (CloseableHttpClient httpclient = HttpClientBuilder.create().build()) { // This should trigger MediaSessionStartedEvent httpclient.execute(new HttpGet(httpEP.getUrl())); } Assert.assertNotNull("MediaSessionTerminatedEvent not sent in 20s", events.poll(20, SECONDS)); httpEP.release(); player.release(); }
From source file:com.kurento.kmf.media.HttpGetEndpointTest.java
/** * Test for {@link MediaSessionStartedEvent} * /*from w ww. j a v a2 s . co m*/ * @throws InterruptedException */ @Test public void testEventMediaSessionStarted() throws InterruptedException { final PlayerEndpoint player = pipeline.newPlayerEndpoint(URL_SMALL).build(); HttpGetEndpoint httpEP = pipeline.newHttpGetEndpoint().build(); player.connect(httpEP); final BlockingQueue<EndOfStreamEvent> eosEvents = new ArrayBlockingQueue<EndOfStreamEvent>(1); player.addEndOfStreamListener(new MediaEventListener<EndOfStreamEvent>() { @Override public void onEvent(EndOfStreamEvent event) { eosEvents.add(event); } }); httpEP.addMediaSessionStartedListener(new MediaEventListener<MediaSessionStartedEvent>() { @Override public void onEvent(MediaSessionStartedEvent event) { player.play(); } }); DefaultHttpClient httpclient = new DefaultHttpClient(); try { // This should trigger MediaSessionStartedEvent httpclient.execute(new HttpGet(httpEP.getUrl())); } catch (ClientProtocolException e) { throw new KurentoMediaFrameworkException(); } catch (IOException e) { throw new KurentoMediaFrameworkException(); } Assert.assertNotNull(eosEvents.poll(7, SECONDS)); httpEP.release(); player.release(); }