@Override public ByteBuf encode(Object value) { try { return LocalCachedMessageCodec.INSTANCE.getValueEncoder().encode(value); } catch (IOException e) { throw new IllegalArgumentException(e); } }
protected ByteBuf encode(Object obj) { try { return codec.getValueEncoder().encode(obj); } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public ByteBuf encode(Object value) { try { return LocalCachedMessageCodec.INSTANCE.getValueEncoder().encode(value); } catch (IOException e) { throw new IllegalArgumentException(e); } }
protected ByteBuf encode(Object obj) { try { return codec.getValueEncoder().encode(obj); } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public String getName(Class<?> entityClass, Class<?> idFieldClass, String idFieldName, Object idValue) { try { String encode = bytesToHex(codec.getMapKeyEncoder().encode(idValue)); return "redisson_live_object:{"+ encode + "}:" + entityClass.getName() + ":" + idFieldName + ":" + idFieldClass.getName(); } catch (IOException ex) { throw new IllegalArgumentException("Unable to encode \"" + idFieldName + "\" [" + idValue + "] into byte[]", ex); } }
@Override public String getFieldReferenceName(Class<?> entityClass, Object idValue, Class<?> fieldClass, String fieldName, Object fieldValue) { try { String encode = bytesToHex(codec.getMapKeyEncoder().encode(idValue)); return "redisson_live_object_field:{" + encode + "}:" + entityClass.getName() + ":" + fieldName + ":" + fieldClass.getName(); } catch (IOException ex) { throw new IllegalArgumentException("Unable to encode \"" + fieldName + "\" [" + fieldValue + "] into byte[]", ex); } }
@Override public String getFieldReferenceName(Class<?> entityClass, Object idValue, Class<?> fieldClass, String fieldName, Object fieldValue) { try { String encode = bytesToHex(codec.getMapKeyEncoder().encode(idValue)); return "redisson_live_object_field:{" + encode + "}:" + entityClass.getName() + ":" + fieldName + ":" + fieldClass.getName(); } catch (IOException ex) { throw new IllegalArgumentException("Unable to encode \"" + fieldName + "\" [" + fieldValue + "] into byte[]", ex); } }
@Override public String getName(Class<?> entityClass, Class<?> idFieldClass, String idFieldName, Object idValue) { try { String encode = bytesToHex(codec.getMapKeyEncoder().encode(idValue)); return "redisson_live_object:{"+ encode + "}:" + entityClass.getName() + ":" + idFieldName + ":" + idFieldClass.getName(); } catch (IOException ex) { throw new IllegalArgumentException("Unable to encode \"" + idFieldName + "\" [" + idValue + "] into byte[]", ex); } }
@Override public RFuture<Void> setAsync(Map<String, ?> buckets) { if (buckets.isEmpty()) { return RedissonPromise.newSucceededFuture(null); } List<Object> params = new ArrayList<Object>(buckets.size()); for (Entry<String, ?> entry : buckets.entrySet()) { params.add(entry.getKey()); try { params.add(codec.getValueEncoder().encode(entry.getValue())); } catch (IOException e) { throw new IllegalArgumentException(e); } } return commandExecutor.writeAsync(params.get(0).toString(), RedisCommands.MSET, params.toArray()); }
@Override public RFuture<Void> setAsync(Map<String, ?> buckets) { if (buckets.isEmpty()) { return RedissonPromise.newSucceededFuture(null); } List<Object> params = new ArrayList<Object>(buckets.size()); for (Entry<String, ?> entry : buckets.entrySet()) { params.add(entry.getKey()); try { params.add(codec.getValueEncoder().encode(entry.getValue())); } catch (IOException e) { throw new IllegalArgumentException(e); } } return commandExecutor.writeAsync(params.get(0).toString(), RedisCommands.MSET, params.toArray()); }
@Override public RFuture<Boolean> trySetAsync(Map<String, ?> buckets) { if (buckets.isEmpty()) { return RedissonPromise.newSucceededFuture(false); } List<Object> params = new ArrayList<Object>(buckets.size()); for (Entry<String, ?> entry : buckets.entrySet()) { params.add(entry.getKey()); try { params.add(codec.getValueEncoder().encode(entry.getValue())); } catch (IOException e) { throw new IllegalArgumentException(e); } } return commandExecutor.writeAsync(params.get(0).toString(), RedisCommands.MSETNX, params.toArray()); }
private byte[] encode(Object task) { // erase RedissonClient field to avoid its serialization Injector.inject(task, null); ByteBuf buf = null; try { buf = codec.getValueEncoder().encode(task); byte[] dst = new byte[buf.readableBytes()]; buf.readBytes(dst); return dst; } catch (IOException e) { throw new IllegalArgumentException(e); } finally { if (buf != null) { buf.release(); } } }
@Override public RFuture<Boolean> trySetAsync(Map<String, ?> buckets) { if (buckets.isEmpty()) { return RedissonPromise.newSucceededFuture(false); } List<Object> params = new ArrayList<Object>(buckets.size()); for (Entry<String, ?> entry : buckets.entrySet()) { params.add(entry.getKey()); try { params.add(codec.getValueEncoder().encode(entry.getValue())); } catch (IOException e) { throw new IllegalArgumentException(e); } } return commandExecutor.writeAsync(params.get(0).toString(), RedisCommands.MSETNX, params.toArray()); }
private byte[] encode(Object task) { // erase RedissonClient field to avoid its serialization Injector.inject(task, null); ByteBuf buf = null; try { buf = codec.getValueEncoder().encode(task); byte[] dst = new byte[buf.readableBytes()]; buf.readBytes(dst); return dst; } catch (IOException e) { throw new IllegalArgumentException(e); } finally { if (buf != null) { buf.release(); } } }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
@Override public void emit(K key, V value) { try { ByteBuf encodedKey = codec.getValueEncoder().encode(key); long hash = Hash.hash64(encodedKey); encodedKey.release(); int part = (int) Math.abs(hash % parts); String partName = name + ":" + part; RListMultimap<K, V> multimap = client.getListMultimap(partName, codec); multimap.put(key, value); if (timeout > 0 && !expirationsBitSet.get(part)) { multimap.expire(timeout, TimeUnit.MILLISECONDS); expirationsBitSet.set(part); } } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public void emit(K key, V value) { try { ByteBuf encodedKey = codec.getValueEncoder().encode(key); long hash = Hash.hash64(encodedKey); encodedKey.release(); int part = (int) Math.abs(hash % parts); String partName = name + ":" + part; RListMultimap<K, V> multimap = client.getListMultimap(partName, codec); multimap.put(key, value); if (timeout > 0 && !expirationsBitSet.get(part)) { multimap.expire(timeout, TimeUnit.MILLISECONDS); expirationsBitSet.set(part); } } catch (IOException e) { throw new IllegalArgumentException(e); } }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf bytes = null; try { LZ4Compressor compressor = factory.fastCompressor(); bytes = innerCodec.getValueEncoder().encode(in); ByteBuffer srcBuf = bytes.internalNioBuffer(bytes.readerIndex(), bytes.readableBytes()); int outMaxLength = compressor.maxCompressedLength(bytes.readableBytes()); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(outMaxLength + DECOMPRESSION_HEADER_SIZE); out.writeInt(bytes.readableBytes()); ByteBuffer outBuf = out.internalNioBuffer(out.writerIndex(), out.writableBytes()); int pos = outBuf.position(); compressor.compress(srcBuf, outBuf); int compressedLength = outBuf.position() - pos; out.writerIndex(out.writerIndex() + compressedLength); return out; } finally { if (bytes != null) { bytes.release(); } } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf bytes = null; try { LZ4Compressor compressor = factory.fastCompressor(); bytes = innerCodec.getValueEncoder().encode(in); ByteBuffer srcBuf = bytes.internalNioBuffer(bytes.readerIndex(), bytes.readableBytes()); int outMaxLength = compressor.maxCompressedLength(bytes.readableBytes()); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(outMaxLength + DECOMPRESSION_HEADER_SIZE); out.writeInt(bytes.readableBytes()); ByteBuffer outBuf = out.internalNioBuffer(out.writerIndex(), out.writableBytes()); int pos = outBuf.position(); compressor.compress(srcBuf, outBuf); int compressedLength = outBuf.position() - pos; out.writerIndex(out.writerIndex() + compressedLength); return out; } finally { if (bytes != null) { bytes.release(); } } } };