Skip to content

Commit 918539f

Browse files
committed
init
1 parent 44e7b60 commit 918539f

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

src/main/java/org/rapidpm/vaadin/BasicTestUIRunner.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,11 @@
1616
package org.rapidpm.vaadin;
1717

1818
import org.apache.meecrowave.Meecrowave;
19-
import org.rapidpm.vaadin.imagecache.filesystem.BlobImageServiceFileSystem;
20-
import org.rapidpm.vaadin.imagecache.map.BlobImageServiceMap;
21-
import org.rapidpm.vaadin.imagecache.BlobService;
2219

2320
public class BasicTestUIRunner {
2421
private BasicTestUIRunner() {
2522
}
2623

27-
28-
public static final BlobService BLOB_SERVICE = new BlobImageServiceFileSystem();
29-
// public static final BlobService BLOB_SERVICE = new BlobImageServiceMap();
30-
// public static final BlobService BLOB_SERVICE = new BlobImageServiceWeakRef();
31-
// public static final BlobService BLOB_SERVICE = new BlobImageServiceMapDB();
32-
3324
public static void main(String[] args) {
3425

3526
new Meecrowave(new Meecrowave.Builder() {

src/main/java/org/rapidpm/vaadin/VaadinApp.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
*/
1616
package org.rapidpm.vaadin;
1717

18+
import static org.rapidpm.frp.model.Result.ofNullable;
19+
import static org.rapidpm.vaadin.BlobImagePushService.register;
1820
import static org.rapidpm.vaadin.imagecache.ImageFunctions.nextImageName;
1921
import static org.rapidpm.vaadin.imagecache.ImageFunctions.streamResource;
20-
import static org.rapidpm.vaadin.BlobImagePushService.register;
2122

2223
import java.util.function.Function;
2324

2425
import org.rapidpm.dependencies.core.logger.HasLogger;
26+
import org.rapidpm.frp.model.Result;
27+
import org.rapidpm.vaadin.imagecache.BlobService;
2528
import com.vaadin.flow.component.Composite;
29+
import com.vaadin.flow.component.DetachEvent;
2630
import com.vaadin.flow.component.html.Div;
2731
import com.vaadin.flow.component.html.Image;
2832
import com.vaadin.flow.component.page.Push;
@@ -43,27 +47,29 @@ private Function<AbstractStreamResource, Image> createImage() {
4347

4448
private Function<String, AbstractStreamResource> createImageResource() {
4549
return (imageID) -> streamResource()
46-
.apply(BasicTestUIRunner.BLOB_SERVICE)
50+
.apply(BlobService.INSTANCE)
4751
.apply(imageID)
4852
.setCacheTime(0);
4953
}
5054

5155
private Image image;
52-
private Registration registration;
56+
private Result<Registration> registration;
5357

5458
public VaadinApp() {
55-
Div content = getContent();
56-
content.setSizeFull();
57-
5859
image = createImageResource()
5960
.andThen(createImage()).apply(nextImageName().get());
6061

61-
registration = register(imgID -> image.getUI()
62-
.ifPresent(ui -> ui.access(() -> {
63-
logger().info("DashboardComponent - imgID = " + imgID);
64-
image.setSrc(createImageResource().apply(imgID));
65-
})));
62+
registration = ofNullable(register(imgID -> image.getUI()
63+
.ifPresent(ui -> ui.access(() -> {
64+
logger().info("VaadinApp - imgID = " + imgID);
65+
image.setSrc(createImageResource().apply(imgID));
66+
}))));
67+
getContent().add(image);
68+
}
6669

67-
content.add(image);
70+
@Override
71+
protected void onDetach(DetachEvent detachEvent) {
72+
super.onDetach(detachEvent);
73+
registration.ifPresent(Registration::remove);
6874
}
6975
}

src/main/java/org/rapidpm/vaadin/imagecache/BlobImageServiceFileFunctions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ public interface BlobImageServiceFileFunctions {
1313
static CheckedFunction<String, byte[]> loadFile() {
1414
return (blobID) -> readAllBytes(new File(STORAGE_PREFIX + blobID).toPath());
1515
}
16-
17-
1816
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
package org.rapidpm.vaadin.imagecache;
22

33
import org.rapidpm.frp.model.Result;
4+
import org.rapidpm.vaadin.imagecache.filesystem.BlobImageServiceFileSystem;
5+
import org.rapidpm.vaadin.imagecache.map.BlobImageServiceMap;
6+
import org.rapidpm.vaadin.imagecache.mapdb.BlobImageServiceMapDB;
7+
import org.rapidpm.vaadin.imagecache.weakref.BlobImageServiceWeakRef;
48

59
/**
610
*
711
*/
812
public interface BlobService {
13+
14+
//do not do this in production !!!
15+
BlobService INSTANCE = new BlobImageServiceFileSystem();
16+
// BlobService INSTANCE = new BlobImageServiceMap();
17+
// BlobService INSTANCE = new BlobImageServiceWeakRef();
18+
// BlobService INSTANCE = new BlobImageServiceMapDB();
19+
20+
921
Result<byte[]> loadBlob(String blobID);
1022
}

src/main/java/org/rapidpm/vaadin/imagecache/weakref/BlobImageServiceWeakRef.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,4 @@ public Result<byte[]> loadBlob(String blobID) {
4444
.get();
4545
}
4646
}
47-
48-
4947
}

0 commit comments

Comments
 (0)