List of usage examples for org.springframework.integration.channel RendezvousChannel receive
@Override @Nullable public Message<?> receive(long timeout)
From source file:com.seajas.search.profiler.service.testing.TestingService.java
/** * Dispatch a type-specified modifier test request and wait for the result. * /*from w ww . j a v a 2 s . c o m*/ * @param testFeed * @param type * @return Map<String, Boolean> * @throws TestingException */ @SuppressWarnings("unchecked") private TestResult testModifier(final TestElement testFeed, final TestType type) throws TestingException { final UUID sessionUUID = UUID.randomUUID(); final RendezvousChannel temporaryChannel = new RendezvousChannel(); final MessageHandler messageHandler = new MessageHandler() { @Override public void handleMessage(final Message<?> message) { String messageUUID = message.getHeaders().get(MessageConstants.HEADER_RENDEZVOUS_UUID, String.class); if (sessionUUID.toString().equals(messageUUID)) temporaryChannel.send(message); } }; testingChannel.subscribe(messageHandler); try { injectionService.inject(testFeed, GroupIdDecorator.decorate(testFeed.getTestingUri().getHost()), type.name(), sessionUUID.toString()); // Now wait for read out the rendezvous-channel until we receive the response Message<TestResult> message = (Message<TestResult>) temporaryChannel.receive(receiveTimeout); if (message != null) return message.getPayload(); throw new TestingException("Receiving the testing response failed or timed out"); } finally { testingChannel.unsubscribe(messageHandler); } }
From source file:com.seajas.search.profiler.service.testing.TestingService.java
/** * Dispatch a feed-testing request, where the result is evaluated on the contender-side to be of type RSS - directly or indirectly. * /*from w w w . j a v a 2 s . c o m*/ * <ul> * <li>When a TestingException is thrown, something went wrong or no URLs could be found</li> * <li>When one entry with a boolean value of 'true' is returned, the URL concerns a direct RSS feed</li> * <li>When one or more entry with a boolean value of 'false' is returned, the URL concerns an indirect RSS feed with one or more links</li> * </ul> * * @param uri * @return TestResult * @throws TestingException */ @SuppressWarnings("unchecked") public Map<String, Boolean> exploreUri(final URI uri) throws TestingException { final UUID sessionUUID = UUID.randomUUID(); final RendezvousChannel temporaryChannel = new RendezvousChannel(); final MessageHandler messageHandler = new MessageHandler() { @Override public void handleMessage(final Message<?> message) { String messageUUID = message.getHeaders().get(MessageConstants.HEADER_RENDEZVOUS_UUID, String.class); if (sessionUUID.toString().equals(messageUUID)) temporaryChannel.send(message); } }; testingChannel.subscribe(messageHandler); try { TestElement testElement = new TestElementImpl(uri, null, null, null, null); if (logger.isInfoEnabled()) logger.info("Injecting element with exploration URI '" + uri + "'"); injectionService.inject(testElement, GroupIdDecorator.decorate(uri.getHost()), TestType.EXPLORE.name(), sessionUUID.toString()); // Now wait for read out the rendezvous-channel until we receive the response Message<TestResult> message = (Message<TestResult>) temporaryChannel.receive(receiveTimeout); if (message != null) { TestResult result = message.getPayload(); if (!result.isSuccess()) throw new TestingException( "No feeds - direct or indirect - were retrieved: " + result.getStatusMessage()); else return result.getResult(); } throw new TestingException("Test response aborted by timeout or interrupt."); } finally { testingChannel.unsubscribe(messageHandler); } }