@Override public void onMessage(Message message, @Nullable byte[] pattern) { if (message == null || ObjectUtils.isEmpty(message.getChannel()) || ObjectUtils.isEmpty(message.getBody())) { return; } doHandleMessage(message); }
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 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); } } }
private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
@Override @SuppressWarnings("unchecked") public void onMessage(Message message, byte[] pattern) { byte[] messageChannel = message.getChannel(); byte[] messageBody = message.getBody();
@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); }
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); } }); } }
protected String getChannel(final Message message) { return serializer.deserialize(message.getChannel()); }
protected String getChannel(final Message message) { return serializer.deserialize(message.getChannel()); }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { if (message == null || ObjectUtils.isEmpty(message.getChannel()) || ObjectUtils.isEmpty(message.getBody())) { return; } doHandleMessage(message); }
@Override public void onMessage(Message message, @Nullable byte[] pattern) { if (message == null || ObjectUtils.isEmpty(message.getChannel()) || ObjectUtils.isEmpty(message.getBody())) { return; } doHandleMessage(message); }
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 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); } } }
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 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, 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); } } }
private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
private boolean isKeyExpirationMessage(Message message) { if (message == null || message.getChannel() == null || message.getBody() == null) { return false; } return BinaryKeyspaceIdentifier.isValid(message.getBody()); } }
@Override public void onMessage(Message message, byte[] pattern) { Msg msg = (Msg) serializer.deserialize(message.getBody()); if (LOGGER.isDebugEnabled()){ LOGGER.debug("receive msg {} from channel {}",msg.getType(),new String(message.getChannel())); } if (msg.getMsgType() == Msg.COMMAND && msg.getCommandId() != null && socketProperties.isCommandTimeoutEnabled()){ if (LOGGER.isDebugEnabled()){ LOGGER.debug("remove command id {}",msg.getCommandId()); } socketRegister.removeCommandSend(msg.getCommandId()); } socketSender.sendToSocket(msg); } }
@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); }