Example usage for org.springframework.data.redis.connection Message getChannel

List of usage examples for org.springframework.data.redis.connection Message getChannel

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection Message getChannel.

Prototype

byte[] getChannel();

Source Link

Document

Returns the channel associated with the message.

Usage

From source file:org.springframework.data.redis.listener.RedisMessageListenerContainer.java

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(new Runnable() {
            public void run() {
                processMessage(messageListener, message, source);
            }//from   w  ww  .  j  a va  2s .c om
        });
    }
}

From source file:org.springframework.session.data.redis.RedisOperationsSessionRepository.java

@SuppressWarnings("unchecked")
public void onMessage(Message message, byte[] pattern) {
    byte[] messageChannel = message.getChannel();
    byte[] messageBody = message.getBody();
    if (messageChannel == null || messageBody == null) {
        return;/*from  w  ww .  j a v  a2s .c om*/
    }

    String channel = new String(messageChannel);

    if (channel.startsWith(getSessionCreatedChannelPrefix())) {
        // TODO: is this thread safe?
        Map<Object, Object> loaded = (Map<Object, Object>) this.defaultSerializer
                .deserialize(message.getBody());
        handleCreated(loaded, channel);
        return;
    }

    String body = new String(messageBody);
    if (!body.startsWith(getExpiredKeyPrefix())) {
        return;
    }

    boolean isDeleted = channel.endsWith(":del");
    if (isDeleted || channel.endsWith(":expired")) {
        int beginIndex = body.lastIndexOf(":") + 1;
        int endIndex = body.length();
        String sessionId = body.substring(beginIndex, endIndex);

        RedisSession session = getSession(sessionId, true);

        if (logger.isDebugEnabled()) {
            logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
        }

        cleanupPrincipalIndex(session);

        if (isDeleted) {
            handleDeleted(sessionId, session);
        } else {
            handleExpired(sessionId, session);
        }

        return;
    }
}

From source file:org.springframework.session.data.redis.SessionMessageListener.java

public void onMessage(Message message, byte[] pattern) {
    byte[] messageChannel = message.getChannel();
    byte[] messageBody = message.getBody();
    if (messageChannel == null || messageBody == null) {
        return;//w ww .  java  2  s  .c o m
    }
    String channel = new String(messageChannel);
    if (!(channel.endsWith(":del") || channel.endsWith(":expired"))) {
        return;
    }
    String body = new String(messageBody);
    if (!body.startsWith("spring:session:sessions:")) {
        return;
    }

    int beginIndex = body.lastIndexOf(":") + 1;
    int endIndex = body.length();
    String sessionId = body.substring(beginIndex, endIndex);

    if (logger.isDebugEnabled()) {
        logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
    }

    if (channel.endsWith(":del")) {
        publishEvent(new SessionDeletedEvent(this, sessionId));
    } else {
        publishEvent(new SessionExpiredEvent(this, sessionId));
    }
}