Exemplo n.º 1
0
  public void handleQuery(Query query) throws IOException {
    log.info("Reporting query statatistics");
    bout.write(query.getIdentifier() + ";");

    MonitoringService m = MonitoringUtil.getMonitoringService();
    try {
      int total = 0;
      for (Endpoint e : endpoints) {
        try {
          MonitoringInformation mInfo = m.getMonitoringInformation(e);
          int requestCount = mInfo != null ? mInfo.getNumberOfRequests() : 0;

          total += requestCount;

          log.info("## " + e.getId() + " => " + requestCount + " requests");
          bout.write(requestCount + ";");
        } catch (Exception ex) {
          log.warn("Exception (" + ex.getClass() + "):" + ex.getMessage());
          bout.write("-1;");
        }
      }
      bout.write(total + ";");
      bout.write("\r\n");
      bout.flush();
    } finally {
      m.resetMonitoringInformation();
    }
  }
Exemplo n.º 2
0
 public FedXMonitoringReport(List<Endpoint> endpoints) throws IOException {
   this.endpoints = endpoints;
   bout = new BufferedWriter(new FileWriter("result/fedx_stats.csv"));
   bout.write("query;");
   for (Endpoint e : endpoints) bout.write(e.getId() + ";");
   bout.write("total;");
   bout.write("\r\n");
 }
  @Override
  public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(
      String sparqlQueryString,
      BindingSet bindings,
      String baseUri,
      QueryType type,
      Service service)
      throws QueryEvaluationException {
    RepositoryConnection conn = endpoint.getConn();
    try {
      TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString, baseUri);

      Iterator<Binding> bIter = bindings.iterator();
      while (bIter.hasNext()) {
        Binding b = bIter.next();
        if (service.getServiceVars().contains(b.getName()))
          query.setBinding(b.getName(), b.getValue());
      }

      TupleQueryResult qRes = query.evaluate();
      return new InsertBindingsIteration(qRes, bindings);
    } catch (OpenRDFException e) {
      throw new QueryEvaluationException(e);
    }
  }
  @Override
  public Endpoint loadEndpoint(RepositoryInformation repoInfo) throws FedXException {

    File store = FileUtil.getFileLocation(repoInfo.getLocation());

    if (!store.exists()) {
      throw new FedXRuntimeException(
          "Store does not exist at '"
              + repoInfo.getLocation()
              + ": "
              + store.getAbsolutePath()
              + "'.");
    }

    try {
      NativeStore ns = new NativeStoreExt(store);
      SailRepository repo = new SailRepository(ns);
      repo.initialize();

      ProviderUtil.checkConnectionIfConfigured(repo);

      Endpoint res =
          new Endpoint(
              repoInfo.getId(),
              repoInfo.getName(),
              repoInfo.getLocation(),
              repoInfo.getType(),
              EndpointClassification.Local);
      res.setEndpointConfiguration(repoInfo.getEndpointConfiguration());
      res.setRepo(repo);

      // register a federated service manager to deal with this endpoint
      SAILFederatedService federatedService = new SAILFederatedService(res);
      federatedService.initialize();
      FederatedServiceManager.getInstance().registerService(repoInfo.getName(), federatedService);

      return res;
    } catch (RepositoryException e) {
      throw new FedXException(
          "Repository " + repoInfo.getId() + " could not be initialized: " + e.getMessage(), e);
    }
  }