org.openstreetmap.josm.io
Class MultiFetchServerObjectReader.Fetcher

java.lang.Object
  extended by org.openstreetmap.josm.io.OsmConnection
      extended by org.openstreetmap.josm.io.OsmServerReader
          extended by org.openstreetmap.josm.io.MultiFetchServerObjectReader.Fetcher
All Implemented Interfaces:
java.util.concurrent.Callable<MultiFetchServerObjectReader.FetchResult>
Enclosing class:
MultiFetchServerObjectReader

protected static class MultiFetchServerObjectReader.Fetcher
extends OsmServerReader
implements java.util.concurrent.Callable<MultiFetchServerObjectReader.FetchResult>

The class that actually download data from OSM API. Several instances of this class are used by MultiFetchServerObjectReader (one per set of primitives to fetch). The inheritance of OsmServerReader is only explained by the need to have a distinct OSM connection by Fetcher instance.

See Also:
MultiFetchServerObjectReader.FetchResult

Field Summary
private  java.util.Set<java.lang.Long> pkg
           
private  ProgressMonitor progressMonitor
           
private  OsmPrimitiveType type
           
 
Fields inherited from class org.openstreetmap.josm.io.OsmConnection
activeConnection, cancel, oauthParameters
 
Constructor Summary
MultiFetchServerObjectReader.Fetcher(OsmPrimitiveType type, java.util.Set<java.lang.Long> idsPackage, ProgressMonitor progressMonitor)
          Constructs a Fetcher
 
Method Summary
 MultiFetchServerObjectReader.FetchResult call()
           
protected  MultiFetchServerObjectReader.FetchResult fetch(ProgressMonitor progressMonitor)
          fetches the requested primitives and updates the specified progress monitor.
protected  MultiFetchServerObjectReader.FetchResult multiGetIdPackage(OsmPrimitiveType type, java.util.Set<java.lang.Long> pkg, ProgressMonitor progressMonitor)
          invokes a Multi Get for a set of ids and a given OsmPrimitiveType.
 DataSet parseOsm(ProgressMonitor progressMonitor)
           
protected  DataSet singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor)
          invokes a Multi Get for a single id and a given OsmPrimitiveType.
protected  MultiFetchServerObjectReader.FetchResult singleGetIdPackage(OsmPrimitiveType type, java.util.Set<java.lang.Long> pkg, ProgressMonitor progressMonitor)
          invokes a sequence of Multi Gets for individual ids in a set of ids and a given OsmPrimitiveType.
 
Methods inherited from class org.openstreetmap.josm.io.OsmServerReader
getBaseUrl, getInputStream, getInputStreamRaw, isDoAuthenticate, parseOsmBzip2, parseOsmChange, parseOsmChangeBzip2, parseOsmChangeGzip, parseOsmGzip, parseRawGps, setDoAuthenticate
 
Methods inherited from class org.openstreetmap.josm.io.OsmConnection
addAuth, addBasicAuthorizationHeader, addOAuthAuthorizationHeader, cancel, isCanceled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pkg

private final java.util.Set<java.lang.Long> pkg

type

private final OsmPrimitiveType type

progressMonitor

private final ProgressMonitor progressMonitor
Constructor Detail

MultiFetchServerObjectReader.Fetcher

public MultiFetchServerObjectReader.Fetcher(OsmPrimitiveType type,
                                            java.util.Set<java.lang.Long> idsPackage,
                                            ProgressMonitor progressMonitor)
Constructs a Fetcher

Parameters:
type - The primitive type. Must be one of NODE, WAY, RELATION
idsPackage - The set of primitives ids to fetch
progressMonitor - The progress monitor
Method Detail

parseOsm

public DataSet parseOsm(ProgressMonitor progressMonitor)
                 throws OsmTransferException
Specified by:
parseOsm in class OsmServerReader
Throws:
OsmTransferException

call

public MultiFetchServerObjectReader.FetchResult call()
                                              throws java.lang.Exception
Specified by:
call in interface java.util.concurrent.Callable<MultiFetchServerObjectReader.FetchResult>
Throws:
java.lang.Exception

fetch

protected MultiFetchServerObjectReader.FetchResult fetch(ProgressMonitor progressMonitor)
                                                  throws OsmTransferException
fetches the requested primitives and updates the specified progress monitor.

Parameters:
progressMonitor - the progress monitor
Returns:
the MultiFetchServerObjectReader.FetchResult of this operation
Throws:
OsmTransferException - if an error occurs while communicating with the API server

multiGetIdPackage

protected MultiFetchServerObjectReader.FetchResult multiGetIdPackage(OsmPrimitiveType type,
                                                                     java.util.Set<java.lang.Long> pkg,
                                                                     ProgressMonitor progressMonitor)
                                                              throws OsmTransferException
invokes a Multi Get for a set of ids and a given OsmPrimitiveType. The retrieved primitives are merged to MultiFetchServerObjectReader.outputDataSet.

Parameters:
type - The primitive type. Must be one of NODE, WAY, RELATION
pkg - the package of ids
Returns:
the MultiFetchServerObjectReader.FetchResult of this operation
Throws:
OsmTransferException - if an error occurs while communicating with the API server

singleGetId

protected DataSet singleGetId(OsmPrimitiveType type,
                              long id,
                              ProgressMonitor progressMonitor)
                       throws OsmTransferException
invokes a Multi Get for a single id and a given OsmPrimitiveType. The retrieved primitive is merged to MultiFetchServerObjectReader.outputDataSet.

Parameters:
type - The primitive type. Must be one of NODE, WAY, RELATION
id - the id
Returns:
the DataSet resulting of this operation
Throws:
OsmTransferException - if an error occurs while communicating with the API server

singleGetIdPackage

protected MultiFetchServerObjectReader.FetchResult singleGetIdPackage(OsmPrimitiveType type,
                                                                      java.util.Set<java.lang.Long> pkg,
                                                                      ProgressMonitor progressMonitor)
                                                               throws OsmTransferException
invokes a sequence of Multi Gets for individual ids in a set of ids and a given OsmPrimitiveType. The retrieved primitives are merged to MultiFetchServerObjectReader.outputDataSet. This method is used if one of the ids in pkg doesn't exist (the server replies with return code 404). If the set is fetched with this method it is possible to find out which of the ids doesn't exist. Unfortunately, the server does not provide an error header or an error body for a 404 reply.

Parameters:
type - The primitive type. Must be one of NODE, WAY, RELATION
pkg - the set of ids
Returns:
the MultiFetchServerObjectReader.FetchResult of this operation
Throws:
OsmTransferException - if an error occurs while communicating with the API server


JOSM