今天突然给了个任务让测试点在面内算法,然后通过SuperMap iServerJava 6R发布出来并测试并发访问性能。好久没结果Java突然有点乱,胡子眉毛一把抓,不过思路总算清晰起来了,记录下来以备后需查找吧。
测试总体思路
1、扩展领域开发开出点在面内REST接口。
(1)扩展Component。
扩展Componentpackage com.zhangwei.Extend;import java.util.List;import com.supermap.services.components.Component;import com.supermap.services.components.ComponentContext;import com.supermap.services.components.ComponentContextAware;import com.supermap.services.components.commontypes.Feature;import com.supermap.services.components.commontypes.Geometry;import com.supermap.services.components.spi.DataProvider;@Component(providerTypes={DataProvider.class}, optional=false, type = "")public class InWithComponent implements ComponentContextAware{ //数据提供者 private DataProvider dataProvider = null; /** * 构造函数 */ public InWithComponent() { } /*** * 思路: * 1、从数据集中查询相应ID的数据,现在假设一个点,多个面对象。 * 2、判断点是否在对象几何中。 */ public Geometry inWithString(String datasourceNameR,String datasetNameR,int[] idsR,String datasourceNameP,String datasetNameP,int[] idsP) { ListlistFeatureListR = dataProvider.getFeature(datasourceNameR,datasetNameR,idsR,null); List listFeatureListP = dataProvider.getFeature(datasourceNameP,datasetNameP,idsP,null); int geometryLength = listFeatureListR.size(); int i = 0; //是否是结果标识 boolean flag = false; while(i providers = context.getProviders(Object.class); if(providers != null) { for(Object provider : providers) { if(provider instanceof DataProvider) { this.dataProvider = (DataProvider)provider; } } } }}
(2)扩展服务接口,由于是测试,此处不用Restlet或者JAX-RS,此处为了模拟数据传输对服务器影响,所以直接加了参数解析及返回结果,其实只是测试之用。
扩展接口package com.zhangwei.Extend;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import java.util.Random;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.supermap.services.Interface;import com.supermap.services.InterfaceContext;import com.supermap.services.InterfaceContextAware;import com.supermap.services.components.commontypes.Geometry;@Interface(componentTypes = { InWithComponent.class }, optional = false, multiple = false)public class ISWithInServlet extends HttpServlet implements InterfaceContextAware{ private static final long serialVersionUID = 1L; private InWithComponent inWithComponent = null; private String id = null; public ISWithInServlet() { this.id = String.valueOf(System.currentTimeMillis()); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out; response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); request.getParameter("in").toString(); out = response.getWriter(); int[] idsR = new int[2]; idsR[0] = generateRandom(1,72); idsR[1] = generateRandom(1,72); int[] idsP = new int[1]; idsP[0] = generateRandom(1,163); Geometry geometry = inWithComponent.inWithString("World","Ocean",idsR,"World","Capitals",idsP); out.print("[6390,,4883,4882,183,7136,7135,181,180,2987,651,,4578,4577]"+geometry.id); out.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } public void setInterfaceContext(InterfaceContext context) { this.getServletContext().setAttribute(this.id + "InterfaceContext", context); List