/** * Asynchronously submit a request to the supplied source. This is typically called when the forked requests are not needed * before continuing. * * @param request the request to be submitted; may not be null * @param sourceName the name of the source; may not be null * @see #submitAndAwait(Request, String) * @see #submit(Request, String, CountDownLatch) */ protected void submit( Request request, String sourceName ) { assert request != null; CompositeRequestChannel channel = channelBySourceName.get(sourceName); if (channel == null) { channel = new CompositeRequestChannel(sourceName); channelBySourceName.put(sourceName, channel); channel.start(executor, getExecutionContext(), connectionFactory); } channel.add(request); }
/** * Submit a request to the supplied source, and block until the request has been processed. This method is typically used when * a federated request is forked into multiple source-specific requests, but the output of a source-specific request is * required before forking other source-specific requests. This pattern is common in requests that update one source and any * information not stored by that source needs to be stored in another source. * * @param request the request to be submitted; may not be null * @param sourceName the name of the source; may not be null * @throws InterruptedException if the current thread is interrupted while waiting * @see #submit(Request, String) * @see #submit(Request, String, CountDownLatch) */ protected void submitAndAwait( Request request, String sourceName ) throws InterruptedException { assert request != null; CompositeRequestChannel channel = channelBySourceName.get(sourceName); if (channel == null) { channel = new CompositeRequestChannel(sourceName); channelBySourceName.put(sourceName, channel); channel.start(executor, getExecutionContext(), connectionFactory); } channel.addAndAwait(request); }
/** * Submit a request to the supplied source, and have the supplied {@link CountDownLatch latch} be * {@link CountDownLatch#countDown() decremented} when the request has been completed. Note that the same latch can be used * multiple times. * <p> * This method is typically used when a federated request is forked into multiple source-specific requests, but the output of * a source-specific request is required before forking other source-specific requests. This pattern is common in requests * that update one source and any information not stored by that source needs to be stored in another source. * </p> * * @param request the request to be submitted; may not be null * @param sourceName the name of the source; may not be null * @param latch the count-down latch; may not be null * @see #submit(Request, String) * @see #submitAndAwait(Request, String) */ protected void submit( Request request, String sourceName, CountDownLatch latch ) { assert request != null; CompositeRequestChannel channel = channelBySourceName.get(sourceName); if (channel == null) { channel = new CompositeRequestChannel(sourceName); channelBySourceName.put(sourceName, channel); channel.start(executor, getExecutionContext(), connectionFactory); } channel.add(request, latch); }
@Before public void beforeEach() { MockitoAnnotations.initMocks(this); context = new ExecutionContext(); sourceName = "SourceA"; channel = new CompositeRequestChannel(sourceName); requests = new ArrayList<Request>(); requests.add(new MockRequest()); requests.add(new MockRequest()); requests.add(new MockRequest()); requests.add(new MockRequest()); // Create the mock connection ... executedRequests = new LinkedList<Request>(); // this is where requests submitted to the connection will go connection = new MockRepositoryConnection(sourceName, executedRequests); // Stub the connection factory ... when(connectionFactory.createConnection(sourceName)).thenReturn(connection); // Create the executor ... executor = Executors.newSingleThreadExecutor(); }
this.sourceName = searchEngine.getSourceName(); this.connectionFactory = connectionFactory; this.channel = new CompositeRequestChannel(this.sourceName, false, true); this.service = Executors.newSingleThreadExecutor(new NamedThreadFactory("search-" + sourceName));
channel = new CompositeRequestChannel(delegate().getName()); channel.start(executorService, context, connectionFactory);