private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
/** * Extract the message body from the given Redis message. * * @param message the Redis <code>Message</code> * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { if (serializer != null) { return serializer.deserialize(message.getBody()); } return message.getBody(); }
private void dispatchMessage(Collection<MessageListener> listeners, final Message message, final byte[] pattern) { final byte[] source = (pattern != null ? pattern.clone() : message.getChannel()); for (final MessageListener messageListener : listeners) { taskExecutor.execute(() -> processMessage(messageListener, message, source)); } }
@Override protected void doHandleMessage(Message message) { publishEvent(new RedisKeyExpiredEvent(message.getBody())); }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { Collection<MessageListener> listeners = null; // if it's a pattern, disregard channel if (pattern != null && pattern.length > 0) { listeners = patternMapping.get(new ByteArrayWrapper(pattern)); } else { pattern = null; // do channel matching first listeners = channelMapping.get(new ByteArrayWrapper(message.getChannel())); } if (!CollectionUtils.isEmpty(listeners)) { dispatchMessage(listeners, message, pattern); } } }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { if (message == null || ObjectUtils.isEmpty(message.getChannel()) || ObjectUtils.isEmpty(message.getBody())) { return; } doHandleMessage(message); }
/** * Extract the message body from the given Redis message. * * @param message the Redis <code>Message</code> * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { if (serializer != null) { return serializer.deserialize(message.getBody()); } return message.getBody(); }
private void dispatchMessage(Collection<MessageListener> listeners, final Message message, final byte[] pattern) { final byte[] source = (pattern != null ? pattern.clone() : message.getChannel()); Executor executor = message.getChannel().length>32 ? logExecutor:taskExecutor; for (final MessageListener messageListener : listeners) { executor.execute(new Runnable() { @Override public void run() { processMessage(messageListener, message, source); } }); } }
@Override @SuppressWarnings("unchecked") public void onMessage(Message message, byte[] pattern) { byte[] messageChannel = message.getChannel(); byte[] messageBody = message.getBody(); .deserialize(message.getBody()); handleCreated(loaded, channel); return;
/** * Extract the message body from the given Redis message. * * @param message the Redis <code>Message</code> * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { if (serializer != null) { return serializer.deserialize(message.getBody()); } return message.getBody(); }
protected String getChannel(final Message message) { return serializer.deserialize(message.getChannel()); }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { if (!isKeyExpirationMessage(message)) { return; } byte[] key = message.getBody(); byte[] phantomKey = ByteUtils.concat(key, converter.getConversionService().convert(KeyspaceIdentifier.PHANTOM_SUFFIX, byte[].class)); Map<byte[], byte[]> hash = ops.execute((RedisCallback<Map<byte[], byte[]>>) connection -> { Map<byte[], byte[]> hash1 = connection.hGetAll(phantomKey); if (!CollectionUtils.isEmpty(hash1)) { connection.del(phantomKey); } return hash1; }); Object value = converter.read(Object.class, new RedisData(hash)); String channel = !ObjectUtils.isEmpty(message.getChannel()) ? converter.getConversionService().convert(message.getChannel(), String.class) : null; RedisKeyExpiredEvent event = new RedisKeyExpiredEvent(channel, key, value); ops.execute((RedisCallback<Void>) connection -> { connection.sRem(converter.getConversionService().convert(event.getKeyspace(), byte[].class), event.getId()); new IndexWriter(connection, converter).removeKeyFromIndexes(event.getKeyspace(), event.getId()); return null; }); publishEvent(event); }
protected String getInfo(final Message message) { return serializer.deserialize(message.getBody()); }
protected String getChannel(final Message message) { return serializer.deserialize(message.getChannel()); }
private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
@Override protected void doSubscribe(String topic, Consumer<String> consumer) { new Thread(() -> redisTemplate.execute((RedisCallback<Void>) connection -> { connection.subscribe((message, pattern) -> consumer.accept(new String(message.getBody(), StandardCharsets.UTF_8)) , topic.getBytes()); return null; })).start(); }
private void dispatchMessage(Collection<MessageListener> listeners, final Message message, final byte[] pattern) { final byte[] source = (pattern != null ? pattern.clone() : message.getChannel()); for (final MessageListener messageListener : listeners) { taskExecutor.execute(() -> processMessage(messageListener, message, source)); } }
private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
protected String getInfo(final Message message) { return serializer.deserialize(message.getBody()); }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { Collection<MessageListener> listeners = null; // if it's a pattern, disregard channel if (pattern != null && pattern.length > 0) { listeners = patternMapping.get(new ByteArrayWrapper(pattern)); } else { pattern = null; // do channel matching first listeners = channelMapping.get(new ByteArrayWrapper(message.getChannel())); } if (!CollectionUtils.isEmpty(listeners)) { dispatchMessage(listeners, message, pattern); } } }