Skip to content

Commit

Permalink
chore(demo): highlight block in VaadinServiceInitListener
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-godoy committed Jul 15, 2024
1 parent f8a59c4 commit a1b99fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.flowingcode.vaadin.addons.demo.DemoSource;
import com.flowingcode.vaadin.addons.demo.SourceCodeViewer;
import com.flowingcode.vaadin.addons.gridhelpers.GridHelper;
import com.flowingcode.vaadin.addons.gridhelpers.HeightMode;
import com.github.javafaker.Faker;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.grid.Grid;
Expand All @@ -38,7 +40,7 @@
import org.apache.poi.EncryptedDocumentException;

@DemoSource
@DemoSource("/src/test/java/com/flowingcode/vaadin/addons/gridexporter/VaadinServiceInitListenerImpl.java")
@DemoSource(clazz = VaadinServiceInitListenerImpl.class)
@PageTitle("Big Dataset")
@Route(value = "gridexporter/bigdataset", layout = GridExporterDemoView.class)
@SuppressWarnings("serial")
Expand Down Expand Up @@ -80,29 +82,38 @@ public GridExporterBigDatasetDemo() throws EncryptedDocumentException, IOExcepti
exporter.setFileName(
"GridExport" + new SimpleDateFormat("yyyyddMM").format(Calendar.getInstance().getTime()));

// begin-block concurrent
// show-source add(grid);

// #if vaadin eq 0
Html concurrent = new Html(
GridHelper.setHeightByRows(grid, 6);
GridHelper.setHeightMode(grid, HeightMode.ROW);
Html block1 = new Html(
"""
<div>
This configuration prepares the exporter for the BigDataset demo, enabling it to manage resource-intensive
document generation tasks effectively. In this setup, an upper limit of 10 is established for the cost of
concurrent downloads, and the big dataset exporter is configured with a cost of 9, while other exporters
handling smaller datasets retain the default cost of 1. This customization allows a combination of one large
dataset download alongside one small dataset download, or up to 10 concurrent downloads of smaller datasets
when no big dataset is being exported.<p>
when no big dataset is being exported.
</div>""");
Html block2 = new Html(
"""
<div>
Additionally, <code>setConcurrentDownloadTimeout</code> enforces a timeout for acquiring the necessary permits
during a download operation. If the permits are not obtained within the specified timeframe, the download
request will be aborted and the <code>DownloadTimeoutEvent</code> listener will execute, preventing prolonged
waiting periods, especially during peak system loads.
</div>""");
add(concurrent);

add(block1, grid, block2);
SourceCodeViewer.highlightOnHover(block1, "concurrent");
SourceCodeViewer.highlightOnHover(block2,
"VaadinServiceInitListenerImpl.java#setConcurrentDownloadTimeout");
// #endif
SourceCodeViewer.highlightOnHover(concurrent, "concurrent");
// begin-block concurrent
exporter.setConcurrentDownloadCost(9);
// end-block

add(grid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener
@Override
public void serviceInit(ServiceInitEvent event) {
GridExporter.setConcurrentDownloadLimit(10);

// begin-block setConcurrentDownloadTimeout
GridExporter.setConcurrentDownloadTimeout(5, TimeUnit.SECONDS);
GridExporter.addGlobalConcurrentDownloadTimeoutEvent(ev -> {
Notification.show("System is busy. Please try again later.")
.addThemeVariants(NotificationVariant.LUMO_ERROR);
});
// end-block

}

}

0 comments on commit a1b99fc

Please sign in to comment.