@Override public Object wrap(Object obj) { if (obj instanceof byte[]) return new WrappedByteArray((byte[]) obj); return obj; }
@Override public WrappedByteArray readObject(ObjectInput input) throws IOException { byte[] bytes = MarshallUtil.unmarshallByteArray(input); boolean hasHashCode = input.readBoolean(); if (hasHashCode) { return new WrappedByteArray(bytes, input.readInt()); } else { return new WrappedByteArray(bytes); } } }
private WrappedByteArray toUserObject(byte[] bytes) { return new WrappedByteArray(bytes); } }
boolean removeClientListener(byte[] listenerId, Cache cache) { Object sender = eventSenders.get(new WrappedByteArray(listenerId)); if (sender != null) { cache.removeListener(sender); return true; } else return false; }
void removeEntry(HotRodHeader header, Subject subject, byte[] key, byte[] value) { log.trace("Call removeEntry"); WrappedByteArray keyWrappped = new WrappedByteArray(key); WrappedByteArray valueWrapped = new WrappedByteArray(value); server.multimap(header, subject).remove(keyWrappped, valueWrapped).whenComplete(handleBoolean(header)); }
void containsEntry(HotRodHeader header, Subject subject, byte[] key, byte[] value) { log.trace("Call containsEntry"); WrappedByteArray keyWrappped = new WrappedByteArray(key); WrappedByteArray valueWrapped = new WrappedByteArray(value); server.multimap(header, subject).containsEntry(keyWrappped, valueWrapped).whenComplete(handleBoolean(header)); }
TestCounterNotificationManager(HotRodClient client) { this.client = client; byte[] listenerId = new byte[16]; ThreadLocalRandom.current().nextBytes(listenerId); this.listenerId = new WrappedByteArray(listenerId); userListenerList = new ConcurrentHashMap<>(); }
void get(HotRodHeader header, Subject subject, byte[] key) { if (trace) { log.trace("Call get"); } WrappedByteArray keyWrappped = new WrappedByteArray(key); server.multimap(header, subject).get(keyWrappped).whenComplete( (result, throwable) -> handleGet(header, result, throwable)); }
void removeKey(HotRodHeader header, Subject subject, byte[] key) { if (trace) { log.trace("Call removeKey"); } WrappedByteArray keyWrappped = new WrappedByteArray(key); server.multimap(header, subject).remove(keyWrappped).whenComplete(handleBoolean(header)); }
private String convertToStrWrappedArray(String keyAsString) { WrappedByteArray wrappedByteArray = new WrappedByteArray(keyAsString.getBytes(UTF_8)); return STRING_MAPPER.getStringMapping(wrappedByteArray); }
void containsKey(HotRodHeader header, Subject subject, byte[] key) { log.trace("Call containsKey"); WrappedByteArray keyWrappped = new WrappedByteArray(key); server.multimap(header, subject).containsKey(keyWrappped).whenComplete(handleBoolean(header)); }
void getWithMetadata(HotRodHeader header, Subject subject, byte[] key) { if (trace) { log.trace("Call getWithMetadata"); } WrappedByteArray keyWrappped = new WrappedByteArray(key); server.multimap(header, subject).getEntry(keyWrappped).whenComplete((entry, throwable) -> handleGetWithMetadata(header, entry, throwable)); }
private ContextValue performGet(byte[] key) { TestGetWithMetadataResponse response = client.getWithMetadata(key, 0); ContextValue contextValue = response.data .map(bytes -> new ContextValue(response.dataVersion, (byte) 0, bytes)) .orElseGet(RemoteTransaction::nonExisting); txContext.put(new WrappedByteArray(key), contextValue); return contextValue; }
private byte[] get(byte[] key) { log.debugf("GET[%s] (%s)", xid, printArray(key, true)); ContextValue value = txContext.get(new WrappedByteArray(key)); if (value != null) { return value.value; } return performGet(key).value; }
public TestCounterEventResponse(byte version, long messageId, HotRodOperation operation, ByteBuf buffer) { super(version, messageId, "", (byte) 0, operation, OperationStatus.Success, 0, null); counterName = ExtendedByteBuf.readString(buffer); listenerId = new WrappedByteArray(ExtendedByteBuf.readRangedBytes(buffer)); byte counterState = buffer.readByte(); counterEvent = new CounterEventImpl(buffer.readLong(), decodeOldState(counterState), buffer.readLong(), decodeNewState(counterState)); }
public void testEqualsAndHashCode() throws Exception { StreamingMarshaller marshaller = extractGlobalMarshaller(cache(0).getCacheManager()); Pojo pojo = new Pojo(); WrappedBytes wb = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); WrappedBytes wb2 = new WrappedByteArray(marshaller.objectToByteBuffer(pojo)); assertTrue(wb2.hashCode() == wb.hashCode()); assertEquals(wb, wb2); }
public void testMarshallingCommandWithBigByteArrayKey() throws Exception { byte[] cacheKey = getBigByteArray(); ClusteredGetCommand command = new ClusteredGetCommand(new WrappedByteArray(cacheKey), ByteString.fromString("c"), 0, EnumUtil.EMPTY_BIT_SET); byte[] bytes = marshaller.objectToByteBuffer(command); ClusteredGetCommand readCommand = (ClusteredGetCommand) marshaller.objectFromByteBuffer(bytes); assertEquals(readCommand, command); }
public void set(byte[] key, byte[] value, int lifespan, int maxIdle) { log.debugf("SET[%s] (%s, %s, %s, &s)", xid, printArray(key, true), printArray(value, true), lifespan, maxIdle); ContextValue contextValue = txContext.computeIfAbsent(new WrappedByteArray(key), RemoteTransaction::notRead); contextValue.set(value, lifespan, maxIdle); }
private void putIntoStore(String key, String value) throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); CacheWriter<String, String> writer = TestingUtil.getFirstWriter(testCache); Object writerKey = key; Object writerValue = value; if (storage == StorageType.OFF_HEAP) { GlobalMarshaller gm = TestingUtil.extractGlobalMarshaller(testCache.getCacheManager()); writerKey = new WrappedByteArray(gm.objectToByteBuffer(key)); writerValue = new WrappedByteArray(gm.objectToByteBuffer(value)); } MarshalledEntry entry = new MarshalledEntryImpl(writerKey, writerValue, null, null); writer.write(entry); }
private boolean isEntryInStore(String key) throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); CacheLoader<String, String> loader = TestingUtil.getFirstLoader(testCache); Object loaderKey = key; if (storage == StorageType.OFF_HEAP) { GlobalMarshaller gm = TestingUtil.extractGlobalMarshaller(testCache.getCacheManager()); loaderKey = new WrappedByteArray(gm.objectToByteBuffer(key)); } return loader.contains(loaderKey); }