Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Далбеев Георгий / ИТМО DWS / Stage 5 #195

Merged
59 commits merged into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
05e9923
stage1
Feb 18, 2024
88a5902
stage1
Feb 18, 2024
d67f73f
stage1
Feb 18, 2024
7491aad
report stage1
Feb 21, 2024
98ffc92
Merge branch 'main' into lab1
Feb 28, 2024
202f435
fix issues
Feb 28, 2024
efd4138
lab2 code and move lab1 dir
Feb 29, 2024
a6d1fea
fix codestyle
Feb 29, 2024
a352103
fix codestyle
Feb 29, 2024
585536f
Merge branch 'main' into lab2
incubos Mar 3, 2024
85d43c1
Merge branch 'main' into lab2
Mar 6, 2024
98e3447
fix code
Mar 6, 2024
f081371
Merge remote-tracking branch 'origin/lab2' into lab2
Mar 6, 2024
502073a
fix codestyle
Mar 6, 2024
5dc8c66
fix report
Mar 7, 2024
e70d901
Merge branch 'main' into lab2
goshadalbeev Mar 7, 2024
dc68806
Merge branch 'main' into lab2
incubos Mar 10, 2024
027a623
Merge branch 'main' into lab3
goshadalbeev Mar 13, 2024
8cbc001
code
goshadalbeev Mar 13, 2024
5696a00
fix codestyle
goshadalbeev Mar 13, 2024
4d227fa
fix codestyle
goshadalbeev Mar 13, 2024
b67da69
Merge branch 'main' into lab3
goshadalbeev Mar 17, 2024
0eb99ad
Merge branch 'main' into lab3
goshadalbeev Mar 20, 2024
839dd28
add report
Mar 21, 2024
2c64471
add report
Mar 21, 2024
b132288
Merge branch 'main' into lab3
goshadalbeev Mar 26, 2024
e879893
fix code
goshadalbeev Mar 26, 2024
fddbbc2
stage 4 init commmit - only code
goshadalbeev Mar 28, 2024
5bd4502
fixcodestyle
goshadalbeev Mar 28, 2024
4aa017b
Merge branch 'main' into lab4
goshadalbeev Mar 28, 2024
4f92069
fixcodestyle
goshadalbeev Mar 28, 2024
86a093c
Merge remote-tracking branch 'origin/lab4' into lab4
goshadalbeev Mar 28, 2024
f70ce2e
Merge branch 'main' into lab4
Apr 3, 2024
2ef960f
wrk and async
Apr 3, 2024
c822bb5
add report
Apr 3, 2024
2e0092b
Merge branch 'main' into lab4
goshadalbeev Apr 5, 2024
8da9866
Merge branch 'main' into lab4
goshadalbeev Apr 11, 2024
857c3a3
add code
goshadalbeev Apr 11, 2024
67aefed
fix
goshadalbeev Apr 11, 2024
02459ba
fix codestyle
goshadalbeev Apr 11, 2024
7216161
fix codestyle
goshadalbeev Apr 11, 2024
78619ce
fix codestyle
goshadalbeev Apr 11, 2024
c965e1d
Merge branch 'main' into lab5
goshadalbeev Apr 11, 2024
2fccbce
Merge branch 'main' into lab5
goshadalbeev Apr 14, 2024
b450da6
fix codestyle
goshadalbeev Apr 14, 2024
1376ebf
Merge remote-tracking branch 'origin/lab5' into lab5
goshadalbeev Apr 14, 2024
116f834
fix codestyle
goshadalbeev Apr 14, 2024
c49a053
fix codestyle
goshadalbeev Apr 14, 2024
9597989
fix codestyle
goshadalbeev Apr 14, 2024
8a0949d
Merge branch 'main' into lab5
goshadalbeev Apr 14, 2024
48800e2
Merge branch 'main' into lab5
goshadalbeev Apr 17, 2024
50d9272
add wrk and profiling. add report
Apr 17, 2024
81601ea
Merge remote-tracking branch 'origin/lab5' into lab5
Apr 17, 2024
869f602
add wrk and profiling. add report
Apr 17, 2024
eb11798
fix report
goshadalbeev Apr 17, 2024
05e6121
fix some words in report
goshadalbeev Apr 18, 2024
85185eb
Merge branch 'main' into lab5
goshadalbeev Apr 24, 2024
e5c9345
fix log
goshadalbeev Apr 25, 2024
d510473
Merge branch 'main' into lab5
May 22, 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

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/ru/vk/itmo/test/georgiidalbeev/MyHandleResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.vk.itmo.test.georgiidalbeev;

public record MyHandleResult(int status, byte[] data, long timestamp) {

public MyHandleResult(int status, byte[] data, long timestamp) {
this.status = status;
this.data = data;
this.timestamp = timestamp;
}

public MyHandleResult(int status, byte[] data) {
this(status, data, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ru.vk.itmo.test.georgiidalbeev;

import one.nio.http.HttpSession;
import one.nio.http.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.concurrent.atomic.AtomicInteger;

public class MyMergeHandleResult {
private static final Logger log = LoggerFactory.getLogger(MyMergeHandleResult.class);
private final AtomicInteger count;
private final AtomicInteger success;
private final int ack;
private final int from;
private final HttpSession session;
private boolean isSent;
MyHandleResult mergedResult = new MyHandleResult(HttpURLConnection.HTTP_GATEWAY_TIMEOUT, null);

public MyMergeHandleResult(HttpSession session, int size, int ack) {
this.session = session;
this.count = new AtomicInteger();
this.ack = ack;
this.from = size;
this.success = new AtomicInteger();
}

public void add(MyHandleResult handleResult) {
int get = count.incrementAndGet();

if (handleResult.status() == HttpURLConnection.HTTP_OK
|| handleResult.status() == HttpURLConnection.HTTP_CREATED
|| handleResult.status() == HttpURLConnection.HTTP_ACCEPTED
|| handleResult.status() == HttpURLConnection.HTTP_NOT_FOUND) {
success.incrementAndGet();
if (mergedResult.timestamp() <= handleResult.timestamp()) {
mergedResult = handleResult;
}
if (success.get() >= ack && !isSent) {
isSent = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не атомарная проверка переменной и ее изменение. можем 2 раза отправить ответ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у меня коммит после дедлайна, потому что идея решила перенести чужие файлы, в моей директории я ничего не трогал, проверьте.

sendResult();
}
}

if (get == from && success.get() < ack && !isSent) {
sendResult();
}
}

private void sendResult() {
try {
if (success.get() < ack) {
session.sendResponse(new Response(Response.GATEWAY_TIMEOUT, Response.EMPTY));
} else {
session.sendResponse(new Response(String.valueOf(mergedResult.status()), mergedResult.data()));
}
} catch (Exception e) {
log.error("Exception during handleRequest", e);
try {
session.sendResponse(new Response(Response.INTERNAL_ERROR, Response.EMPTY));
} catch (IOException ex) {
log.error("Exception while sending close connection", e);
session.scheduleClose();
}
}
}
}
Loading
Loading