@Override public PeerItem onMasterInstance(int localPort, int masterPort, String masterAddress) { // store information PeerItem item = new PeerItem(); item.networkName = NETWORK; item.isMaster = false; item.masterName = masterAddress; item.masterPort = masterPort; item.distributionStrategy = DISTRIBUTION.toString(); item.port = localPort; item.useSubgraphSubmission = withSubgraphSubmission; // set ports and master Map<String, Object> cfg = P2P_QueryClient_Instanciator.getP2PImplementationConfiguration(); cfg.put(P2PNetworkCreator.P2PConfigurationConstants.cPORT, localPort); cfg.put(P2PNetworkCreator.P2PConfigurationConstants.cMASTER_IP, masterAddress); cfg.put(P2PNetworkCreator.P2PConfigurationConstants.cMASTER_PORT, masterPort); P2P_QueryClient_Instanciator.setP2PImplementationConfiguration(cfg); P2P_QueryClient_Instanciator.setSubgraphSubmission(withSubgraphSubmission); // create instance and store instance QueryClient qC = createInstance(); item.queryEvaluator = qC; return item; }
@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; }
@Override public PeerItem onLocalInstance(int localPort) { /* * store information */ PeerItem item = new PeerItem(); item.networkName = NETWORK; item.isMaster = true; item.distributionStrategy = DISTRIBUTION.toString(); item.port = localPort; item.useSubgraphSubmission = withSubgraphSubmission; /* * store configuration */ Map<String, Object> cfg = P2P_QueryClient_Instanciator.getP2PImplementationConfiguration(); cfg.put(P2PNetworkCreator.P2PConfigurationConstants.cPORT, localPort); cfg.remove(P2PNetworkCreator.P2PConfigurationConstants.cMASTER_IP); cfg.remove(P2PNetworkCreator.P2PConfigurationConstants.cMASTER_PORT); P2P_QueryClient_Instanciator.setP2PImplementationConfiguration(cfg); P2P_QueryClient_Instanciator.setSubgraphSubmission(withSubgraphSubmission); // create instance and store instance QueryClient qC = createInstance(); item.queryEvaluator = qC; return item; }