Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 8b4b616

Browse files
committed
Fix for using fallback data when offline and triggering usage of newly loaded data was missing.
1 parent 32452e2 commit 8b4b616

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main/java/org/javamoney/moneta/internal/loader/DefaultLoaderService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ private void addScheduledLoad(final LoadableResource load) {
477477
@Override
478478
public void run() {
479479
try {
480-
load.load();
480+
if (load.load()) {
481+
triggerListeners(load.getResourceId(), load.getDataStream());
482+
}
481483
} catch (Exception e) {
482484
LOG.log(Level.SEVERE, "Failed to update remote resource: " + load.getResourceId(), e);
483485
}

src/main/java/org/javamoney/moneta/internal/loader/LoadableResource.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ public boolean load() {
147147
clearCache();
148148
}
149149
if (!readCache()) {
150-
if (shouldReadDataFromCallBack()) {
150+
if (shouldReadDataFromFallback()) {
151151
return loadFallback();
152152
}
153153
}
154154
return true;
155155
}
156156

157-
private boolean shouldReadDataFromCallBack() {
158-
return LoaderService.UpdatePolicy.NEVER.equals(updatePolicy) || !loadRemote();
157+
private boolean shouldReadDataFromFallback() {
158+
return LoaderService.UpdatePolicy.NEVER.equals(updatePolicy) || !loadRemote();
159159
}
160160

161161
/**
@@ -229,12 +229,12 @@ public final long getLastLoaded() {
229229
public boolean loadRemote() {
230230
for (URI itemToLoad : remoteResources) {
231231
try {
232-
return !load(itemToLoad, false);
232+
return load(itemToLoad, false);
233233
} catch (Exception e) {
234234
LOG.log(Level.INFO, "Failed to load resource: " + itemToLoad, e);
235235
}
236236
}
237-
return true;
237+
return false;
238238
}
239239

240240
/**
@@ -328,8 +328,6 @@ protected boolean load(URI itemToLoad, boolean fallbackLoad) {
328328
setData(bos.toByteArray());
329329
if (!fallbackLoad) {
330330
writeCache();
331-
}
332-
if (!fallbackLoad) {
333331
lastLoaded = System.currentTimeMillis();
334332
loadCount.incrementAndGet();
335333
}
@@ -372,7 +370,7 @@ protected byte[] getData(boolean loadIfNeeded) {
372370
synchronized (LOCK) {
373371
currentData = this.data == null ? null : this.data.get();
374372
if (currentData==null) {
375-
if (shouldReadDataFromCallBack()) {
373+
if (shouldReadDataFromFallback()) {
376374
loadFallback();
377375
}
378376
}
@@ -407,7 +405,7 @@ public void unload() {
407405
*
408406
* @return true on success.
409407
*/
410-
public boolean resetToFallback(){
408+
public boolean resetToFallback() {
411409
if (loadFallback()) {
412410
loadCount.set(0);
413411
return true;

0 commit comments

Comments
 (0)