Search in sources :

Example 1 with CodekvastPublishingException

use of io.codekvast.javaagent.publishing.CodekvastPublishingException in project codekvast by crispab.

the class HttpInvocationDataPublisherImpl method doPublishInvocationData.

@Override
void doPublishInvocationData(long recordingIntervalStartedAtMillis, Set<String> invocations) throws CodekvastPublishingException {
    if (invocations.isEmpty()) {
        logger.fine("Codekvast detected no invocations to publish");
        return;
    }
    String url = getConfig().getInvocationDataUploadEndpoint();
    File file = null;
    try {
        InvocationDataPublication2 publication = createPublication(getCustomerId(), recordingIntervalStartedAtMillis, invocations);
        file = FileUtils.serializeToFile(publication, getConfig().getFilenamePrefix("invocations-"), ".ser");
        doPost(file, url, getCodeBaseFingerprint().toString(), publication.getInvocations().size());
        logger.fine(String.format("Codekvast uploaded %d invocations (%s) to %s", publication.getInvocations().size(), LogUtil.humanReadableByteCount(file.length()), url));
    } catch (Exception e) {
        throw new CodekvastPublishingException("Cannot upload invocation data to " + url, e);
    } finally {
        FileUtils.safeDelete(file);
    }
}
Also used : CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) File(java.io.File) CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) InvocationDataPublication2(io.codekvast.javaagent.model.v2.InvocationDataPublication2)

Example 2 with CodekvastPublishingException

use of io.codekvast.javaagent.publishing.CodekvastPublishingException in project codekvast by crispab.

the class InvocationRegistryTest method doExtremelyConcurrentRegistrationOf.

private boolean doExtremelyConcurrentRegistrationOf(final Signature... signatures) throws InterruptedException {
    val numThreads = 25;
    val numRegistrations = 10_000;
    val finishLine = new CountDownLatch(numThreads * numRegistrations);
    val random = new Random();
    val startingGun = new CountDownLatch(1);
    for (int i = 0; i < numThreads; i++) {
        Thread t = new Thread(() -> {
            try {
                int max = signatures.length;
                startingGun.await();
                for (int j = 0; j < numRegistrations; j++) {
                    InvocationRegistry.registerMethodInvocation(signatures[random.nextInt(max)]);
                    finishLine.countDown();
                }
            } catch (InterruptedException ignore) {
                Thread.currentThread().interrupt();
            }
        });
        t.start();
    }
    Thread publisher = new Thread(() -> {
        NullInvocationDataPublisher publisher1 = new NullInvocationDataPublisher();
        try {
            startingGun.await();
            while (true) {
                InvocationRegistry.publishInvocationData(publisher1);
            }
        } catch (InterruptedException | CodekvastPublishingException ignore) {
            Thread.currentThread().interrupt();
        }
    });
    publisher.start();
    startingGun.countDown();
    finishLine.await();
    publisher.interrupt();
    InvocationRegistry.initialize(null);
    return true;
}
Also used : lombok.val(lombok.val) Random(java.util.Random) CountDownLatch(java.util.concurrent.CountDownLatch) CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) CodeBaseFingerprint(io.codekvast.javaagent.codebase.CodeBaseFingerprint)

Example 3 with CodekvastPublishingException

use of io.codekvast.javaagent.publishing.CodekvastPublishingException in project codekvast by crispab.

the class HttpCodeBasePublisherImpl method doPublishCodeBase.

@Override
public void doPublishCodeBase(CodeBase codeBase) throws CodekvastPublishingException {
    String url = getConfig().getCodeBaseUploadEndpoint();
    File file = null;
    try {
        CodeBasePublication3 publication = codeBase.getCodeBasePublication(getCustomerId(), this.getSequenceNumber());
        file = FileUtils.serializeToFile(publication, getConfig().getFilenamePrefix("codebase-"), ".ser");
        doPost(file, url, codeBase.getFingerprint().toString(), publication.getEntries().size());
        logger.fine(String.format("Codekvast uploaded %d methods (%s) to %s", publication.getEntries().size(), LogUtil.humanReadableByteCount(file.length()), url));
    } catch (IOException e) {
        throw new CodekvastPublishingException("Cannot upload code base to " + url, e);
    } finally {
        FileUtils.safeDelete(file);
    }
}
Also used : CodeBasePublication3(io.codekvast.javaagent.model.v3.CodeBasePublication3) IOException(java.io.IOException) CodekvastPublishingException(io.codekvast.javaagent.publishing.CodekvastPublishingException) File(java.io.File)

Aggregations

CodekvastPublishingException (io.codekvast.javaagent.publishing.CodekvastPublishingException)3 File (java.io.File)2 CodeBaseFingerprint (io.codekvast.javaagent.codebase.CodeBaseFingerprint)1 InvocationDataPublication2 (io.codekvast.javaagent.model.v2.InvocationDataPublication2)1 CodeBasePublication3 (io.codekvast.javaagent.model.v3.CodeBasePublication3)1 IOException (java.io.IOException)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 lombok.val (lombok.val)1