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

org.wildfly.clustering.ejb.cache.bean.DefaultBeanMetaDataEntry Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.ejb.cache.bean;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.function.Supplier;

import org.wildfly.clustering.server.offset.Offset;
import org.wildfly.clustering.server.offset.OffsetValue;

/**
 * @author Paul Ferraro
 */
public class DefaultBeanMetaDataEntry implements RemappableBeanMetaDataEntry {

    private final String name;
    private final K groupId;
    private final OffsetValue lastAccess;

    public DefaultBeanMetaDataEntry(String name, K groupId) {
        this(name, groupId, Instant.now().truncatedTo(ChronoUnit.MILLIS));
    }

    DefaultBeanMetaDataEntry(String name, K groupId, Instant creationTime) {
        this.name = name;
        this.groupId = groupId;
        this.lastAccess = OffsetValue.from(creationTime);
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public K getGroupId() {
        return this.groupId;
    }

    @Override
    public OffsetValue getLastAccess() {
        return this.lastAccess;
    }

    @Override
    public RemappableBeanMetaDataEntry remap(Supplier> lastAccessOffset) {
        RemappableBeanMetaDataEntry result = new DefaultBeanMetaDataEntry<>(this.name, this.groupId, this.lastAccess.getBasis());
        result.getLastAccess().set(lastAccessOffset.get().apply(this.lastAccess.get()));
        return result;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder(this.getClass().getSimpleName()).append(" { ");
        builder.append("name = ").append(this.name);
        builder.append(", group = ").append(this.groupId);
        builder.append(", created = ").append(this.lastAccess.getBasis());
        builder.append(", last-access = ").append(this.lastAccess.get());
        return builder.append(" }").toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy