-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-4721 - add Harakiri controller thread
- Loading branch information
1 parent
0010427
commit cdfdaf2
Showing
4 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#Build Number for ANT. Do not edit! | ||
#Tue Oct 10 13:30:49 CEST 2023 | ||
build.number=1 | ||
#Tue Oct 10 13:44:11 CEST 2023 | ||
build.number=2 |
82 changes: 82 additions & 0 deletions
82
source/java/src/org/lucee/extension/resource/s3/Harakiri.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.lucee.extension.resource.s3; | ||
|
||
import java.util.Map; | ||
|
||
import org.lucee.extension.resource.s3.info.S3Info; | ||
|
||
import lucee.commons.io.log.Log; | ||
|
||
public class Harakiri { | ||
private S3Cache cache; | ||
private HarakiriThread thread; | ||
private Log log; | ||
|
||
public Harakiri(S3Cache cache, Log log) { | ||
this.cache = cache; | ||
this.log = log; | ||
} | ||
|
||
public void touch() { | ||
if (thread == null || !thread.isAlive()) { | ||
synchronized (this) { | ||
if (thread == null || !thread.isAlive()) { | ||
thread = new HarakiriThread(cache, log); | ||
thread.start(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static class HarakiriThread extends Thread { | ||
private static final long IDLE_TIMEOUT = 10000; | ||
private static final long INTERVALL = 1000; | ||
private long lastMod; | ||
private S3Cache cache; | ||
private Log log; | ||
|
||
public HarakiriThread(S3Cache cache, Log log) { | ||
this.cache = cache; | ||
this.log = log; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (true) { | ||
if (log != null) | ||
log.debug("S3", "S3 cache observer: checking for elements to flush in the cache, there are " + cache.exists.size() + " elements currently in the cache"); | ||
if (!cache.exists.isEmpty()) { | ||
long now = System.currentTimeMillis(); | ||
try { | ||
for (Map.Entry<String, S3Info> e: cache.exists.entrySet()) { | ||
if (e.getValue().validUntil() < now) { | ||
if (log != null) log.debug("S3", "S3 cache observer: remove object " + e.getKey() + " from cache"); | ||
cache.exists.remove(e.getKey()); | ||
|
||
} | ||
} | ||
} | ||
catch (Exception e) { | ||
if (log != null) log.error("S3", e); | ||
} | ||
lastMod = now; | ||
} | ||
// nothing to do ATM | ||
else { | ||
long now = System.currentTimeMillis(); | ||
if (lastMod + IDLE_TIMEOUT < now) { | ||
if (log != null) log.debug("S3", "S3 cache observer: nothing to do, idle timeout reached, stoping observer "); | ||
break; | ||
} | ||
else if (log != null) log.debug("S3", "S3 cache observer: nothing to do, remaining idle for another " + ((lastMod + IDLE_TIMEOUT) - now) + "ms"); | ||
} | ||
if (log != null) log.debug("S3", "S3 cache observer: sleep for " + INTERVALL + "ms"); | ||
try { | ||
sleep(INTERVALL); | ||
} | ||
catch (InterruptedException e) { | ||
if (log != null) log.error("S3", e); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
source/java/src/org/lucee/extension/resource/s3/S3Cache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.lucee.extension.resource.s3; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.lucee.extension.resource.s3.S3.S3BucketExists; | ||
import org.lucee.extension.resource.s3.S3.ValidUntilElement; | ||
import org.lucee.extension.resource.s3.S3.ValidUntilMap; | ||
import org.lucee.extension.resource.s3.info.S3BucketWrapper; | ||
import org.lucee.extension.resource.s3.info.S3Info; | ||
import org.lucee.extension.resource.s3.region.RegionFactory; | ||
import org.lucee.extension.resource.s3.region.RegionFactory.Region; | ||
|
||
import com.amazonaws.services.s3.model.AccessControlList; | ||
|
||
import lucee.commons.io.log.Log; | ||
|
||
class S3Cache { | ||
|
||
final Harakiri harakiri; | ||
ValidUntilMap<S3BucketWrapper> buckets; | ||
Map<String, S3BucketExists> existBuckets; | ||
final Map<String, ValidUntilMap<S3Info>> objects = new ConcurrentHashMap<String, ValidUntilMap<S3Info>>(); | ||
final Map<String, ValidUntilElement<AccessControlList>> accessControlLists = new ConcurrentHashMap<String, ValidUntilElement<AccessControlList>>(); | ||
final Map<String, Region> regions = new ConcurrentHashMap<String, Region>(); | ||
final Map<String, Region> bucketRegions = new ConcurrentHashMap<String, Region>(); | ||
final Map<String, S3Info> exists = new ConcurrentHashMap<String, S3Info>(); | ||
|
||
public S3Cache(Log log) { | ||
regions.put("US", RegionFactory.US_EAST_1); | ||
harakiri = new Harakiri(this, log); | ||
} | ||
} |