
com.hazelcast.map.impl.journal.MapEventJournalFunctions 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.map.impl.journal;
import com.hazelcast.core.EntryEventType;
import com.hazelcast.internal.journal.DeserializingEntry;
import com.hazelcast.internal.serialization.SerializableByConvention;
import com.hazelcast.map.EventJournalMapEvent;
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 MapEventJournalFunctions {
private MapEventJournalFunctions() { }
public static Predicate> mapPutEvents() {
return new MapPutEventsPredicate<>();
}
public static Function, Entry> mapEventToEntry() {
return new MapEventToEntryProjection<>();
}
@SuppressWarnings("unchecked")
public static Function, V> mapEventNewValue() {
return new MapEventNewValueProjection();
}
@SerializableByConvention
private static class MapPutEventsPredicate implements Predicate>, Serializable {
private static final long serialVersionUID = 1L;
@Override
public boolean test(EventJournalMapEvent e) {
return e.getType() == EntryEventType.ADDED || e.getType() == EntryEventType.UPDATED;
}
}
@SerializableByConvention
private static class MapEventToEntryProjection
implements Function, Entry>, Serializable {
private static final long serialVersionUID = 1L;
@Override
public Entry apply(EventJournalMapEvent e) {
DeserializingEventJournalMapEvent casted = (DeserializingEventJournalMapEvent) e;
return new DeserializingEntry<>(casted.getDataKey(), casted.getDataNewValue());
}
}
@SerializableByConvention
private static class MapEventNewValueProjection implements Function, Serializable {
private static final long serialVersionUID = 1L;
@Override
public Object apply(Object event) {
DeserializingEventJournalMapEvent casted = (DeserializingEventJournalMapEvent) event;
return casted.getDataNewValue();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy