@Override public PeerItem onQueryEvaluator(PeerItem evaluator) throws Exception { // Here you should throw an exception, if the selected QueryEvaluator is not // allowed, because wrong network or different distribution strategy ... if (evaluator.queryEvaluator == null) throw new NullPointerException("Evaluator is not existing anymore."); if (!evaluator.networkName.equals(NETWORK)) { throw new IllegalArgumentException("Only same P2P network can be used."); } if (!evaluator.distributionStrategy.equals(DISTRIBUTION.toString())) { throw new IllegalArgumentException("Only same distribution strategy can be used."); } if (evaluator.useSubgraphSubmission != withSubgraphSubmission) { QueryClient evalInstance = evaluator.queryEvaluator; /* * try to change the submission type, if special instance */ if (evalInstance instanceof P2P_SG_QueryClient_WithSubgraph) { // update the queryclient and the table row evaluator.useSubgraphSubmission = withSubgraphSubmission; ((P2P_SG_QueryClient_WithSubgraph) evalInstance) .setUseSubgraphSubmission(withSubgraphSubmission); } else throw new IllegalArgumentException( "Evaluator does not support changing the behavior of sending subgraphs"); } return evaluator; }
/** * Creates a new instance of a query client * * @return a new instance * @param args an array of {@link java.lang.String} objects. */ @SuppressWarnings({"rawtypes", "unchecked"}) public static QueryClient newInstance(String[] args) { try { /*set literalfactory */ Bindings.instanceClass = BindingsMap.class; LiteralFactory.setType(MapType.NOCODEMAP); LiteralFactory.setTypeWithoutInitializing(MapType.NOCODEMAP); final int instance = instanceCounter.incrementAndGet(); if (bindings != null) Bindings.instanceClass = bindings; BindingsFactory bf = BindingsFactory.createBindingsFactory(); String debugString = "\n"; debugString += (String.format("Creating new P2P query client instance: %d \n", instance)); AbstractP2PNetwork p2pInstance = networkInstance != null ? networkInstance : getP2PNetworkImplementation(); if (networkInstance == null) { debugString += (String.format( "P2P network: %s \nP2P configuration: %s \nP2P instance: %s \nhas local storage %s \n", p2pImplementationConstant, (p2pImplementationConfiguration != null) ? getP2PConfig(p2pImplementationConfiguration) : "{}", p2pInstance, p2pInstance.hasLocalStorage())); } else { debugString += (String.format( "P2P network: %s \nP2P instance: %s \nhas local storage: %s \n", p2pInstance.getClass(), p2pInstance, p2pInstance.hasLocalStorage())); } IDistribution distribution = getDistribution(); debugString += (String.format( "DistributionStrategy: %s [%s] \n", distribution, distribution.getClass())); P2P_SubgraphExecuter sgExecuter = new P2P_SubgraphExecuter() { @Override public String toString() { return String.format( "SubgraphExecuter for query client instance %s on node: %s \n", instance, p2p); } }; StorageWithDistributionStrategy storageInstance = invoke(storageClass.getName(), p2pInstance, distribution, bf); if (storageConfiguration != null) { storageConfiguration.doConfiguration(storageInstance); debugString += (String.format( "Storage: %s [%s] with manual configuration: %s \n", storageInstance, storageInstance.getClass(), storageConfiguration)); } else { debugString += (String.format("Storage: %s [%s] \n", storageInstance, storageInstance.getClass())); } P2P_SG_QueryClient_WithSubgraph queryClientInstance = new P2P_SG_QueryClient_WithSubgraph(storageInstance, sgExecuter) { @Override public String toString() { return String.format("QueryClient [%s]", instance); } }; if (useSubgraphSubmission) debugString += (String.format("Query Client: %s with subgraph submission \n", queryClientInstance)); else debugString += (String.format("Query Client: %s without subgraph submission \n", queryClientInstance)); queryClientInstance.setUseSubgraphSubmission(useSubgraphSubmission); /* * if a local storage is supported, use this for subgraph executer */ IStorage localStorage = (p2pInstance.hasLocalStorage()) ? p2pInstance.getLocalStorage(distribution) : storageInstance; sgExecuter.setStorage(localStorage); sgExecuter.setP2PNetwork(p2pInstance); /* * create an query evaluator for the local storage, which is evaluated in local storage */ QueryEvaluator localEvaluator = new QueryClientWithSubgraphTransmission(localStorage, distribution, sgExecuter) { @Override public String toString() { return "LocalQueryExecuter for instance " + instance; } }; Collection<URILiteral> defaultGraphs = new LinkedList<URILiteral>(); // init with empty dataset ... LiteralFactory.setType(MapType.NOCODEMAP); defaultGraphs.add(LiteralFactory.createURILiteralWithoutLazyLiteral("<inlinedata:>")); Collection<URILiteral> namedGraphs = new LinkedList<URILiteral>(); localEvaluator.prepareInputData(defaultGraphs, namedGraphs); queryClientInstance.prepareInputData(defaultGraphs, namedGraphs); try { PhysicalOptimizations.memoryReplacements(); } catch (Exception e) { // ignore } // connect local storage evaluater in subgraph executer sgExecuter.setEvaluator(localEvaluator); log.info(debugString); return queryClientInstance; } catch (Exception e) { throw new RuntimeException("Cannot instanciate class:" + e.getMessage()); } }