Make sure each cycle for cache control is finished before starting the next

This commit is contained in:
LOOHP committed 2025-03-02 20:16:52 +00:00
1 parent c37a1fda8f
commit e8204c1fa9
24 files changed
+59 -45

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_16</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_16_2</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_16_4</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_17</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_18</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_18_2</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_19</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_19_3</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_19_4</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_20</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_20_2</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_20_3</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_20_5</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_20_6</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_21</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_21_1</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_21_2</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_21_3</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-V1_21_4</artifactId>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
</parent>
<artifactId>ImageFrame-Abstraction</artifactId>
+1 -1
View File
@@ -26,7 +26,7 @@
<groupId>com.loohp</groupId>
<artifactId>ImageFrame</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
<packaging>jar</packaging>
<name>ImageFrame</name>
@@ -126,17 +126,17 @@ public abstract class ImageMap {
return manager;
}
public abstract void loadColorCache();
protected abstract void loadColorCache();
public void reloadColorCache() {
protected void reloadColorCache() {
if (hasColorCached()) {
loadColorCache();
}
}
public abstract boolean hasColorCached();
protected abstract boolean hasColorCached();
public abstract void unloadColorCache();
protected abstract void unloadColorCache();
public int getImageIndex() {
return imageIndex;
@@ -22,21 +22,26 @@ package com.loohp.imageframe.objectholders;
import com.loohp.imageframe.ImageFrame;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
public class ImageMapCacheControlTask implements Runnable, AutoCloseable {
private final ImageMap imageMap;
private int noViewerCounts;
private boolean locked;
private final AtomicBoolean locked;
private final AtomicBoolean closed;
private final Scheduler.ScheduledTask task;
private final AtomicReference<Scheduler.ScheduledTask> task;
private final AtomicInteger noViewerCounts;
public ImageMapCacheControlTask(ImageMap imageMap) {
this.imageMap = imageMap;
this.noViewerCounts = 0;
this.locked = false;
this.task = Scheduler.runTaskTimerAsynchronously(ImageFrame.plugin, this, 0, 1);
this.noViewerCounts = new AtomicInteger(0);
this.locked = new AtomicBoolean(false);
this.closed = new AtomicBoolean(false);
this.task = new AtomicReference<>(Scheduler.runTaskLaterAsynchronously(ImageFrame.plugin, this, 5));
}
public ImageMap getImageMap() {
@@ -44,32 +49,41 @@ public class ImageMapCacheControlTask implements Runnable, AutoCloseable {
}
public boolean isLocked() {
return locked;
return locked.get();
}
public void setLocked(boolean locked) {
this.locked = locked;
this.locked.set(locked);
}
@Override
public void run() {
if (locked) {
if (closed.get()) {
return;
}
if (imageMap.hasViewers()) {
noViewerCounts = 0;
if (!imageMap.hasColorCached()) {
imageMap.loadColorCache();
}
} else {
if (noViewerCounts++ > 200 && imageMap.hasColorCached()) {
imageMap.unloadColorCache();
if (!locked.get()) {
if (imageMap.hasViewers()) {
noViewerCounts.set(0);
if (!imageMap.hasColorCached()) {
imageMap.loadColorCache();
}
} else {
if (noViewerCounts.getAndIncrement() > 200 && imageMap.hasColorCached()) {
imageMap.unloadColorCache();
}
}
}
this.task.set(Scheduler.runTaskLaterAsynchronously(ImageFrame.plugin, this, 5));
}
@Override
public void close() {
task.cancel();
closed.set(true);
task.updateAndGet(t -> {
if (t != null) {
t.cancel();
}
return t;
});
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.loohp</groupId>
<artifactId>ImageFrame-Parent</artifactId>
<version>1.7.14.6</version>
<version>1.7.14.7</version>
<packaging>pom</packaging>
<properties>