当前位置: 首页>>代码示例>>Java>>正文


Java LBHttpSolrServer.Rsp方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.impl.LBHttpSolrServer.Rsp方法的典型用法代码示例。如果您正苦于以下问题:Java LBHttpSolrServer.Rsp方法的具体用法?Java LBHttpSolrServer.Rsp怎么用?Java LBHttpSolrServer.Rsp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.impl.LBHttpSolrServer的用法示例。


在下文中一共展示了LBHttpSolrServer.Rsp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: submit

import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
@Override
public void submit(final ShardRequest sreq, final String shard, final ModifiableSolrParams params) {
  // do this outside of the callable for thread safety reasons
  final List<String> urls = getURLs(shard);

  Callable<ShardResponse> task = new Callable<ShardResponse>() {
    @Override
    public ShardResponse call() throws Exception {

      ShardResponse srsp = new ShardResponse();
      if (sreq.nodeName != null) {
        srsp.setNodeName(sreq.nodeName);
      }
      srsp.setShardRequest(sreq);
      srsp.setShard(shard);
      SimpleSolrResponse ssr = new SimpleSolrResponse();
      srsp.setSolrResponse(ssr);
      long startTime = System.nanoTime();

      try {
        params.remove(CommonParams.WT); // use default (currently javabin)
        params.remove(CommonParams.VERSION);

        // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");
        // use generic request to avoid extra processing of queries
        QueryRequest req = new QueryRequest(params);
        req.setMethod(SolrRequest.METHOD.POST);

        // no need to set the response parser as binary is the default
        // req.setResponseParser(new BinaryResponseParser());

        // if there are no shards available for a slice, urls.size()==0
        if (urls.size()==0) {
          // TODO: what's the right error code here? We should use the same thing when
          // all of the servers for a shard are down.
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
        }

        if (urls.size() <= 1) {
          String url = urls.get(0);
          srsp.setShardAddress(url);
          SolrServer server = new HttpSolrServer(url, httpClient);
          try {
            ssr.nl = server.request(req);
          } finally {
            server.shutdown();
          }
        } else {
          LBHttpSolrServer.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
          ssr.nl = rsp.getResponse();
          srsp.setShardAddress(rsp.getServer());
        }
      }
      catch( ConnectException cex ) {
        srsp.setException(cex); //????
      } catch (Exception th) {
        srsp.setException(th);
        if (th instanceof SolrException) {
          srsp.setResponseCode(((SolrException)th).code());
        } else {
          srsp.setResponseCode(-1);
        }
      }

      ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

      return srsp;
    }
  };

  pending.add( completionService.submit(task) );
}
 
开发者ID:europeana,项目名称:search,代码行数:73,代码来源:HttpShardHandler.java

示例2: submit

import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
@Override
public void submit(final ShardRequest sreq, final String shard, final ModifiableSolrParams params) {
  // do this outside of the callable for thread safety reasons
  final List<String> urls = getURLs(shard);

  Callable<ShardResponse> task = new Callable<ShardResponse>() {
    @Override
    public ShardResponse call() throws Exception {

      ShardResponse srsp = new ShardResponse();
      if (sreq.nodeName != null) {
        srsp.setNodeName(sreq.nodeName);
      }
      srsp.setShardRequest(sreq);
      srsp.setShard(shard);
      SimpleSolrResponse ssr = new SimpleSolrResponse();
      srsp.setSolrResponse(ssr);
      long startTime = System.nanoTime();

      try {
        String json = params.get(AbstractQParser.ALFRESCO_JSON);
        params.remove(AbstractQParser.ALFRESCO_JSON); 
          
        params.remove(CommonParams.WT); // use default (currently javabin)
        params.remove(CommonParams.VERSION);

        // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");
        // use generic request to avoid extra processing of queries
        AlfrescoQueryRequest req = new AlfrescoQueryRequest(params);
        req.setMethod(SolrRequest.METHOD.POST);
        if(json != null)
        {
            req.setContentStream(new ContentStreamBase.StringStream(json));
        }

        // no need to set the response parser as binary is the default
        // req.setResponseParser(new BinaryResponseParser());

        // if there are no shards available for a slice, urls.size()==0
        if (urls.size()==0) {
          // TODO: what's the right error code here? We should use the same thing when
          // all of the servers for a shard are down.
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
        }

        if (urls.size() <= 1) {
          String url = urls.get(0);
          srsp.setShardAddress(url);
          SolrServer server = new HttpSolrServer(url, httpClient);
          try {
            ssr.nl = server.request(req);
          } finally {
            server.shutdown();
          }
        } else {
          LBHttpSolrServer.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
          ssr.nl = rsp.getResponse();
          srsp.setShardAddress(rsp.getServer());
        }
      }
      catch( ConnectException cex ) {
        srsp.setException(cex); //????
      } catch (Exception th) {
        srsp.setException(th);
        if (th instanceof SolrException) {
          srsp.setResponseCode(((SolrException)th).code());
        } else {
          srsp.setResponseCode(-1);
        }
      }

      ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

      return srsp;
    }
  };

  pending.add( completionService.submit(task) );
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:80,代码来源:AlfrescoHttpShardHandler.java

示例3: submit

import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
@Override
public void submit(final ShardRequest sreq, final String shard, final ModifiableSolrParams params) {
  // do this outside of the callable for thread safety reasons
  final List<String> urls = getURLs(shard);

  Callable<ShardResponse> task = new Callable<ShardResponse>() {
    @Override
    public ShardResponse call() throws Exception {

      ShardResponse srsp = new ShardResponse();
      if (sreq.nodeName != null) {
        srsp.setNodeName(sreq.nodeName);
      }
      srsp.setShardRequest(sreq);
      srsp.setShard(shard);
      SimpleSolrResponse ssr = new SimpleSolrResponse();
      srsp.setSolrResponse(ssr);
      long startTime = System.currentTimeMillis();

      try {
        params.remove(CommonParams.WT); // use default (currently javabin)
        params.remove(CommonParams.VERSION);

        // SolrRequest req = new QueryRequest(SolrRequest.METHOD.POST, "/select");
        // use generic request to avoid extra processing of queries
        QueryRequest req = new QueryRequest(params);
        req.setMethod(SolrRequest.METHOD.POST);

        // no need to set the response parser as binary is the default
        // req.setResponseParser(new BinaryResponseParser());

        // if there are no shards available for a slice, urls.size()==0
        if (urls.size()==0) {
          // TODO: what's the right error code here? We should use the same thing when
          // all of the servers for a shard are down.
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
        }

        if (urls.size() <= 1) {
          String url = urls.get(0);
          srsp.setShardAddress(url);
          SolrServer server = new HttpSolrServer(url, httpClient);
          ssr.nl = server.request(req);
        } else {
          LBHttpSolrServer.Rsp rsp = httpShardHandlerFactory.loadbalancer.request(new LBHttpSolrServer.Req(req, urls));
          ssr.nl = rsp.getResponse();
          srsp.setShardAddress(rsp.getServer());
        }
      }
      catch( ConnectException cex ) {
        srsp.setException(cex); //????
      } catch (Throwable th) {
        srsp.setException(th);
        if (th instanceof SolrException) {
          srsp.setResponseCode(((SolrException)th).code());
        } else {
          srsp.setResponseCode(-1);
        }
      }

      ssr.elapsedTime = System.currentTimeMillis() - startTime;

      return srsp;
    }
  };

  pending.add( completionService.submit(task) );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:69,代码来源:HttpShardHandler.java

示例4: makeLoadBalancedRequest

import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
/**
 * Makes a request to one or more of the given urls, using the configured load balancer.
 *
 * @param req The solr search request that should be sent through the load balancer
 * @param urls The list of solr server urls to load balance across
 * @return The response from the request
 */
public LBHttpSolrServer.Rsp makeLoadBalancedRequest(final QueryRequest req, List<String> urls)
  throws SolrServerException, IOException {
  return loadbalancer.request(new LBHttpSolrServer.Req(req, urls));
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:HttpShardHandlerFactory.java

示例5: makeLoadBalancedRequest

import org.apache.solr.client.solrj.impl.LBHttpSolrServer; //导入方法依赖的package包/类
/**
 * Makes a request to one or more of the given urls, using the configured load balancer.
 *
 * @param req The solr search request that should be sent through the load balancer
 * @param urls The list of solr server urls to load balance across
 * @return The response from the request
 */
public LBHttpSolrServer.Rsp makeLoadBalancedRequest(final AlfrescoQueryRequest req, List<String> urls)
  throws SolrServerException, IOException {
  return loadbalancer.request(new LBHttpSolrServer.Req(req, urls));
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:12,代码来源:AlfrescoHttpShardHandlerFactory.java


注:本文中的org.apache.solr.client.solrj.impl.LBHttpSolrServer.Rsp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。