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

com.databasesandlife.util.wicket.CachingFutureModel Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util.wicket;

import com.databasesandlife.util.Future;
import org.apache.wicket.model.IModel;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.Serializable;

/**
 * Can be used simple as a cache of a Future, or also as a Wicket model.
 * 

* Futures have the problem that they are not serializable. * Wicket only needs to serialize things after they've been displayed, i.e. after the future has delivered its results. *

*/ abstract public class CachingFutureModel implements IModel { protected transient @CheckForNull Future future; protected @CheckForNull T contents; public CachingFutureModel() { refresh(); } abstract protected @Nonnull T populate(); @Override public @Nonnull T getObject() { if (future != null) contents = future.get(); if (contents != null) return contents; throw new RuntimeException("Object serialized before future executed"); } public void refresh() { future = new Future() { @Override protected @Nonnull T populate() { return CachingFutureModel.this.populate(); } }; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy