private Object unmarshall(byte[] bytes) { try { return this.ctx.getMarshaller().objectFromByteBuffer(bytes); } catch (IOException | ClassNotFoundException e) { throw new PersistenceException(e); } }
private byte[] marshall(Object key) { try { return (key instanceof WrappedByteArray) ? ((WrappedByteArray) key).getBytes() : this.ctx.getMarshaller().objectToByteBuffer(key); } catch (IOException | InterruptedException e) { throw new PersistenceException(e); } }
private Object unmarshall(byte[] bytes) throws IOException, ClassNotFoundException { if (bytes == null) return null; return ctx.getMarshaller().objectFromByteBuffer(bytes); }
private byte[] marshall(Object entry) throws IOException, InterruptedException { return ctx.getMarshaller().objectToByteBuffer(entry); }
private Object unmarshall(byte[] bytes) { try { return this.ctx.getMarshaller().objectFromByteBuffer(bytes); } catch (IOException | ClassNotFoundException e) { throw new PersistenceException(e); } }
private Object unmarshall(String contentType, byte[] b) throws IOException, ClassNotFoundException { if (configuration.rawValues()) { return b; } else { if (isTextContentType(contentType)) { return new String(b); // TODO: use response header Content Encoding } else { return ctx.getMarshaller().objectFromByteBuffer(b); } } }
private byte[] marshall(Object key) { try { return (key instanceof WrappedByteArray) ? ((WrappedByteArray) key).getBytes() : this.ctx.getMarshaller().objectToByteBuffer(key); } catch (IOException | InterruptedException e) { throw new PersistenceException(e); } }
public MarshalledEntry<K,V> _load(Object key, boolean loadValue, boolean loadMetadata) { Scanner scanner; try { scanner = connector.createScanner(tableName, authorizations); byte[] keyBytes = ctx.getMarshaller().objectToByteBuffer(key); scanner.setRange(new Range(new Text(keyBytes))); } catch (TableNotFoundException e) { throw new PersistenceException(e); } catch (IOException | InterruptedException e) { throw new PersistenceException("Unable to serialize key " + key, e); } Iterator<Map.Entry<Key,Value>> iterator = scanner.iterator(); Map.Entry<Key,Value> entry = iterator.hasNext() ? iterator.next() : null; return decodeEntry(entry, key, loadValue, loadMetadata); }
@Override public void init(InitializationContext ctx) { configuration = ctx.getConfiguration(); marshaller = ctx.getMarshaller(); marshalledEntryFactory = ctx.getMarshalledEntryFactory(); byteBufferFactory = ctx.getByteBufferFactory(); timeService = ctx.getTimeService(); maxKeyLength = configuration.maxNodeSize() - IndexNode.RESERVED_SPACE; }
private byte[] marshall(String contentType, MarshalledEntry entry) throws IOException, InterruptedException { if (configuration.rawValues()) { return (byte[]) entry.getValue(); } else { if (isTextContentType(contentType)) { return (byte[]) entry.getValue(); } return ctx.getMarshaller().objectToByteBuffer(entry.getValue()); } }
@Override public Void call() throws Exception { try { final HashSet<MarshalledEntry> allInternalEntries = new HashSet<>(); dir.loadAllEntries(allInternalEntries, Integer.MAX_VALUE, ctx.getMarshaller()); for (MarshalledEntry me : allInternalEntries) { if (taskContext.isStopped()) break; if (filter == null || filter.accept(me.getKey())) { task.processEntry(me, taskContext); } } return null; } catch (Exception e) { log.errorExecutingParallelStoreTask(e); throw e; } } });
@Override public Void call() throws Exception { try { final HashSet<MarshalledEntry> allInternalEntries = new HashSet<MarshalledEntry>(); dir.loadAllEntries(allInternalEntries, Integer.MAX_VALUE, ctx.getMarshaller()); for (MarshalledEntry me : allInternalEntries) { if (taskContext.isStopped()) break; if (filter == null || filter.shouldLoadKey(me.getKey())) { task.processEntry(me, taskContext); } } return null; } catch (Exception e) { log.errorExecutingParallelStoreTask(e); throw e; } } });
@Override public boolean delete(Object key) { log.trace("Deleting value for {} from the Accumulo cache for table {}.", key, tableName); try { byte[] keyBytes = ctx.getMarshaller().objectToByteBuffer(key); Mutation m = new Mutation(keyBytes); m.putDelete("", ""); try { batchWriter.addMutation(m); batchWriter.flush(); return true; } catch (MutationsRejectedException e) { throw new PersistenceException("Unable to write cache value to Accumulo", e); } } catch (IOException | InterruptedException e) { throw new PersistenceException("Unable to serialize key: " + key, e); } }
@Override public void init(InitializationContext ctx) { this.ctx = ctx; this.configuration = ctx.getConfiguration(); this.cache = ctx.getCache(); this.marshaller = ctx.getMarshaller(); this.storeName = makeStoreName(configuration, cache); this.initCount.incrementAndGet(); this.timeService = ctx.getTimeService(); }
@Override public Publisher<MarshalledEntry<K, V>> publishEntries(Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata) { return Flowable.defer(() -> { // Make sure that we update directories before we start iterating upon directories scanForUnknownDirectories(); return Flowable.fromIterable(openDirectories.values()); }) // We parallelize this since the loading below is blocking .parallel() .runOn(Schedulers.from(ctx.getExecutor())) .flatMap(dir -> { final Set<MarshalledEntry<K, V>> allInternalEntries = new HashSet<>(); dir.loadAllEntries(allInternalEntries, Integer.MAX_VALUE, ctx.getMarshaller()); return Flowable.fromIterable(allInternalEntries); }) .filter(me -> filter == null || filter.test(me.getKey())) .sequential(); }
this.key2StringMapper.setMarshaller(ctx.getMarshaller()); this.path = configuration.path(); try {
@Override public void init(InitializationContext ctx) { this.configuration = ctx.getConfiguration(); this.emfRegistry = ctx.getCache().getAdvancedCache().getComponentRegistry().getGlobalComponentRegistry().getComponent(EntityManagerFactoryRegistry.class); this.marshallerEntryFactory = ctx.getMarshalledEntryFactory(); this.marshaller = ctx.getMarshaller(); this.timeService = ctx.getTimeService(); this.executorService = ctx.getExecutor(); }
if (b == null) continue; MarshalledEntry me = (MarshalledEntry) ctx.getMarshaller().objectFromByteBuffer(b);
ByteSequence rowData = entry.getKey().getRowData(); @SuppressWarnings("unchecked") K key = (K) ctx.getMarshaller().objectFromByteBuffer(rowData.getBackingArray(), rowData.offset(), rowData.length()); if (filter.accept(key)) { MarshalledEntry<K,V> marshalledEntry = decodeEntry(entry, key, fetchValue, fetchMetadata);
@Override public void init(InitializationContext ctx) { this.configuration = ctx.getConfiguration(); this.cacheName = ctx.getCache().getName(); this.globalConfiguration = ctx.getCache().getCacheManager().getCacheManagerConfiguration(); this.marshalledEntryFactory = ctx.getMarshalledEntryFactory(); this.marshaller = ctx.getMarshaller(); this.timeService = ctx.getTimeService(); this.keyPartitioner = configuration.segmented() ? ctx.getKeyPartitioner() : null; this.isDistributedCache = ctx.getCache().getCacheConfiguration() != null && ctx.getCache().getCacheConfiguration().clustering().cacheMode().isDistributed(); }