Skip to content

Commit 268b5ae

Browse files
committed
feat(demo): add concurrent limit to BigDataset demo
1 parent 86b1d0e commit 268b5ae

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterBigDatasetDemo.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.gridexporter;
2121

22+
import com.flowingcode.vaadin.addons.demo.DemoSource;
23+
import com.flowingcode.vaadin.addons.demo.SourceCodeViewer;
24+
import com.github.javafaker.Faker;
25+
import com.vaadin.flow.component.Html;
26+
import com.vaadin.flow.component.grid.Grid;
27+
import com.vaadin.flow.component.grid.Grid.Column;
28+
import com.vaadin.flow.component.html.Div;
29+
import com.vaadin.flow.router.PageTitle;
30+
import com.vaadin.flow.router.Route;
2231
import java.io.IOException;
2332
import java.math.BigDecimal;
2433
import java.text.SimpleDateFormat;
@@ -27,15 +36,9 @@
2736
import java.util.stream.Collectors;
2837
import java.util.stream.IntStream;
2938
import org.apache.poi.EncryptedDocumentException;
30-
import com.flowingcode.vaadin.addons.demo.DemoSource;
31-
import com.github.javafaker.Faker;
32-
import com.vaadin.flow.component.grid.Grid;
33-
import com.vaadin.flow.component.grid.Grid.Column;
34-
import com.vaadin.flow.component.html.Div;
35-
import com.vaadin.flow.router.PageTitle;
36-
import com.vaadin.flow.router.Route;
3739

3840
@DemoSource
41+
@DemoSource("/src/test/java/com/flowingcode/vaadin/addons/gridexporter/VaadinServiceInitListenerImpl.java")
3942
@PageTitle("Grid Exporter Addon Big Dataset Demo")
4043
@Route(value = "gridexporter/bigdataset", layout = GridExporterDemoView.class)
4144
@SuppressWarnings("serial")
@@ -68,14 +71,37 @@ public GridExporterBigDatasetDemo() throws EncryptedDocumentException, IOExcepti
6871
}).collect(Collectors.toList());
6972
grid.setItems(query->persons.stream().skip(query.getOffset()).limit(query.getLimit()));
7073
grid.setWidthFull();
71-
this.setSizeFull();
74+
setSizeFull();
7275
GridExporter<Person> exporter = GridExporter.createFor(grid);
7376
exporter.setAutoSizeColumns(false);
7477
exporter.setExportValue(budgetCol, item -> "" + item.getBudget());
7578
exporter.setColumnPosition(lastNameCol, 1);
7679
exporter.setTitle("People information");
7780
exporter.setFileName(
7881
"GridExport" + new SimpleDateFormat("yyyyddMM").format(Calendar.getInstance().getTime()));
82+
83+
// begin-block concurrent
84+
// #if vaadin eq 0
85+
Html concurrent = new Html(
86+
"""
87+
<div>
88+
This configuration prepares the exporter for the BigDataset demo, enabling it to manage resource-intensive
89+
document generation tasks effectively. In this setup, an upper limit of 10 is established for the cost of
90+
concurrent downloads, and the big dataset exporter is configured with a cost of 9, while other exporters
91+
handling smaller datasets retain the default cost of 1. This customization allows a combination of one large
92+
dataset download alongside one small dataset download, or up to 10 concurrent downloads of smaller datasets
93+
when no big dataset is being exported.<p>
94+
95+
Additionally, <code>setConcurrentDownloadTimeout</code> enforces a timeout for acquiring the necessary permits
96+
during a download operation. If the permits are not obtained within the specified timeframe, the download
97+
request will be aborted, preventing prolonged waiting periods, especially during peak system loads.
98+
</div>""");
99+
add(concurrent);
100+
// #endif
101+
SourceCodeViewer.highlightOnHover(concurrent, "concurrent");
102+
exporter.setConcurrentDownloadCost(9);
103+
// end-block
104+
79105
add(grid);
80106
}
81107
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.flowingcode.vaadin.addons.gridexporter;
2+
3+
import com.vaadin.flow.server.ServiceInitEvent;
4+
import com.vaadin.flow.server.VaadinServiceInitListener;
5+
import java.util.concurrent.TimeUnit;
6+
7+
public class VaadinServiceInitListenerImpl implements VaadinServiceInitListener {
8+
9+
@Override
10+
public void serviceInit(ServiceInitEvent event) {
11+
GridExporter.setConcurrentDownloadLimit(10);
12+
GridExporter.setConcurrentDownloadTimeout(5, TimeUnit.SECONDS);
13+
}
14+
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.flowingcode.vaadin.addons.gridexporter.VaadinServiceInitListenerImpl

0 commit comments

Comments
 (0)