public class MultiFetchServerObjectReader extends OsmServerReader
OsmPrimitives from an OSM server using the so called
Multi Fetch API.
Usage:
MultiFetchServerObjectReader reader = MultiFetchServerObjectReader()
.append(2345,2334,4444)
.append(new Node(72343));
reader.parseOsm();
if (!reader.getMissingPrimitives().isEmpty()) {
Logging.info("There are missing primitives: " + reader.getMissingPrimitives());
}
if (!reader.getSkippedWays().isEmpty()) {
Logging.info("There are skipped ways: " + reader.getMissingPrimitives());
}
| Modifier and Type | Class and Description |
|---|---|
protected class |
MultiFetchServerObjectReader.Fetcher
The class that actually download data from OSM API.
|
protected static class |
MultiFetchServerObjectReader.FetchResult
The class holding the results given by
MultiFetchServerObjectReader.Fetcher. |
OsmServerReader.DomParser<R>OsmConnection.OAuthAccessTokenFetcher| Modifier and Type | Field and Description |
|---|---|
private static int |
MAX_IDS_PER_REQUEST
the max.
|
private java.util.Set<PrimitiveId> |
missingPrimitives |
private java.util.Set<java.lang.Long> |
nodes |
private DataSet |
outputDataSet |
private java.util.Set<java.lang.Long> |
relations |
private java.util.Set<java.lang.Long> |
ways |
contentType, gpxParsedProperlyactiveConnection, cancel, fetcher, oauthParameters| Modifier | Constructor and Description |
|---|---|
protected |
MultiFetchServerObjectReader()
Constructs a
MultiFetchServerObjectReader. |
| Modifier and Type | Method and Description |
|---|---|
MultiFetchServerObjectReader |
append(java.util.Collection<? extends OsmPrimitive> primitives)
appends a list of
OsmPrimitive to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
append(DataSet ds,
long id,
OsmPrimitiveType type)
appends a
OsmPrimitive id to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
append(OsmPrimitive primitive)
appends an
OsmPrimitive to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
appendNode(Node node)
appends a
Node id to the list of ids which will be fetched from the server. |
protected MultiFetchServerObjectReader |
appendRelation(Relation relation)
appends a
Relation id to the list of ids which will be fetched from the server. |
MultiFetchServerObjectReader |
appendWay(Way way)
appends a
Way id and the list of ids of nodes the way refers to the list of ids which will be fetched from the server. |
protected java.lang.String |
buildRequestString(OsmPrimitiveType type,
java.util.Set<java.lang.Long> idPackage)
builds the Multi Get request string for a set of ids and a given
OsmPrimitiveType. |
static MultiFetchServerObjectReader |
create()
Creates a new instance of
MultiFetchServerObjectReader or MultiFetchOverpassObjectReader
depending on the preference. |
static MultiFetchServerObjectReader |
create(boolean fromMirror)
Creates a new instance of
MultiFetchServerObjectReader or MultiFetchOverpassObjectReader
depending on the fromMirror parameter. |
protected java.util.Set<java.lang.Long> |
extractIdPackage(java.util.Set<java.lang.Long> ids)
extracts a subset of max
MAX_IDS_PER_REQUEST ids from ids and
replies the subset. |
protected void |
fetchPrimitives(java.util.Set<java.lang.Long> ids,
OsmPrimitiveType type,
ProgressMonitor progressMonitor)
fetches a set of ids of a given
OsmPrimitiveType from the server |
java.util.Set<PrimitiveId> |
getMissingPrimitives()
replies the set of ids of all primitives for which a fetch request to the
server was submitted but which are not available from the server (the server
replied a return code of 404)
|
protected void |
merge(DataSet from)
merges the dataset
from to outputDataSet. |
DataSet |
parseOsm(ProgressMonitor progressMonitor)
invokes one or more Multi Gets to fetch the
OsmPrimitives and replies
the dataset of retrieved primitives. |
protected boolean |
recursesDown()
Whether this reader fetches nodes when loading ways, or members when loading relations.
|
protected void |
remember(PrimitiveId id)
Remembers an
OsmPrimitive's id. |
protected void |
rememberNodesOfIncompleteWaysToLoad(DataSet from) |
adaptRequest, fetchData, getAttribute, getBaseUrl, getInputStream, getInputStream, getInputStreamRaw, getInputStreamRaw, getInputStreamRaw, getInputStreamRaw, isDoAuthenticate, isGpxParsedProperly, parseNotes, parseOsm, parseOsmChange, parseOsmChange, parseRawGps, parseRawGps, parseRawNotes, parseRawNotes, setDoAuthenticateaddAuth, addBasicAuthorizationHeader, addOAuthAuthorizationHeader, cancel, isCanceled, obtainAccessToken, retrieveBasicAuthorizationLogin, setOAuthAccessTokenFetcherprivate static final int MAX_IDS_PER_REQUEST
private final java.util.Set<java.lang.Long> nodes
private final java.util.Set<java.lang.Long> ways
private final java.util.Set<java.lang.Long> relations
private java.util.Set<PrimitiveId> missingPrimitives
private final DataSet outputDataSet
protected MultiFetchServerObjectReader()
MultiFetchServerObjectReader.public static MultiFetchServerObjectReader create()
MultiFetchServerObjectReader or MultiFetchOverpassObjectReader
depending on the preference.public static MultiFetchServerObjectReader create(boolean fromMirror)
MultiFetchServerObjectReader or MultiFetchOverpassObjectReader
depending on the fromMirror parameter.fromMirror - false for MultiFetchServerObjectReader, true for MultiFetchOverpassObjectReaderprotected void remember(PrimitiveId id)
OsmPrimitive's id. The id will
later be fetched as part of a Multi Get request.
Ignore the id if it represents a new primitives.id - the idpublic MultiFetchServerObjectReader append(DataSet ds, long id, OsmPrimitiveType type)
OsmPrimitive id to the list of ids which will be fetched from the server.public MultiFetchServerObjectReader appendNode(Node node)
Node id to the list of ids which will be fetched from the server.node - the node (ignored, if null)public MultiFetchServerObjectReader appendWay(Way way)
Way id and the list of ids of nodes the way refers to the list of ids which will be fetched from the server.way - the way (ignored, if null)protected MultiFetchServerObjectReader appendRelation(Relation relation)
Relation id to the list of ids which will be fetched from the server.relation - the relation (ignored, if null)public MultiFetchServerObjectReader append(OsmPrimitive primitive)
OsmPrimitive to the list of ids which will be fetched from the server.primitive - the primitivepublic MultiFetchServerObjectReader append(java.util.Collection<? extends OsmPrimitive> primitives)
OsmPrimitive to the list of ids which will be fetched from the server.primitives - the list of primitives (ignored, if null)append(OsmPrimitive)protected java.util.Set<java.lang.Long> extractIdPackage(java.util.Set<java.lang.Long> ids)
MAX_IDS_PER_REQUEST ids from ids and
replies the subset. The extracted subset is removed from ids.ids - a set of idsprotected java.lang.String buildRequestString(OsmPrimitiveType type, java.util.Set<java.lang.Long> idPackage)
OsmPrimitiveType.protected void rememberNodesOfIncompleteWaysToLoad(DataSet from)
protected void merge(DataSet from)
from to outputDataSet.from - the other datasetprotected void fetchPrimitives(java.util.Set<java.lang.Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException
OsmPrimitiveType from the serverids - the set of idstype - The primitive type. Must be one of NODE, WAY,
RELATIONprogressMonitor - progress monitorOsmTransferException - if an error occurs while communicating with the API serverpublic DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException
OsmPrimitives and replies
the dataset of retrieved primitives. Note that the dataset includes non visible primitives too!
In contrast to a simple Get for a node, a way, or a relation, a Multi Get always replies
the latest version of the primitive (if any), even if the primitive is not visible (i.e. if
visible==false).
Invoke getMissingPrimitives() to get a list of primitives which have not been
found on the server (the server response code was 404)parseOsm in class OsmServerReaderprogressMonitor - The progress monitorOsmTransferException - if an error occurs while communicating with the API servergetMissingPrimitives()public java.util.Set<PrimitiveId> getMissingPrimitives()
protected boolean recursesDown()
true if the reader recurses down