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

com.hazelcast.cache.impl.journal.CacheEventJournalFunctions Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.cache.impl.journal;

import com.hazelcast.cache.CacheEventType;
import com.hazelcast.cache.EventJournalCacheEvent;
import com.hazelcast.internal.journal.DeserializingEntry;
import com.hazelcast.internal.serialization.SerializableByConvention;

import java.io.Serializable;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * Utility functions used from Jet. They are here so that they can be also used
 * when Jet accesses remote imdg (non-jet) cluster.
 */
public final class CacheEventJournalFunctions {

    private CacheEventJournalFunctions() { }

    public static  Predicate> cachePutEvents() {
        return new CachePutEventsPredicate();
    }

    public static  Function, Entry> cacheEventToEntry() {
        return new CacheEventToEntryProjection();
    }

    @SuppressWarnings("unchecked")
    public static  Function, V> cacheEventNewValue() {
        return new CacheEventNewValueProjection();
    }

    @SerializableByConvention
    private static class CachePutEventsPredicate implements Predicate>, Serializable {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean test(EventJournalCacheEvent e) {
            return e.getType() == CacheEventType.CREATED || e.getType() == CacheEventType.UPDATED;
        }
    }

    @SerializableByConvention
    private static class CacheEventToEntryProjection
            implements Function, Entry>, Serializable {
        private static final long serialVersionUID = 1L;

        @Override
        public Entry apply(EventJournalCacheEvent e) {
            DeserializingEventJournalCacheEvent casted = (DeserializingEventJournalCacheEvent) e;
            return new DeserializingEntry<>(casted.getDataKey(), casted.getDataNewValue());
        }
    }

    @SerializableByConvention
    private static class CacheEventNewValueProjection implements Function, Serializable {
        private static final long serialVersionUID = 1L;

        @Override
        public Object apply(Object event) {
            DeserializingEventJournalCacheEvent casted = (DeserializingEventJournalCacheEvent) event;
            return casted.getDataNewValue();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy