org.redisson.client.handler.State Java Examples

The following examples show how to use org.redisson.client.handler.State. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public List<ByteRecord> decode(List<Object> parts, State state) {
    List<List<Object>> list = (List<List<Object>>) (Object) parts;
    List<ByteRecord> result = new ArrayList<>(parts.size()/2);

    for (List<Object> entries : list) {
        List<List<Object>> streamEntries = (List<List<Object>>) entries.get(1);
        if (streamEntries.isEmpty()) {
            continue;
        }

        String name = (String) entries.get(0);
        for (List<Object> se : streamEntries) {
            ByteRecord record = StreamRecords.newRecord()
                                    .in(name.getBytes())
                                    .withId(RecordId.of(se.get(0).toString()))
                                    .ofBytes((Map<byte[], byte[]>) se.get(1));
            result.add(record);
        }
    }
    return result;
}
 
Example #2
Source File: GeoWaveMetadataCodec.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public Object decode(final ByteBuf buf, final State state) throws IOException {
  final byte[] primaryId = new byte[buf.readUnsignedByte()];
  final byte[] secondaryId = new byte[buf.readUnsignedByte()];
  final byte[] visibility;
  if (visibilityEnabled) {
    visibility = new byte[buf.readUnsignedByte()];
  } else {
    visibility = new byte[0];
  }
  final byte[] value = new byte[buf.readUnsignedShort()];
  buf.readBytes(primaryId);
  buf.readBytes(secondaryId);
  if (visibilityEnabled) {
    buf.readBytes(visibility);
  }
  buf.readBytes(value);
  return new GeoWaveMetadata(primaryId, secondaryId, visibility, value);
}
 
Example #3
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public StreamInfo.XInfoConsumers decode(List<Object> parts, State state) {
    List<Object> result = new ArrayList<>();
    for (List<Object> part: (List<List<Object>>) (Object)parts) {
        Map<String, Object> res = new HashMap<>();
        res.put("name", part.get(1));
        res.put("pending", part.get(3));
        res.put("idle", part.get(5));
        List<Object> list = res.entrySet().stream()
                .flatMap(e -> Stream.of(e.getKey(), e.getValue()))
                .collect(Collectors.toList());
        result.add(list);
    }

    return StreamInfo.XInfoConsumers.fromList(groupName, result);
}
 
Example #4
Source File: ObjectListReplayDecoder2.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> decode(List<Object> parts, State state) {
    for (int i = 0; i < parts.size(); i++) {
        Object object = parts.get(i);
        if (object instanceof List) {
            if (((List) object).isEmpty()) {
                parts.set(i, null);
            }
        }
    }
    return (List<T>) parts;
}
 
Example #5
Source File: ListObjectDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum == 0) {
        return StringCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #6
Source File: RedissonReactiveStringCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    if (buf.readableBytes() == 0) {
        System.out.println("null:");
        return null;
    }
    
    byte[] result = new byte[buf.readableBytes()];
    buf.readBytes(result);
    return result;
}
 
Example #7
Source File: RedissonStreamCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public StreamInfo.XInfoStream decode(List<Object> parts, State state) {
    Map<String, Object> res = new HashMap<>();
    res.put("length", parts.get(1));
    res.put("radix-tree-keys", parts.get(3));
    res.put("radix-tree-nodes", parts.get(5));
    res.put("groups", parts.get(7));
    res.put("last-generated-id", parts.get(9).toString());

    List<?> firstEntry = (List<?>) parts.get(11);
    if (firstEntry != null) {
        StreamMessageId firstId = StreamIdConvertor.INSTANCE.convert(firstEntry.get(0));
        Map<Object, Object> firstData = (Map<Object, Object>) firstEntry.get(1);
        res.put("first-entry", firstData);
    }

    List<?> lastEntry = (List<?>) parts.get(13);
    if (lastEntry != null) {
        StreamMessageId lastId = StreamIdConvertor.INSTANCE.convert(lastEntry.get(0));
        Map<Object, Object> lastData = (Map<Object, Object>) lastEntry.get(1);
        res.put("last-entry", lastData);
    }

    List<Object> list = res.entrySet().stream()
                            .flatMap(e -> Stream.of(e.getKey(), e.getValue()))
                            .collect(Collectors.toList());
    return StreamInfo.XInfoStream.fromList(list);
}
 
Example #8
Source File: ObjectListReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> decode(List<Object> parts, State state) {
    if (reverse) {
        Collections.reverse(parts);
    }
    return (List<T>) parts;
}
 
Example #9
Source File: ObjectMapReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Map<K, V> decode(List<Object> parts, State state) {
    Map<K, V> result = new LinkedHashMap<>(parts.size()/2);
    for (int i = 0; i < parts.size(); i++) {
        if (i % 2 != 0) {
            result.put((K) parts.get(i-1), (V) parts.get(i));
        }
    }
    return result;
}
 
Example #10
Source File: GeoDistanceMapDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Map<Object, Object> decode(List<Object> parts, State state) {
    Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
    for (int i = 0; i < parts.size(); i++) {
        if (i % 2 != 0) {
            result.put(parts.get(i-1), parts.get(i));
       }
    }
    return result;
}
 
Example #11
Source File: ScoredSortedSetReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<ScoredEntry<T>> decode(List<Object> parts, State state) {
    List<ScoredEntry<T>> result = new ArrayList<>();
    for (int i = 0; i < parts.size(); i += 2) {
        result.add(new ScoredEntry<T>(((Number) parts.get(i+1)).doubleValue(), (T) parts.get(i)));
    }
    return result;
}
 
Example #12
Source File: PointDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Point decode(List<Object> parts, State state) {
    if (parts.isEmpty()) {
        return null;
    }

    Double longitude = (Double)parts.get(0);
    Double latitude = (Double)parts.get(1);
    return new Point(longitude, latitude);
}
 
Example #13
Source File: RedissonReactiveHashCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<Object> decode(List<Object> parts, State state) {
    List<Object> list = parts.stream().filter(e -> e != null).collect(Collectors.toList());
    if (list.isEmpty()) {
        return null;
    }
    return parts;
}
 
Example #14
Source File: RedissonTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    String str = buf.toString(CharsetUtil.UTF_8);
    buf.readerIndex(buf.readableBytes());
    try {
        Thread.sleep(2500);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return str;
}
 
Example #15
Source File: ScoredSortedSetReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Tuple> decode(List<Object> parts, State state) {
    Set<Tuple> result = new LinkedHashSet<Tuple>();
    for (int i = 0; i < parts.size(); i += 2) {
        result.add(new DefaultTuple((byte[])parts.get(i), ((Number)parts.get(i+1)).doubleValue()));
    }
    return result;
}
 
Example #16
Source File: Kryo5Codec.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    Kryo kryo = kryoPool.obtain();
    Input input = inputPool.obtain();
    try {
        input.setInputStream(new ByteBufInputStream(buf));
        return kryo.readClassAndObject(input);
    } finally {
        kryoPool.free(kryo);
        inputPool.free(input);
    }
}
 
Example #17
Source File: ObjectFirstScoreReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum % 2 != 0) {
        return DoubleCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #18
Source File: MapCacheScanResultReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public MapCacheScanResult<Object, Object> decode(List<Object> parts, State state) {
    Long pos = (Long) parts.get(0);
    Map<Object, Object> values = (Map<Object, Object>) parts.get(1);
    List<Object> idleKeys = (List<Object>) parts.get(2);
    return new MapCacheScanResult<Object, Object>(pos, values, idleKeys);
}
 
Example #19
Source File: ListObjectDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public T decode(List<Object> parts, State state) {
    if (parts.isEmpty()) {
        return null;
    }
    return (T) parts.get(index);
}
 
Example #20
Source File: ScoredSortedListReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum % 2 != 0) {
        return DoubleCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #21
Source File: ScoredSortedListReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<Tuple> decode(List<Object> parts, State state) {
    List<Tuple> result = new ArrayList<Tuple>();
    for (int i = 0; i < parts.size(); i += 2) {
        result.add(new DefaultTuple((byte[])parts.get(i), ((Number)parts.get(i+1)).doubleValue()));
    }
    return result;
}
 
Example #22
Source File: ScoredSortedListReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum % 2 != 0) {
        return DoubleCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #23
Source File: ScoredSortedSetReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum % 2 != 0) {
        return DoubleCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #24
Source File: PropertiesListDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Properties decode(List<Object> parts, State state) {
    Properties result = new Properties();
    for (int j = 0; j < parts.size(); j+=2) {
        Object key = parts.get(j);
        Object value = parts.get(j+1);
        result.put(key, value);
    }
    return result;
}
 
Example #25
Source File: ScoredSortedListReplayDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (paramNum % 2 != 0) {
        return DoubleCodec.INSTANCE.getValueDecoder();
    }
    return null;
}
 
Example #26
Source File: RedissonReactiveHashCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<Object> decode(List<Object> parts, State state) {
    List<Object> list = parts.stream().filter(e -> e != null).collect(Collectors.toList());
    if (list.isEmpty()) {
        return null;
    }
    return parts;
}
 
Example #27
Source File: StringMapDataDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> decode(ByteBuf buf, State state) {
    String value = buf.toString(CharsetUtil.UTF_8);
    Map<String, String> result = new HashMap<String, String>();
    for (String entry : value.split("\r\n|\n")) {
        String[] parts = entry.split(":");
        if (parts.length == 2) {
            result.put(parts[0], parts[1]);
        }
    }
    return result;
}
 
Example #28
Source File: ObjectMapDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
    if (mapDecoded) {
        return codec.getMapKeyDecoder();
    }
    
    if (pos++ % 2 == 0) {
        return codec.getMapKeyDecoder();
    }
    return codec.getMapValueDecoder();
}
 
Example #29
Source File: ObjectListReplayDecoder2.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> decode(List<Object> parts, State state) {
    for (int i = 0; i < parts.size(); i++) {
        Object object = parts.get(i);
        if (object instanceof List) {
            if (((List) object).isEmpty()) {
                parts.set(i, null);
            }
        }
    }
    return (List<T>) parts;
}
 
Example #30
Source File: StreamIdDecoder.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    String id = (String) StringCodec.INSTANCE.getValueDecoder().decode(buf, state);
    String[] parts = id.toString().split("-");
    if (parts.length == 1) {
        return null;
    }
    return new StreamMessageId(Long.valueOf(parts[0]), Long.valueOf(parts[1]));
}