solr处理请求的接口为SolrRequestHandler.java ,由handleRequest方法处理来自http的请求
/***********************************************************************
* Module: SolrRequestHandler.java
* Author: Administrator
* Purpose: Defines the Interface SolrRequestHandler
***********************************************************************/
import java.util.*;
/** @pdOid 92641501-9fac-4850-bf72-43e262d42eff */
public interface SolrRequestHandler {
/** @param args
* @pdOid 0d916c92-cb61-408c-844d-a756cc1e9a41 */
void init(NamedList args);
/** @param req
* @param rsp
* @pdOid 35c91800-4167-49d1-aefe-c961fb7082d1 */
void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp);
* Module: SolrRequestHandler.java
* Author: Administrator
* Purpose: Defines the Interface SolrRequestHandler
***********************************************************************/
import java.util.*;
/** @pdOid 92641501-9fac-4850-bf72-43e262d42eff */
public interface SolrRequestHandler {
/** @param args
* @pdOid 0d916c92-cb61-408c-844d-a756cc1e9a41 */
void init(NamedList args);
/** @param req
* @param rsp
* @pdOid 35c91800-4167-49d1-aefe-c961fb7082d1 */
void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp);
}
公用的实现类为RequestHandlerBase.java
/***********************************************************************
* Module: RequestHandlerBase.java
* Author: Administrator
* Purpose: Defines the Class RequestHandlerBase
***********************************************************************/
import java.util.*;
/** @pdOid 9e2891cc-6977-4d7e-86f8-d406a3493599 */
public abstract class RequestHandlerBase implements SolrRequestHandler {
/** @param args
* @pdOid 48f0c55d-b3a3-4736-8e47-1c866398eeef */
public void init(NamedList args) {
}
/** @param req
* @param rsp
* @exception Exception
* @pdOid 3eec0a97-ed48-4f4e-b78b-142247478b69 */
public abstract void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception;
/** @param req
* @param rsp
* @pdOid 7b97a1ac-509c-4a03-aaed-a2bbd320dbcc */
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
}
}
* Author: Administrator
* Purpose: Defines the Class RequestHandlerBase
***********************************************************************/
import java.util.*;
/** @pdOid 9e2891cc-6977-4d7e-86f8-d406a3493599 */
public abstract class RequestHandlerBase implements SolrRequestHandler {
/** @param args
* @pdOid 48f0c55d-b3a3-4736-8e47-1c866398eeef */
public void init(NamedList args) {
}
/** @param req
* @param rsp
* @exception Exception
* @pdOid 3eec0a97-ed48-4f4e-b78b-142247478b69 */
public abstract void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception;
/** @param req
* @param rsp
* @pdOid 7b97a1ac-509c-4a03-aaed-a2bbd320dbcc */
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
}
}
这是一个抽象类,其中抽象方法handleRequestBody 由子类实现,真正的处理逻辑在子类的handleRequestBody方法
由handleRequest调用子类的 handleRequestBody方法,这是一种典型的模板方法设计模式
负责数据导入的实现类为DataImportHandler.java,示例代码如下
/***********************************************************************
* Module: DataImportHandler.java
* Author: Administrator
* Purpose: Defines the Class DataImportHandler
***********************************************************************/
import java.util.*;
/** @pdOid 1277dd7d-601d-45c7-a2ef-1836f46db6f3 */
public class DataImportHandler extends RequestHandlerBase {
/** @pdOid 6e53bcab-98f0-4ce1-97a0-1c15e9be51ac */
private DataImporter importer;
/** @param req
* @param rsp
* @exception Exception
* @pdOid 15ebeea5-1faf-4d9d-89bb-3c4be63bf15a */
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
importer.runCmd(requestParams, sw);
}
}
* Author: Administrator
* Purpose: Defines the Class DataImportHandler
***********************************************************************/
import java.util.*;
/** @pdOid 1277dd7d-601d-45c7-a2ef-1836f46db6f3 */
public class DataImportHandler extends RequestHandlerBase {
/** @pdOid 6e53bcab-98f0-4ce1-97a0-1c15e9be51ac */
private DataImporter importer;
/** @param req
* @param rsp
* @exception Exception
* @pdOid 15ebeea5-1faf-4d9d-89bb-3c4be63bf15a */
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
importer.runCmd(requestParams, sw);
}
}
DataImportHandler类持有DataImporter的引用,调用DataImporter类的相关方法实现进一步的处理
简要类图如下