@@ -221,7 +221,7 @@ public ContinuousQueryCache(NamedCache<K, V_BACK> cache, Filter filter,
221
221
* @param filter the {@link Filter} that defines the view
222
222
* @param fCacheValues pass {@code true} to cache both the keys and values of the
223
223
* materialized view locally, or {@code false} to only cache
224
- * the keys
224
+ * the keys. Override of {@code false} described in {@link #isCacheValues()}.
225
225
*/
226
226
public ContinuousQueryCache (NamedCache <K , V_BACK > cache , Filter filter , boolean fCacheValues )
227
227
{
@@ -247,7 +247,7 @@ public ContinuousQueryCache(NamedCache<K, V_BACK> cache, Filter filter, boolean
247
247
public ContinuousQueryCache (NamedCache <K , V_BACK > cache , Filter filter ,
248
248
MapListener <? super K , ? super V_FRONT > listener )
249
249
{
250
- this (cache , filter , false , listener , null );
250
+ this (cache , filter , true , listener , null );
251
251
}
252
252
253
253
/**
@@ -284,15 +284,19 @@ public ContinuousQueryCache(NamedCache<K, V_BACK> cache, Filter filter,
284
284
*
285
285
* @param cache the {@link NamedCache} to create a view of
286
286
* @param filter the {@link Filter} that defines the view
287
- * @param fCacheValues pass true to cache both the keys and values of the
288
- * materialized view locally, or false to only cache
289
- * the keys
287
+ * @param fCacheValues pass {@code true} to cache both the keys and values of the
288
+ * materialized view locally, or {@code false} to only cache
289
+ * the keys. Override of {@code false} described in {@link #isCacheValues()}
290
290
* @param listener an optional {@link MapListener} that will receive all
291
291
* events starting from the initialization of the {@code ContinuousQueryCache}
292
292
* @param transformer an optional {@link ValueExtractor} that would be used to
293
293
* transform values retrieved from the underlying cache
294
294
* before storing them locally; if specified, this
295
295
* {@code ContinuousQueryCache} will become "read-only"
296
+ * <p>
297
+ * Note: When parameter {@code fCacheValues} is {@code false}, it is inferred that provided parameter
298
+ * {@code listener} is a lite listener as described by {@code fLite} parameter of
299
+ * {@link #addMapListener(MapListener, Filter, boolean)}.
296
300
*/
297
301
public ContinuousQueryCache (NamedCache <K , V_BACK > cache , Filter filter ,
298
302
boolean fCacheValues , MapListener <? super K , ? super V_FRONT > listener ,
@@ -321,7 +325,7 @@ public ContinuousQueryCache(NamedCache<K, V_BACK> cache, Filter filter,
321
325
* @param filter the {@link Filter} that defines the view
322
326
* @param fCacheValues pass {@code true} to cache both the keys and values of the
323
327
* materialized view locally, or {@code false} to only cache
324
- * the keys
328
+ * the keys. Override of {@code false} described in {@link #isCacheValues()}
325
329
* @param listener an optional {@link MapListener} that will receive all
326
330
* events starting from the initialization of the
327
331
* {@code ContinuousQueryCache}
@@ -330,6 +334,10 @@ public ContinuousQueryCache(NamedCache<K, V_BACK> cache, Filter filter,
330
334
* before storing them locally; if specified, this
331
335
* {@code ContinuousQueryCache} will become <em>read-only</em>
332
336
* @param loader an optional {@link ClassLoader}
337
+ * * <p>
338
+ * Note: When parameter {@code fCacheValues} is {@code false}, it is inferred that the provided parameter
339
+ * {@code listener} is a lite listener as described by {@code fLite} parameter of
340
+ * {@link #addMapListener(MapListener, Filter, boolean)}.
333
341
*
334
342
* @since 12.2.1.4
335
343
*/
@@ -365,6 +373,8 @@ public ContinuousQueryCache(Supplier<NamedCache<K, V_BACK>> supplierCache, Filte
365
373
m_fReadOnly = transformer != null ;
366
374
m_nState = STATE_DISCONNECTED ;
367
375
376
+ // initialize Observable listener on whether a standard (non-lite) listener passed at construction time
377
+ m_fListeners = listener != null && fCacheValues ;
368
378
if (listener instanceof MapTriggerListener )
369
379
{
370
380
throw new IllegalArgumentException ("ContinuousQueryCache does not support MapTriggerListeners" );
@@ -458,13 +468,20 @@ public Filter getFilter()
458
468
459
469
/**
460
470
* Determine if this {@code ContinuousQueryCache} caches values locally.
471
+ * <p>
472
+ * Note: if {@link #addMapListener(MapListener, Filter, boolean) addMapListener} adds
473
+ * a standard (non-lite) listener or a filter to this {@link ObservableMap},
474
+ * cache values are always maintained locally. The locally cached values are
475
+ * used to filter events and to supply the {@link MapEvent#getOldValue() old}
476
+ * and {@link MapEvent#getNewValue() new} values for the events that it raises.
477
+ * Additionally, a non-null {@link #getTransformer() transformer} infers caches values being stored locally.
461
478
*
462
479
* @return {@code true} if this object caches values locally, and {@code false} if it
463
480
* relies on the underlying {@link NamedCache}
464
481
*/
465
482
public boolean isCacheValues ()
466
483
{
467
- return m_fCacheValues || isObserved ();
484
+ return m_fCacheValues || isObserved () || getTransformer () != null ;
468
485
}
469
486
470
487
/**
@@ -478,7 +495,7 @@ public boolean isCacheValues()
478
495
* <p>
479
496
*
480
497
* @param fCacheValues pass {@code true} to enable local caching, or {@code false}
481
- * to disable it
498
+ * to disable it. Override of {@code false} described in {@link #isCacheValues()}.
482
499
*/
483
500
public synchronized void setCacheValues (boolean fCacheValues )
484
501
{
@@ -572,13 +589,13 @@ protected ObservableMap<K, V_FRONT> ensureInternalCache()
572
589
m_mapLocal = instantiateInternalCache ();
573
590
574
591
MapListener mapListener = m_mapListener ;
592
+ boolean fLite = !isCacheValues ();
575
593
if (mapListener != null )
576
594
{
577
595
// the initial listener has to hear the initial events
578
596
ensureEventQueue ();
579
597
ensureListenerSupport ().addListener (
580
- instantiateEventRouter (mapListener , false ), (Filter ) null , false );
581
- m_fListeners = true ;
598
+ instantiateEventRouter (mapListener , fLite ), (Filter ) null , fLite );
582
599
}
583
600
}
584
601
return m_mapLocal ;
@@ -1678,8 +1695,8 @@ protected synchronized void configureSynchronization(boolean fReload)
1678
1695
changeState (STATE_CONFIGURING );
1679
1696
m_ldtConnectionTimestamp = getSafeTimeMillis ();
1680
1697
1681
- NamedCache cache = getCache ();
1682
- Filter filter = getFilter ();
1698
+ NamedCache cache = getCache ();
1699
+ Filter filter = getFilter ();
1683
1700
boolean fCacheValues = isCacheValues ();
1684
1701
1685
1702
// get the old filters and listeners
0 commit comments