您的位置:首页 > 理论基础 > 计算机网络

GeoServer学习手记(六):Servlet及HTTP派发过程之三

2009-11-02 21:35 483 查看
GeoServer学习手记(六):Servlet及HTTP派发过程之三

粟卫民http://www.gisdev.cn/http://blog.csdn.net/suen/日期:2009-10-31

保留所有版权。如需转载,请联系作者,并在醒目位置注明出处

接上篇《GeoServer学习手记(五):Servlet及HTTP派发过程之二》(http://blog.csdn.net/suen/archive/2009/11/02/4759398.aspx)。

Response
TheResponseistheprocessingofwhatissentbacktotheuseraftertheirrequest.Theformatofthisrsponse,foragetFeaturerequest,isGML.

Hereisanoverviewoftheprocessinpictureformat:




WhereitStarts

Attheverybeginning,inWfsDispatcher,anHttpServeletResponseispassedintodoGet()anddoPost()

publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException


publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException

Letsreferbacktothisdiagram:




ThisresponseobjectispassedintotheFeatureservelet,soitcanbepopulatedonceithasaholdofaFeatureReader.

OutputStrategyObject

TheoutputstrategyobjecttellsGeoserverhowtoproceedewhenreturningthedata.Whatdoesthismean?Herearesomeexamplesthatarespecifiedintheweb.xmlfiletohelpexplainit:


serviceStratagy


SPEED


WhyisitcalledStrategy?AStrategyisadesignpatternthatisdefinedintheGangofFourDesignPatternsbook(ISBN0201633612).Whatitessentiallydoes,isallowtheusertoplugintheirownmethodofperformingaspecifictask.SowhatGeoserverdoesisreadtheweb.xmlfile,seewhatstrategyyouwanttouse('speed'inourexample),andplugitintotheoutputresponseprocess.

Youcandefineyourownoutputstrategyobjectbylookinginorg.vfny.geoserver.servlets.AbstractService.Itmustimplementorg.vfny.geoserver.servlets.AbstractService.ServiceStrategy

Hereisatutorialonsettingupyourownoutputstrategy.

FeatureStreaming

ItsveryimportanttonotethattheGeoserver/GeotoolsdesignallowsforFeatureStreaming,meaningthatGeoserveronlyeverhasaroundonefeatureinmemoryatatime.Thisisveryimportantforlargequeries(oryou'drunoutofmemory)aswellassimutaneouslydoingmultiplequeries.

WhenaDataStoreacceptsaQuery,itdoesntactuallyreturnFeatures,insteaditreturnsaFeatureReaderwhichcanbeusedtoreadtheFeaturethattheQueryselectsone-at-a-time.Thedelegate(ie.GML2producerinourexample)readsasinglefeature,convertsittoGML2andsendtheresultsofftotheoutputStrategyobject.

GMLEncoding

Aftertheoutputstrategyhasbeendetermined,theFeaturesendstheoutputtoaFeatureResponseobject.ThisfeatureresponseobjectwillthenpassontheinformationtotheGML2FeatureResponseDelegateobject.

TheGMLencodingobjectwilltakecareoftherestoftheoutputforyouthatwillbestreamedthroughtheoutputstrategy.

TheEnd

Notes
HowDatastoresprocessQuery&Filter

SomeDataStores(liketheDatabasebackedones)candomostoftheFilterprocessinginthedatabaseusingthedatabase'sindexes.Otherdatastorescando"quick"processingofcertaincomponentsoftheFilter.Forexample,the"normalshapefile"datastorecanquicklydobounding-boxtestsforfeatures.The"indexshapefile"datastore(thatsashapefilewitha.qixspatialindexfile)candospatialsearchingquickly.

Basically,theFilterobjectissenttothedatastorewhichlooksattheFilterandbeaksitintocomponents:

portionsthatthedatastorecanindex(ie.quicklyapproximateasolution)

portionsthatthedatastorecanefficientlycalculate(ie.quicklycalculateasolution)

portionsthatthedatastorecannotefficientlycalculate(thesewillbehandledbyGeotoolsJavacode)

AllthisishandledtransparentlybythedatastoresotheprogrammerjusthastosendaQueryobjectofftotheDataStoreandnothavetoworryabouthowitprocessesit.ThefeaturesreturnedbytheFeatureReaderwillonlybeonesthatpasstheFilterconditions.

LetslooksataPostGISexampleforaQuery'sFilterthatlookslikethis:

(the_geomINTERSECTS)AND(population>1000000)

ThiswillbetranslatedintotheSQLquery:

SELECT...FROMWHERE

[code]the_geom&&--thisisthespatialindexoperation
ANDintersects(the_geom,)--thisisthefullOGCspatialoperation

ANDpopulation>1000000;

Thesamequerytothe"normalshapefile"datastorewillbeprocesseddifferently.Theshapefiledatastorecanperformbounding-boxvsbounding-boxoperationsquicklybecausetheshapefilehastheboundingofeachgeometrystored.

Thereadprocessingisdoneintwostates:(a)shapefileoptimizedand(b)Java-codehandled.

foreachrowintheshapefile

Iftherow'sboundingboxoverlapsthe

THENsendthisrowtothenextstage

OTHERWISEthisfeaturedoesnotpasstheFiltercondition

Javacodewillthentakethe"approximate"solutionthatthedatastorecanquicklycomputeandfullyevaluatetheFilter.

Thesamequerytothe"indexedshapefile"datastorecanbeprocessedevenmoreeffiently.InsteadofhavingtoreadlargeportionsoftheshapefiletotestEVERYrowtoseeiftheboundingboxintersectsthesearchboundingbox,itcanjustreadaportionofthespatialindex.Javacodewillthentakethis"approximate"solutionthatthedatastorecanveryquicklycomputeandfullyevaluatetheFilter.

1.6版之后的HTTP派发过程

(未完待续)

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: