Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a370a7b
WIP reconfigure only changed namespaces
attilakreiner May 31, 2024
3757300
WIP watch resources
attilakreiner Jun 5, 2024
c02e5c4
WIP refactoring watch resources
attilakreiner Jun 5, 2024
8fcae70
WIP refactoring 2
attilakreiner Jun 5, 2024
96f070e
WIP fix
attilakreiner Jun 6, 2024
df0b998
WIP EngineConfigWatcher
attilakreiner Jun 6, 2024
c0a554f
WIP ResourceResolver
attilakreiner Jun 6, 2024
b726267
WIP fix ResourceResolver
attilakreiner Jun 6, 2024
9c2cbbe
fix indentation
attilakreiner Jun 10, 2024
abb923f
fix EngineManager method names
attilakreiner Jun 10, 2024
b9355c6
rm ResourceResolver
attilakreiner Jun 10, 2024
c58ebc9
WIP EngineManager addResources
attilakreiner Jun 10, 2024
2285123
Revert "WIP reconfigure only changed namespaces"
attilakreiner Jun 11, 2024
39f34d0
fix EngineConfigWatcher addResources
attilakreiner Jun 11, 2024
b482fac
Merge branch 'develop' into config-reload
attilakreiner Jun 11, 2024
fd17488
Merge branch 'develop' into config-reload
attilakreiner Jun 13, 2024
b6c2ff2
Merge branch 'develop' into config-reload
attilakreiner Jun 14, 2024
2da3603
WIP readPath resolvePath readLocation
attilakreiner Jun 11, 2024
c85bdc1
WIP filesystem-http
attilakreiner Jun 5, 2024
ab94dac
WIP
attilakreiner Jun 18, 2024
22a2d03
fix
attilakreiner Jun 18, 2024
dfe9610
Merge branch 'develop' into config-reload
attilakreiner Jun 18, 2024
e4cf407
fix
attilakreiner Jun 18, 2024
df172d8
fix EngineConfiguration configPath
attilakreiner Jun 19, 2024
bef04ad
WIP fix
attilakreiner Jun 19, 2024
3177c80
WIP hfs 1
attilakreiner Jun 20, 2024
2a217f8
WIP hfs uri
attilakreiner Jun 20, 2024
4f5737a
WIP hfs resolveSibling
attilakreiner Jun 20, 2024
6395780
WIP hfs rm timeout
attilakreiner Jun 20, 2024
54a2b87
WIP hfs revert send
attilakreiner Jun 20, 2024
a5d0a39
WIP hfs HP readBody resolveBody
attilakreiner Jun 20, 2024
f19e623
WIP hfs HP readBody etag
attilakreiner Jun 20, 2024
a8a4015
WIP hfs HP
attilakreiner Jun 20, 2024
c2efe21
WIP hfs ignore AppIT
attilakreiner Jun 20, 2024
873b5e1
WIP hfs fix AppIT
attilakreiner Jun 20, 2024
c166431
WIP hfs watchBody 1
attilakreiner Jun 20, 2024
0c0f7f4
WIP hfs watchBody 2
attilakreiner Jun 20, 2024
31b420c
WIP hfs watchBody 3
attilakreiner Jun 21, 2024
d3109f7
WIP hfs watchBody 4
attilakreiner Jun 21, 2024
3198b10
WIP hfs watchBody 5
attilakreiner Jun 21, 2024
ef2d377
WIP hfs watchBody 6
attilakreiner Jun 21, 2024
8f982fe
WIP hfs getPath
attilakreiner Jun 21, 2024
50c8792
WIP hfs watchBody 7
attilakreiner Jun 21, 2024
71231a9
WIP fix
attilakreiner Jun 21, 2024
7535666
Remove BindingConfig.readLocation
jfallows Jun 26, 2024
e7c6c56
No watch event needed for identical response body
jfallows Jun 26, 2024
5423718
Handle status 204 with null body and infer delay for optional prefer …
jfallows Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP hfs watchBody 7
  • Loading branch information
attilakreiner committed Jun 21, 2024
commit 50c87920da823034998f920e4b663bcc671ba4ab
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static java.net.http.HttpClient.Version.HTTP_2;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static java.util.Objects.requireNonNull;
import static org.agrona.LangUtil.rethrowUnchecked;

import java.io.File;
import java.io.IOException;
Expand All @@ -39,6 +38,9 @@
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class HttpPath implements Path
{
Expand All @@ -50,9 +52,10 @@ public class HttpPath implements Path

private final HttpFileSystem fs;
private final URI location;
private final ScheduledExecutorService executor;
private int pollSeconds; // TODO: Ati - HttpFileSystemConfiguration -> final

private byte[] body;
private boolean longPolling;
private String etag;
private HttpWatchService.HttpWatchKey watchKey;
private CompletableFuture<Void> future;
Expand All @@ -65,16 +68,21 @@ public class HttpPath implements Path
{
throw new IllegalArgumentException(String.format("invalid protocol: %s", location.getScheme()));
}
System.out.println("HP constructor location " + location); // TODO: Ati
this.fs = fs;
this.location = location;
this.longPolling = true;
this.executor = Executors.newScheduledThreadPool(2);
// TODO: Ati - HttpFileSystemConfiguration
//this.pollSeconds = 30;
this.pollSeconds = 3;
}

HttpPath()
{
this.fs = null;
this.location = null;
this.longPolling = true;
this.executor = null;
this.pollSeconds = 0;
}

@Override
Expand Down Expand Up @@ -243,6 +251,7 @@ public WatchKey register(
WatchService watcher,
WatchEvent.Kind<?>... events) throws IOException
{
System.out.println("HP register"); // TODO: Ati
return register(watcher, events, new WatchEvent.Modifier[0]);
}

Expand Down Expand Up @@ -288,6 +297,13 @@ public int hashCode()
return Objects.hashCode(location);
}

// TODO: Ati - HttpFileSystemConfiguration
public void pollSeconds(
int pollSeconds)
{
this.pollSeconds = pollSeconds;
}

byte[] readBody()
{
System.out.println("HP readBody"); // TODO: Ati
Expand Down Expand Up @@ -328,12 +344,30 @@ else if (response.statusCode() == HTTP_NOT_MODIFIED)
catch (Exception ex)
{
System.out.println("HP readBody exception " + ex); // TODO: Ati
rethrowUnchecked(ex);
body = new byte[0];
}
return body;
}

void watchBody()
void watch()
{
scheduleWatchBody(this.pollSeconds);
}

private void scheduleWatchBody(
int pollSeconds)
{
if (pollSeconds == 0)
{
watchBody();
}
else
{
executor.schedule(this::watchBody, pollSeconds, TimeUnit.SECONDS);
}
}

private void watchBody()
{
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
.GET()
Expand All @@ -355,19 +389,17 @@ private void handleResponse(
System.out.println("HP handleResponse response: " + response); // TODO: Ati
System.out.println("HP handleResponse response.headers: " + response.headers()); // TODO: Ati
int statusCode = response.statusCode();
//int pollSeconds = 0;
int pollSeconds = 1;
if (statusCode == 404)
{
body = EMPTY_BODY;
watchKey.addEvent(ENTRY_MODIFY, this);
longPolling = false;
//pollSeconds = this.pollSeconds;
pollSeconds = this.pollSeconds;
}
else if (statusCode >= 500 && statusCode <= 599)
{
body = null;
longPolling = false;
//pollSeconds = this.pollSeconds;
pollSeconds = this.pollSeconds;
}
else
{
Expand All @@ -384,9 +416,8 @@ else if (statusCode >= 500 && statusCode <= 599)
}
else if (response.statusCode() != 304)
{
this.body = response.body();
longPolling = false;
//pollSeconds = this.pollSeconds;
body = response.body();
pollSeconds = this.pollSeconds;
}
}
else
Expand All @@ -401,23 +432,27 @@ else if (response.statusCode() != 304)
watchKey.addEvent(ENTRY_MODIFY, this);
//addEvent(path);
}
//pollSeconds = this.pollSeconds;
pollSeconds = this.pollSeconds;
}
}
watchKey.watchBody();
}

boolean longPolling()
{
return longPolling;
scheduleWatchBody(pollSeconds);
}

void cancel()
{
System.out.println("HP cancel"); // TODO: Ati
body = null;
etag = null;
future.cancel(true);
}

// required for testing
public void shutdown()
{
System.out.println("HP shutdown"); // TODO: Ati
executor.shutdownNow();
}

private Void handleException(
Throwable throwable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class HttpWatchService implements WatchService
Expand All @@ -39,22 +37,18 @@ public class HttpWatchService implements WatchService

private final WatchKey closeKey = new HttpWatchKey(CLOSE_PATH);

private final ScheduledExecutorService executor;
private final List<HttpWatchKey> watchKeys;
private final LinkedBlockingQueue<WatchKey> pendingKeys;
private final MessageDigest md5;

private int pollSeconds;
private volatile boolean closed;

public HttpWatchService()
{
this.executor = Executors.newScheduledThreadPool(2);

this.watchKeys = Collections.synchronizedList(new LinkedList<>());
this.pendingKeys = new LinkedBlockingQueue<>();
this.md5 = initMessageDigest("MD5");
// TODO: Ati - HttpFileSystemConfiguration
this.pollSeconds = 30;
this.closed = false;
}

Expand Down Expand Up @@ -98,13 +92,6 @@ public WatchKey take() throws InterruptedException
return key;
}

// TODO: Ati - HttpFileSystemConfiguration
public void pollSeconds(
int pollSeconds)
{
this.pollSeconds = pollSeconds;
}

private void checkOpen()
{
if (closed)
Expand Down Expand Up @@ -147,7 +134,7 @@ HttpWatchKey register(
}
System.out.printf("HWS register path: %s\n", path); // TODO: Ati
HttpWatchKey watchKey = new HttpWatchKey(path);
watchKey.watchBody();
watchKey.watch();
watchKeys.add(watchKey);
return watchKey;
}
Expand Down Expand Up @@ -213,6 +200,7 @@ public boolean reset()
@Override
public void cancel()
{
System.out.println("HWK cancel"); // TODO: Ati
watchKeys.remove(this);
path.cancel();
valid = false;
Expand Down Expand Up @@ -254,18 +242,11 @@ public int hashCode()
return Objects.hashCode(path);
}

void watchBody()
void watch()
{
if (valid)
{
if (path.longPolling())
{
path.watchBody();
}
else
{
executor.schedule(path::watchBody, pollSeconds, TimeUnit.SECONDS);
}
path.watch();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public void shouldWatch() throws Exception
// GIVEN
String url = "http://localhost:8080/hello.txt";
Path path = Path.of(new URI(url));
((HttpPath) path).pollSeconds(1); // TODO: Ati
HttpWatchService watchService = (HttpWatchService) path.getFileSystem().newWatchService();
watchService.pollSeconds(1); // TODO: Ati

// WHEN
k3po.start();
Expand All @@ -216,6 +216,7 @@ public void shouldWatch() throws Exception
WatchKey key2 = watchService.take();
List<WatchEvent<?>> events2 = key2.pollEvents();
watchService.close();
((HttpPath) path).shutdown();
k3po.finish();

// THEN
Expand All @@ -237,7 +238,7 @@ public void shouldWatchRead() throws Exception
String url = "http://localhost:8080/hello.txt";
Path path = Path.of(new URI(url));
HttpWatchService watchService = (HttpWatchService) path.getFileSystem().newWatchService();
watchService.pollSeconds(1); // TODO: Ati
((HttpPath) path).pollSeconds(1); // TODO: Ati

// WHEN
k3po.start();
Expand All @@ -252,6 +253,7 @@ public void shouldWatchRead() throws Exception
k3po.notifyBarrier("SECOND_READ");
String body2 = Files.readString(path);
watchService.close();
((HttpPath) path).shutdown();
k3po.finish();

// THEN
Expand Down