public QueryInterceptor(SearchIntegrator searchFactory, KeyTransformationHandler keyTransformationHandler, IndexModificationStrategy indexingMode, ConcurrentMap<GlobalTransaction, Map<Object, Object>> txOldValues, AdvancedCache<?, ?> cache) { this.searchFactory = searchFactory; this.keyTransformationHandler = keyTransformationHandler; this.indexingMode = indexingMode; this.txOldValues = txOldValues; this.cache = cache; this.valueDataConversion = cache.getValueDataConversion(); this.keyDataConversion = cache.getKeyDataConversion(); }
@Override public DataConversion getValueDataConversion() { return cache.getValueDataConversion(); }
@Override public void setEnvironment(Cache<Object, Object> cache, Set<Object> inputKeys) { this.cache = cache; this.indexUpdater = new IndexUpdater(cache); ComponentRegistry componentRegistry = SecurityActions.getCacheComponentRegistry(cache.getAdvancedCache()); this.clusteringDependentLogic = componentRegistry.getComponent(ClusteringDependentLogic.class); if (everywhereKeys != null && everywhereKeys.size() > 0) keys.addAll(everywhereKeys); if (inputKeys != null && inputKeys.size() > 0) keys.addAll(inputKeys); valueDataConversion = cache.getAdvancedCache().getValueDataConversion(); }
public Map<String, ?> convertParameters(TaskContext context) { if (!context.getParameters().isPresent()) return null; Map<String, ?> contextParams = context.getParameters().get(); Map<String, Object> converted = new HashMap<>(contextParams.size()); if (context.getCache().isPresent()) { DataConversion valueDataConversion = context.getCache().get().getAdvancedCache().getValueDataConversion(); MediaType requestMediaType = valueDataConversion.getRequestMediaType(); contextParams.forEach((s, o) -> { Object c = requestMediaType == null ? o : valueDataConversion.convert(o, valueDataConversion.getRequestMediaType(), APPLICATION_OBJECT); converted.put(s, c); }); return converted; } else { return contextParams; } }
protected AdvancedCache<?, ?> wrapCache(AdvancedCache<?, ?> cache, boolean isIndexed) { DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion(); if (valueDataConversion.isStorageFormatFilterable()) { cache = cache.withEncoding(IdentityEncoder.class); } return cache; }
public QueryInterceptor(SearchIntegrator searchFactory, IndexModificationStrategy indexingMode, Cache cache) { this.searchFactory = searchFactory; this.indexingMode = indexingMode; this.cache = cache; this.valueDataConversion = cache.getAdvancedCache().getValueDataConversion(); this.keyDataConversion = cache.getAdvancedCache().getKeyDataConversion(); }
boolean isObjectStorage() { MediaType storageMediaType = cache.getAdvancedCache().getValueDataConversion().getStorageMediaType(); return APPLICATION_OBJECT.match(storageMediaType); }
if (filterFactory.equals(converterFactory)) { List<byte[]> binaryParams = binaryFilterParams.isEmpty() ? binaryConverterParams : binaryFilterParams; CacheEventFilterConverter<byte[], byte[], byte[]> filterConverter = getFilterConverter(cache.getValueDataConversion(), h.getValueMediaType(), filterFactory, useRawData, binaryParams); filter = filterConverter; converter = filterConverter; } else { filter = getFilter(cache.getValueDataConversion(), h.getValueMediaType(), filterFactory, useRawData, binaryFilterParams); converter = getConverter(cache.getValueDataConversion(), h.getValueMediaType(), converterFactory, useRawData, binaryConverterParams); filter = getFilter(cache.getValueDataConversion(), h.getValueMediaType(), filterFactory, useRawData, binaryFilterParams); converter = null; converter = getConverter(cache.getValueDataConversion(), h.getValueMediaType(), converterFactory, useRawData, binaryConverterParams); } else { filter = null;
private <T> CompletableFuture<T> invokeTask(TaskContext context, ServerTaskWrapper<T> task) { ServerTaskRunner runner = runnerFactory.getRunner(task.getExecutionMode()); launderParameters(context); MediaType requestMediaType = context.getCache().map(c -> c.getAdvancedCache().getValueDataConversion().getRequestMediaType()).orElse(MediaType.MATCH_ALL); context.getCache().ifPresent(c -> context.cache(c.getAdvancedCache().withMediaType(APPLICATION_OBJECT_TYPE, APPLICATION_OBJECT_TYPE))); return runner.execute(task.getName(), context).thenApply(r -> (T) scriptConversions.convertToRequestType(r, APPLICATION_OBJECT, requestMediaType)); }
@Override public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable { DataConversion valueDataConversion = cache.wired().getValueDataConversion(); assertNotNull(valueDataConversion); Object value = command.getValue(); assertEquals(i, valueDataConversion.fromStorage(value)); return invokeNext(ctx, command); } }
AdvancedCache<Object, Object> advancedCache = cache.getAdvancedCache(); DataConversion valueDataConversion = advancedCache.getValueDataConversion(); Function<Object, Object> unmarshaller = p -> valueDataConversion.convert(p, requestValueType, APPLICATION_OBJECT); MediaType storageMediaType = advancedCache.getValueDataConversion().getStorageMediaType();
@Override public void setEnvironment(Cache<Object, Object> cache, Set<Object> inputKeys) { AdvancedCache<Object, Object> unwrapped = SecurityActions.getUnwrappedCache(cache).getAdvancedCache(); if (unwrapped.getCacheConfiguration().memory().storageType() == StorageType.OBJECT) { this.cache = unwrapped.withWrapping(ByteArrayWrapper.class, IdentityWrapper.class); } else { this.cache = cache; //todo [anistor] why not `unwrapped` instead ? do we need security for mass indexing ? } SearchIntegrator searchIntegrator = ComponentRegistryUtils.getSearchIntegrator(unwrapped); KeyTransformationHandler keyTransformationHandler = ComponentRegistryUtils.getKeyTransformationHandler(unwrapped); TimeService timeService = ComponentRegistryUtils.getTimeService(unwrapped); this.indexUpdater = new IndexUpdater(searchIntegrator, keyTransformationHandler, timeService); this.clusteringDependentLogic = SecurityActions.getClusteringDependentLogic(unwrapped); if (everywhereKeys != null) keys.addAll(everywhereKeys); if (inputKeys != null) keys.addAll(inputKeys); keyDataConversion = unwrapped.getKeyDataConversion(); valueDataConversion = unwrapped.getValueDataConversion(); }
MediaType requestMediaType = context.getCache().map(c -> c.getAdvancedCache().getValueDataConversion().getRequestMediaType()).orElse(MediaType.MATCH_ALL); Bindings userBindings = context.getParameters() .map(p -> {
@Test(dataProvider = "capacityTest") public void testCapacity(int inserts, int nodeExpected) { caches().forEach(c -> { DataContainer container = c.getAdvancedCache().getDataContainer(); // Just reuse same value Object value = c.getAdvancedCache().getValueDataConversion().toStorage("foo"); Metadata metadata = new EmbeddedMetadata.Builder().build(); // We just insert into data container directly - as we can guarantee same size then (this can't happen // in a real cache, but we can control the size easily) for (int i = 0; i < inserts; ++i) { Object key = c.getAdvancedCache().getKeyDataConversion().toStorage(i); container.put(key, value, metadata); } }); ClusterCacheStats stats = TestingUtil.extractComponent(cache(0), ClusterCacheStats.class); assertEquals(handleModeEstimate(nodeExpected, cacheMode), stats.getRequiredMinimumNumberOfNodes()); } }
@Override public void call() throws Exception { ComponentRegistry registry = cm.getCache().getAdvancedCache().getComponentRegistry(); testWith(DataConversion.DEFAULT_KEY, registry); testWith(DataConversion.DEFAULT_VALUE, registry); testWith(DataConversion.IDENTITY_KEY, registry); testWith(DataConversion.IDENTITY_VALUE, registry); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.compatibility().enable(); cm.defineConfiguration("compat", builder.build()); AdvancedCache<?, ?> compat = cm.getCache("compat").getAdvancedCache(); ComponentRegistry compatRegistry = compat.getComponentRegistry(); testWith(compat.getKeyDataConversion(), compatRegistry); testWith(compat.getValueDataConversion(), compatRegistry); AdvancedCache<?, ?> wrapped = compat.withEncoding(IdentityEncoder.class).withWrapping(IdentityWrapper.class); ComponentRegistry wrappedRegistry = wrapped.getComponentRegistry(); testWith(wrapped.getKeyDataConversion(), wrappedRegistry); testWith(wrapped.getValueDataConversion(), wrappedRegistry); } });
public void testStoreAsBinaryOnBoth() { ConfigurationBuilder c = new ConfigurationBuilder(); c.memory().storageType(StorageType.BINARY).build(); ecm = TestCacheManagerFactory.createCacheManager(c); ecm.getCache().put(key, value); DataConversion keyDataConversion = ecm.getCache().getAdvancedCache().getKeyDataConversion(); DataConversion valueDataConversion = ecm.getCache().getAdvancedCache().getValueDataConversion(); DataContainer<?, ?> dc = ecm.getCache().getAdvancedCache().getDataContainer(); InternalCacheEntry entry = dc.iterator().next(); Object key = entry.getKey(); Object value = entry.getValue(); assertTrue(key instanceof WrappedBytes); assertEquals(keyDataConversion.fromStorage(key), this.key); assertTrue(value instanceof WrappedBytes); assertEquals(valueDataConversion.fromStorage(value), this.value); } }