Repository: incubator-blur Updated Branches: refs/heads/master da069f03d -> 89e415622
Fixing ShardCommandManager to work changed made to the command interface types. IndexReadCombiningCommand no longer inherits from IndexReadCommand. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/89e41562 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/89e41562 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/89e41562 Branch: refs/heads/master Commit: 89e415622f1d1807664fef9ed2d4300126d3835b Parents: da069f0 Author: Aaron McCurry <[email protected]> Authored: Fri Aug 29 07:50:34 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Fri Aug 29 07:50:34 2014 -0400 ---------------------------------------------------------------------- .../manager/command/ShardCommandManager.java | 55 +++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/89e41562/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java b/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java index 5586a44..573fde9 100644 --- a/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java @@ -46,7 +46,7 @@ public class ShardCommandManager extends BaseCommandManager { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } - if (command instanceof IndexReadCommand) { + if (command instanceof IndexReadCommand || command instanceof IndexReadCombiningCommand) { return toResponse(executeReadCommand(command, tableContext, args), command); } else if (command instanceof IndexWriteCommand) { return toResponse(executeReadWriteCommand((IndexWriteCommand<?>) command, tableContext, args), command); @@ -76,18 +76,17 @@ public class ShardCommandManager extends BaseCommandManager { String shardId = e.getKey(); final Shard shard = new Shard(shardId); final BlurIndex blurIndex = e.getValue(); - final IndexReadCommand<?> readCommand = (IndexReadCommand<?>) command.clone(); - Future<Object> future = _executorService.submit(new Callable<Object>() { - @Override - public Object call() throws Exception { - IndexSearcherClosable searcher = blurIndex.getIndexSearcher(); - try { - return readCommand.execute(new ShardIndexContext(tableContext, shard, searcher, args)); - } finally { - searcher.close(); - } - } - }); + Callable<Object> callable; + if (command instanceof IndexReadCommand) { + final IndexReadCommand<?> readCommand = (IndexReadCommand<?>) command.clone(); + callable = getCallable(tableContext, args, shard, blurIndex, readCommand); + } else if (command instanceof IndexReadCombiningCommand) { + final IndexReadCombiningCommand<?, ?> readCombiningCommand = (IndexReadCombiningCommand<?, ?>) command.clone(); + callable = getCallable(tableContext, args, shard, blurIndex, readCombiningCommand); + } else { + throw new IOException("Command type of [" + command.getClass() + "] not supported."); + } + Future<Object> future = _executorService.submit(callable); futureMap.put(shardId, future); } Map<Shard, Object> resultMap = new HashMap<Shard, Object>(); @@ -106,6 +105,36 @@ public class ShardCommandManager extends BaseCommandManager { return resultMap; } + private Callable<Object> getCallable(final TableContext tableContext, final Args args, final Shard shard, + final BlurIndex blurIndex, final IndexReadCombiningCommand<?, ?> readCombiningCommand) { + return new Callable<Object>() { + @Override + public Object call() throws Exception { + IndexSearcherClosable searcher = blurIndex.getIndexSearcher(); + try { + return readCombiningCommand.execute(new ShardIndexContext(tableContext, shard, searcher, args)); + } finally { + searcher.close(); + } + } + }; + } + + private Callable<Object> getCallable(final TableContext tableContext, final Args args, final Shard shard, + final BlurIndex blurIndex, final IndexReadCommand<?> readCommand) { + return new Callable<Object>() { + @Override + public Object call() throws Exception { + IndexSearcherClosable searcher = blurIndex.getIndexSearcher(); + try { + return readCommand.execute(new ShardIndexContext(tableContext, shard, searcher, args)); + } finally { + searcher.close(); + } + } + }; + } + static class ShardIndexContext extends IndexContext { private final TableContext _tableContext;
