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); } }
@Override public Object wrap(Object obj) { if (obj instanceof byte[]) return new WrappedByteArray((byte[]) obj); return obj; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; Class<?> oClass = o.getClass(); if (getClass() != oClass) { return WrappedBytes.class.isAssignableFrom(oClass) && equalsWrappedBytes((WrappedBytes) o); } WrappedByteArray that = (WrappedByteArray) o; return Arrays.equals(bytes, that.bytes); }
private static WrappedByteArray wrapId(byte[] id) { return new WrappedByteArray(id); }
@Override public Object unwrap(Object obj) { if (obj != null && obj.getClass().equals(WrappedByteArray.class)) return WrappedByteArray.class.cast(obj).getBytes(); 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); } } }
@Override protected <K, V> void matchEvent(EventWrapper<K, V, CacheEntryEvent<K, V>> eventWrapper, Matcher matcher) { CacheEntryEvent<?, ?> event = eventWrapper.getEvent(); Object instance = event.getValue(); if (instance != null) { if (instance.getClass() == WrappedByteArray.class) { instance = ((WrappedByteArray) instance).getBytes(); } matcher.match(eventWrapper, event.getType(), instance); } }
private WrappedByteArray toUserObject(byte[] bytes) { return new WrappedByteArray(bytes); } }
@Override protected <K, V> void matchEvent(EventWrapper<K, V, CacheEntryEvent<K, V>> eventWrapper, Matcher matcher) { CacheEntryEvent<?, ?> event = eventWrapper.getEvent(); Object instance = event.getValue(); if (instance != null) { if (instance.getClass() == WrappedByteArray.class) { instance = ((WrappedByteArray) instance).getBytes(); } matcher.match(eventWrapper, event.getType(), instance); } }
boolean removeClientListener(byte[] listenerId, Cache cache) { Object sender = eventSenders.get(new WrappedByteArray(listenerId)); if (sender != null) { cache.removeListener(sender); return true; } else return false; }
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 static WrappedByteArray byteArray() { return new WrappedByteArray(new byte[]{1}); }
private static TxWrite transform(Map.Entry<WrappedByteArray, ContextValue> entry) { ContextValue contextValue = entry.getValue(); if (contextValue.removed) { return TxWrite.remove(entry.getKey().getBytes(), ControlByte.REMOVE_OP.set(contextValue.control), contextValue.versionRead); } else { return TxWrite.put(entry.getKey().getBytes(), contextValue.value, contextValue.lifespan, contextValue.maxIdle, contextValue.control, contextValue.versionRead); } }
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)); }
@Override public int hash(Object o) { if (o instanceof byte[]) return hash((byte[]) o); else if (o instanceof WrappedByteArray) { return hash(((WrappedByteArray) o).getBytes()); } else if (o instanceof long[]) return hash((long[]) o); else if (o instanceof String) return hashString((String) o); else return hash(o.hashCode()); }
void removeClientListener(byte[] listenerId) { clientListeners.remove(new WrappedByteArray(listenerId)); }
@Override protected <K, V> void matchEvent(EventWrapper<K, V, CacheEntryEvent<K, V>> eventWrapper, Matcher matcher) { CacheEntryEvent<?, ?> event = eventWrapper.getEvent(); Object oldValue = event.getType() == Event.Type.CACHE_ENTRY_REMOVED ? ((CacheEntryRemovedEvent) event).getOldValue() : null; if (event.getType() == Event.Type.CACHE_ENTRY_MODIFIED) { oldValue = ((EventImpl) event).getOldValue(); } Object newValue = event.getValue(); if (event.getType() == Event.Type.CACHE_ENTRY_EXPIRED) { oldValue = newValue; // expired events have the expired value as newValue newValue = null; } if (oldValue != null || newValue != null) { if (oldValue != null && oldValue.getClass() == WrappedByteArray.class) { oldValue = ((WrappedByteArray) oldValue).getBytes(); } if (newValue != null && newValue.getClass() == WrappedByteArray.class) { newValue = ((WrappedByteArray) newValue).getBytes(); } matcher.matchDelta(eventWrapper, event.getType(), oldValue, newValue, joiningEvent, updatedEvent, leavingEvent); } }
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)); }
private ClientNotificationManager add(WrappedByteArray id, ClientNotificationManager manager, byte version, String counterName, Channel channel, VersionedEncoder encoder, ByRef<ListenerOperationStatus> status) { boolean useChannel = false; if (manager == null) { manager = new ClientNotificationManager(id.getBytes(), counterManager, channel, encoder); useChannel = true; } if (manager.addCounterListener(version, counterName)) { status.set(useChannel ? ListenerOperationStatus.OK_AND_CHANNEL_IN_USE : ListenerOperationStatus.OK); return manager; } else { status.set(ListenerOperationStatus.COUNTER_NOT_FOUND); return null; } }