Search in sources :

Example 1 with AvMessage

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AvMessage(dvoraka.avservice.common.data.AvMessage) DefaultAvMessage(dvoraka.avservice.common.data.DefaultAvMessage) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with AvMessage

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());
}
Also used : AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 3 with AvMessage

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;
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 4 with AvMessage

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;
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 5 with AvMessage

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;
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Aggregations

AvMessage (dvoraka.avservice.common.data.AvMessage)10 DefaultAvMessage (dvoraka.avservice.common.data.DefaultAvMessage)3 MessageNotFoundException (dvoraka.avservice.common.exception.MessageNotFoundException)3 ResponseEntity (org.springframework.http.ResponseEntity)2 MapperException (dvoraka.avservice.common.exception.MapperException)1 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 JMSException (javax.jms.JMSException)1 Message (org.springframework.amqp.core.Message)1 MessageProperties (org.springframework.amqp.core.MessageProperties)1 MessageConversionException (org.springframework.amqp.support.converter.MessageConversionException)1 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1