All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.carm.plugin.mineredis.api.message.RedisMessage Maven / Gradle / Ivy

package cc.carm.plugin.mineredis.api.message;

import cc.carm.plugin.mineredis.MineRedis;
import com.google.common.io.ByteArrayDataInput;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class RedisMessage {

    protected final @NotNull String channel;
    protected final @NotNull String sourceServerID;
    protected final long timestamp;

    protected final ByteArrayDataInput data;

    public RedisMessage(@NotNull String channel, @NotNull String sourceServerID,
                        long timestamp, ByteArrayDataInput data) {
        this.channel = channel;
        this.sourceServerID = sourceServerID;
        this.timestamp = timestamp;
        this.data = data;
    }

    /**
     * 判断当前消息是否为本地(当前服务器)发出的。
     *
     * @return 是否为本地发出的消息
     */
    public boolean isLocalMessage() {
        return MineRedis.getServerID().equals(sourceServerID);
    }

    public @NotNull String getSourceServerID() {
        return sourceServerID;
    }

    public @NotNull String getChannel() {
        return channel;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public ByteArrayDataInput getData() {
        return data;
    }

    public  T apply(@NotNull Function handler) {
        return handler.apply(getData());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy