Implement the cluster filter |
Create an com.supermap.sample.ImageBoundsFilter class (implementing the ClusterServiceFilter interface) to implement a class with a name based on the bbox parameter (i.e., the cluster node filter).
Codes:
package com.supermap.sample; import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; import com.supermap.services.cluster.ServiceInfo; import com.supermap.services.cluster.client.spi.ClusterServiceFilter; import com.supermap.services.components.spi.ClusterServiceFilterType; @ClusterServiceFilterType(componentType = "Map", interfaceType = "WMS") public class ImageBoundsFilter implements ClusterServiceFilter { /** * Implement methods in com.supermap.services.cluster.client.spi.ClusterServiceFilter. This method will be called by the cluseter service to determine whether a service is available for processing a specific request. */ public boolean filter(ServiceInfo serviceInfo, HttpServletRequest request) { if(serviceInfo != null) { // Remove the servicers that are not WMS or the Map component type if(!"WMS".equalsIgnoreCase(serviceInfo.protocol) || !"Map".equalsIgnoreCase(serviceInfo.type) ) { return true; } } //Get the bbox parameter from the request String requestBBox = getBBox(request); if (requestBBox == null) { //If the bbox parameter is null, then this filter is not suitable for this request, return ClusterServiceFilter.NEUTRAL return true; } if (serviceInfo.address == null) { return true; } //Determine whether the bbox in the current request is within the configuration extent, and whether the port of the address for the service information is the specified port if(isContain(requestBBox, new double[]{-180,-90,0,90}) && serviceInfo.address.indexOf("8091") != -1) { return false; } if(isContain(requestBBox, new double[]{0,-90,180,90}) && serviceInfo.address.indexOf("8092") != -1) { return false; } return true; } private boolean isContain(String requestBBox, double[] bounds) { double[] requested = split(requestBBox); return requested[0] >= bounds[0] && requested[1] >= bounds[1] && requested[2] <= bounds[2] && requested[3] <= bounds[3]; } private String getBBox(HttpServletRequest request) { Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if ("BBOX".equalsIgnoreCase(name)) { return request.getParameter(name); } } return null; } private double[] split(String bbox) { String[] tmp = bbox.split(","); double[] result = new double[4]; for (int i = 0; i < 4; i++) { result[i] = Double.parseDouble(tmp[i]); } return result; } }
Create a file named as SuperMapClusterClient.properties for necessary configuration. This file should be stored under a specified directory (META-INF/extensions/cluster/filters). The file has the following contents:
implementation=com.supermap.sample.ImageBoundsFilter
A filter for customizing WMS cluster functions is configured and declared in this file. The cluster service will read this configuration file and construct the corresponding instance of an object.
After compiling the above codes, pack ImageBoundsFilter.class and the declaration file of the filter (SuperMapClusterClient.properties) into a Jar package, like clusterfilter.jar. Place clusterfilter.jar under SuperMap iServer Web of the cluster, i.e., %SuperMap iServer_HOME%webapps\iserver\WEB-INF\lib.