Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui views: sysconfig to configure how much time we keep the views before we expire them #1407

Merged
merged 4 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.metas.ui.web.bankstatement_reconciliation;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class BankStatementReconciliationViewFactory implements IViewFactory, IVi
private final IMsgBL msgBL = Services.get(IMsgBL.class);
private final IADProcessDAO adProcessDAO = Services.get(IADProcessDAO.class);
private final BankStatementLineAndPaymentsToReconcileRepository rowsRepo;
private final DefaultViewsRepositoryStorage views = new DefaultViewsRepositoryStorage(1);
private final DefaultViewsRepositoryStorage views = new DefaultViewsRepositoryStorage(TimeUnit.HOURS.toMinutes(1));

public BankStatementReconciliationViewFactory(
@NonNull final BankStatementLineAndPaymentsToReconcileRepository rowsRepo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.metas.ui.web.material.cockpit;

import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.compiere.model.I_M_Product;
Expand Down Expand Up @@ -48,7 +49,7 @@
@Service
public class MaterialCockpitViewsIndexStorage implements IViewsIndexStorage
{
private final DefaultViewsRepositoryStorage defaultViewsRepositoryStorage = new DefaultViewsRepositoryStorage(1);
private final DefaultViewsRepositoryStorage defaultViewsRepositoryStorage = new DefaultViewsRepositoryStorage(TimeUnit.HOURS.toMinutes(1));

public MaterialCockpitViewsIndexStorage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.adempiere.exceptions.AdempiereException;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class PaymentsViewFactory implements IViewFactory, IViewsIndexStorage

private final IMsgBL msgBL = Services.get(IMsgBL.class);
private final PaymentAndInvoiceRowsRepo rowsRepo;
private final DefaultViewsRepositoryStorage views = new DefaultViewsRepositoryStorage(1);
private final DefaultViewsRepositoryStorage views = new DefaultViewsRepositoryStorage(TimeUnit.HOURS.toMinutes(1));

public PaymentsViewFactory(
@NonNull final PaymentAndInvoiceRowsRepo rowsRepo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalNotification;
import de.metas.logging.LogManager;
import de.metas.ui.web.view.event.ViewChangesCollector;
import de.metas.ui.web.window.datatypes.WindowId;
import lombok.NonNull;
import org.slf4j.Logger;

import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -36,12 +38,14 @@
// NOTE: don't add it to spring context! i.e. don't annotate it with @Component or similar
public final class DefaultViewsRepositoryStorage implements IViewsIndexStorage
{
private static transient final Logger logger = LogManager.getLogger(DefaultViewsRepositoryStorage.class);

private final Cache<ViewId, IView> views;

public DefaultViewsRepositoryStorage(final int viewExpirationTimeoutInHours)
public DefaultViewsRepositoryStorage(final long viewExpirationTimeoutInMinutes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheBestPessimist @metas-ts we shall avoid using primitive (and meaningless) types.
In this case, Duration would be suitable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THere's no way in java 8 to transform a Duration -> Timeunit.
I wanted to use duration in the first place, but didn't see a good way. More details: https://stackoverflow.com/questions/26581708/converting-timeunit-to-chronounit

{
views = CacheBuilder.newBuilder()
.expireAfterAccess(viewExpirationTimeoutInHours, TimeUnit.HOURS)
.expireAfterAccess(viewExpirationTimeoutInMinutes, TimeUnit.MINUTES)
.removalListener(this::onViewRemoved)
.build();
}
Expand Down Expand Up @@ -91,6 +95,7 @@ public void closeById(@NonNull final ViewId viewId, @NonNull final ViewCloseActi
private void onViewRemoved(final RemovalNotification<Object, Object> notification)
{
final IView view = (IView)notification.getValue();
logger.debug("View <" + view.getViewId() + "> removed from cache. Cause: " + notification.getCause());
view.afterDestroy();
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/metas/ui/web/view/ViewsRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

/*
Expand Down Expand Up @@ -100,8 +101,8 @@ public ViewsRepository(
this.defaultFactory = defaultFactory;
this.menuTreeRepo = menuTreeRepo;

final int viewExpirationTimeoutInHours = Services.get(ISysConfigBL.class).getIntValue("de.metas.ui.web.view.ViewExpirationTimeoutInHours", 1);
defaultViewsIndexStorage = new DefaultViewsRepositoryStorage(viewExpirationTimeoutInHours);
final int viewExpirationTimeoutInMinutes = Services.get(ISysConfigBL.class).getIntValue("de.metas.ui.web.view.ViewExpirationTimeoutInMinutes", 60);
defaultViewsIndexStorage = new DefaultViewsRepositoryStorage(viewExpirationTimeoutInMinutes);
}

@PostConstruct
Expand Down