use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.
the class FileController method loadFile.
@GetMapping("/{filename}")
public ResponseEntity<AvMessage> loadFile(@PathVariable String filename, Principal principal) {
log.debug("Load file: {}, principal: {}", filename, principal);
AvMessage fileRequest = new DefaultAvMessage.Builder(Utils.genUuidString()).filename(filename).owner(principal.getName()).type(MessageType.FILE_LOAD).build();
restService.loadFile(fileRequest);
AvMessage response;
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < LOAD_MAX_TIME) {
response = restService.getResponse(fileRequest.getId());
if (response != null) {
return new ResponseEntity<>(response, HttpStatus.OK);
}
final long sleepTime = 100;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
log.warn("Loading interrupted!", e);
Thread.currentThread().interrupt();
break;
}
}
return new ResponseEntity<>(fileRequest.createErrorResponse("Load timed out."), HttpStatus.OK);
}
use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.
the class CompositeMessageProcessor method sendMessage.
@Override
public void sendMessage(AvMessage message) {
if (inputFilter != null && checkCondition(inputFilter.negate(), message)) {
log.debug("Filtering out: {}", message);
return;
}
statusStorage.started(message.getId());
AvMessage lastResult = message;
for (ProcessorConfiguration configuration : processors) {
if (!(checkConditions(configuration.getInputConditions().stream(), message, lastResult))) {
log.debug("Input conditions failed for processor: " + configuration);
continue;
}
// process message in a new thread
final AvMessage data = configuration.isUseOriginalMessage() ? message : lastResult;
setActualMessage(data);
new Thread(() -> configuration.getProcessor().sendMessage(data)).start();
// wait for result
try {
final int waitTime = 5;
AvMessage result = queue.poll(waitTime, TimeUnit.SECONDS);
setActualMessage(null);
notifyListeners(listeners, result);
lastResult = result;
} catch (InterruptedException e) {
log.warn("Polling interrupted!", e);
Thread.currentThread().interrupt();
return;
}
}
statusStorage.processed(message.getId());
}
use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.
the class BufferedPerformanceTester method start.
@Override
public void start() {
running = true;
final long loops = testProperties.getMsgCount();
System.out.println("Load test start for " + loops + " messages...");
final int bufferSize = 6;
BlockingQueue<AvMessage> buffer = new ArrayBlockingQueue<>(bufferSize);
long start = System.currentTimeMillis();
for (int loop = 0; loop <= loops; loop++) {
AvMessage message = Utils.genInfectedMessage();
try {
buffer.offer(message, getTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
log.warn("Interrupted.", e);
Thread.currentThread().interrupt();
}
avServiceClient.checkMessage(message);
long start2 = System.currentTimeMillis();
while (buffer.size() >= bufferSize && (System.currentTimeMillis() - start2) < getTimeout()) {
getMessage(buffer);
}
}
long start3 = System.currentTimeMillis();
while (buffer.size() > 0 && (System.currentTimeMillis() - start3) < getTimeout()) {
getMessage(buffer);
}
long duration = System.currentTimeMillis() - start;
System.out.println("Load test end.");
float durationSeconds = duration / MS_PER_SECOND;
setResult(loops / durationSeconds);
System.out.println("\nDuration: " + durationSeconds + " s");
System.out.println("Messages: " + result + "/s");
running = false;
}
use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.
the class SimpleChecker method check.
@Override
public boolean check() {
AvMessage normalMessage = Utils.genMessage();
AvMessage infectedMessage = Utils.genInfectedMessage();
sendAvMessage(normalMessage);
try {
AvMessage receivedMessage = receiveMessage(normalMessage.getId());
if (isInfected(receivedMessage)) {
return false;
}
} catch (MessageNotFoundException e) {
log.debug("Message not found.", e);
return false;
}
sendAvMessage(infectedMessage);
try {
AvMessage receivedMessage = receiveMessage(infectedMessage.getId());
if (!isInfected(receivedMessage)) {
return false;
}
} catch (MessageNotFoundException e) {
log.debug("Message not found.", e);
return false;
}
return true;
}
use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.
the class PerformanceTester method start.
@Override
public void start() {
running = true;
boolean perfect = true;
final long loops = testProperties.getMsgCount();
final long maxRate = testProperties.getMaxRate();
System.out.println("Load test start for " + loops + " messages...");
long start = System.currentTimeMillis();
long maxRateCounter = start;
for (int i = 0; i < loops; i++) {
AvMessage message = Utils.genInfectedMessage();
checker.sendAvMessage(message);
try {
checker.receiveMessage(message.getId());
} catch (MessageNotFoundException e) {
log.warn("Message not found.", e);
perfect = false;
}
if (maxRate == 0) {
continue;
}
long delta = System.currentTimeMillis() - maxRateCounter;
if (i % maxRate == 0 && delta < MS_PER_SECOND) {
sleep(delta);
maxRateCounter = System.currentTimeMillis();
}
}
long duration = System.currentTimeMillis() - start;
System.out.println("Load test end.");
float durationSeconds = duration / MS_PER_SECOND;
setResult(loops / durationSeconds);
System.out.println("\nDuration: " + durationSeconds + " s");
System.out.println("Messages: " + result + "/s");
if (!perfect) {
System.out.println("\nSome messages were lost.");
} else {
passed = true;
}
running = false;
}
Aggregations