use of me.retrodaredevil.solarthing.type.closed.meta.DefaultMetaDatabase in project solarthing by wildmountainfarms.
the class SimpleQueryHandler method queryMeta.
public MetaDatabase queryMeta() {
final VersionedPacket<RootMetaPacket> metadata;
synchronized (this) {
final VersionedPacket<RootMetaPacket> currentCache = metadataCache;
final Long lastMetadataCacheNanos = this.lastMetadataCacheNanos;
if (lastMetadataCacheNanos != null && System.nanoTime() - lastMetadataCacheNanos < METADATA_CACHE_VALID.toNanos()) {
requireNonNull(currentCache);
metadata = currentCache;
} else {
UpdateToken updateToken = currentCache == null ? null : currentCache.getUpdateToken();
final VersionedPacket<RootMetaPacket> newMetadata;
try {
newMetadata = database.queryMetadata(updateToken);
} catch (NotFoundSolarThingDatabaseException e) {
// If we have not defined metadata, then we return an "empty" instance
return EmptyMetaDatabase.getInstance();
} catch (SolarThingDatabaseException e) {
throw new DatabaseException("Could not query meta", e);
}
this.lastMetadataCacheNanos = System.nanoTime();
if (newMetadata == null) {
requireNonNull(currentCache);
metadata = currentCache;
} else {
metadataCache = newMetadata;
metadata = newMetadata;
}
}
}
return new DefaultMetaDatabase(metadata.getPacket());
}
Aggregations