Search in sources :

Example 1 with Explain

use of sirius.kernel.commons.Explain in project sirius-db by scireum.

the class Mongo method setupClient.

@SuppressWarnings("squid:S2095")
@Explain("We cannot close the client here as it is part of the return value.")
protected synchronized Tuple<MongoClient, String> setupClient(String database) {
    Extension config = Sirius.getSettings().getExtension("mongo.databases", database);
    String connectionString = Arrays.stream(config.get("hosts").asString().split(",")).map(String::trim).map(hostname -> PortMapper.mapPort(SERVICE_NAME, hostname, MONGO_PORT)).map(hostAndPort -> hostAndPort.getFirst() + ":" + hostAndPort.getSecond()).collect(Collectors.joining(","));
    MongoClientSettings.Builder settingsBuilder = MongoClientSettings.builder().applyConnectionString(new ConnectionString("mongodb://" + connectionString)).applicationName(CallContext.getNodeName());
    MongoCredential credentials = determineCredentials(config);
    if (credentials != null) {
        settingsBuilder.credential(credentials);
    }
    MongoClient mongoClient = MongoClients.create(settingsBuilder.build());
    createIndices(database, mongoClient.getDatabase(config.get("db").asString()));
    return Tuple.create(mongoClient, config.get("db").asString());
}
Also used : Extension(sirius.kernel.settings.Extension) ReadPreference(com.mongodb.ReadPreference) Log(sirius.kernel.health.Log) Arrays(java.util.Arrays) MongoCredential(com.mongodb.MongoCredential) MongoClient(com.mongodb.client.MongoClient) Watch(sirius.kernel.commons.Watch) Exceptions(sirius.kernel.health.Exceptions) MongoDatabase(com.mongodb.client.MongoDatabase) Explain(sirius.kernel.commons.Explain) Parts(sirius.kernel.di.std.Parts) Sirius(sirius.kernel.Sirius) ConfigValue(sirius.kernel.di.std.ConfigValue) Duration(java.time.Duration) Map(java.util.Map) Counter(sirius.kernel.health.Counter) Nullable(javax.annotation.Nullable) Mixing(sirius.db.mixing.Mixing) PartCollection(sirius.kernel.di.PartCollection) MongoClients(com.mongodb.client.MongoClients) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CallContext(sirius.kernel.async.CallContext) Tuple(sirius.kernel.commons.Tuple) Collectors(java.util.stream.Collectors) Register(sirius.kernel.di.std.Register) Average(sirius.kernel.health.Average) ConnectionString(com.mongodb.ConnectionString) Stoppable(sirius.kernel.Stoppable) Extension(sirius.kernel.settings.Extension) PortMapper(sirius.kernel.settings.PortMapper) Startable(sirius.kernel.Startable) MongoClientSettings(com.mongodb.MongoClientSettings) MongoClient(com.mongodb.client.MongoClient) MongoCredential(com.mongodb.MongoCredential) ConnectionString(com.mongodb.ConnectionString) MongoClientSettings(com.mongodb.MongoClientSettings) ConnectionString(com.mongodb.ConnectionString) Explain(sirius.kernel.commons.Explain)

Example 2 with Explain

use of sirius.kernel.commons.Explain in project sirius-db by scireum.

the class Redis method started.

@Override
@SuppressWarnings("squid:S2250")
@Explain("There aren't that many subscriptions, so there is no performance hotspot")
public void started() {
    if (!isConfigured()) {
        return;
    }
    for (Subscriber subscriber : subscribers) {
        JedisPubSub subscription = new JedisPubSub() {

            @Override
            public void onMessage(String channel, String message) {
                handlePubSubMessage(channel, message, subscriber);
            }
        };
        subscriptions.add(subscription);
        new Thread(() -> subscribe(subscriber, subscription), "redis-subscriber-" + subscriber.getTopic()).start();
    }
}
Also used : JedisPubSub(redis.clients.jedis.JedisPubSub) Explain(sirius.kernel.commons.Explain)

Example 3 with Explain

use of sirius.kernel.commons.Explain in project sirius-biz by scireum.

the class ProcessEnvironment method addZipFile.

@Override
@SuppressWarnings("java:S2095")
@Explain("The stream is closed in a finally-block within the callback")
public OutputStream addZipFile(String zipArchiveName, String filename) throws IOException {
    File zipFile = Files.createTempFile("ZipBuilder", ".zip").toFile();
    ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFile));
    zipOutputStream.putNextEntry(new ZipEntry(filename));
    WatchableOutputStream outputStream = new WatchableOutputStream(new UncloseableOutputStream(zipOutputStream));
    outputStream.getCompletionFuture().onSuccess(() -> {
        try {
            zipOutputStream.closeEntry();
            zipOutputStream.close();
            addFile(zipArchiveName, zipFile);
        } catch (Exception e) {
            throw Exceptions.handle(Log.BACKGROUND, e);
        } finally {
            sirius.kernel.commons.Files.delete(zipFile);
        }
    });
    return outputStream;
}
Also used : WatchableOutputStream(sirius.biz.storage.util.WatchableOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) HandledException(sirius.kernel.health.HandledException) IOException(java.io.IOException) UncloseableOutputStream(sirius.kernel.commons.UncloseableOutputStream) Explain(sirius.kernel.commons.Explain)

Example 4 with Explain

use of sirius.kernel.commons.Explain in project sirius-biz by scireum.

the class BlobDispatcher method virtualDelivery.

/**
 * Prepares a {@link Response} and delegates the call to the layer 2.
 *
 * @param request     the request to handle
 * @param space       the space which is accessed
 * @param accessToken the security token to verify
 * @param variant     the variant to deliver - {@link URLBuilder#VARIANT_RAW} will be used to deliver the blob
 *                    itself
 * @param blobKey     the blob object key used to determine which {@link Blob} should be delivered
 * @param filename    the filename which is used to set up a proper <tt>Content-Type</tt>
 * @param download    determines if a download should be generated
 * @param cacheable   determines if HTTP caching should be supported (<tt>true</tt>) or suppressed (<tt>false</tt>)
 */
@SuppressWarnings("squid:S00107")
@Explain("As this is a super hot code path we use 8 parameters instead of a parameter object" + " as this makes the URL parsing quite obvious")
private void virtualDelivery(WebContext request, String space, String accessToken, @Nullable String variant, String blobKey, String filename, boolean download, boolean cacheable) {
    if (!utils.verifyHash(Strings.isFilled(variant) ? blobKey + "-" + variant : blobKey, accessToken)) {
        request.respondWith().error(HttpResponseStatus.UNAUTHORIZED);
        return;
    }
    BlobStorageSpace storageSpace = blobStorage.getSpace(space);
    Response response = request.respondWith();
    if (cacheable) {
        response.cached();
    } else {
        response.notCached();
    }
    if (download) {
        if (Strings.areEqual(filename, blobKey)) {
            filename = storageSpace.resolveFilename(blobKey).orElse(filename);
        }
        response.download(filename);
    } else {
        response.named(filename);
    }
    storageSpace.deliver(blobKey, variant != null ? variant : URLBuilder.VARIANT_RAW, response, request::markAsLongCall);
}
Also used : Response(sirius.web.http.Response) Explain(sirius.kernel.commons.Explain)

Example 5 with Explain

use of sirius.kernel.commons.Explain in project sirius-biz by scireum.

the class EntityExportJobFactory method createJob.

@SuppressWarnings("squid:S2095")
@Explain("The job must not be closed here as it is returned and managed by the caller.")
@Override
protected EntityExportJob<E, Q> createJob(ProcessContext process) {
    // We only resolve the parameters once and keep the final values around in a local context...
    ImportContext paramterContext = new ImportContext();
    transferParameters(paramterContext, process);
    return new EntityExportJob<E, Q>(getExportType(), getDictionary(), getDefaultMapping(), process, getName()).withQueryExtender(query -> extendSelectQuery(query, process)).withContextExtender(context -> context.putAll(paramterContext)).withFileName(getCustomFileName());
}
Also used : Log(sirius.kernel.health.Log) JobInfoCollector(sirius.biz.jobs.infos.JobInfoCollector) BaseEntity(sirius.db.mixing.BaseEntity) Exceptions(sirius.kernel.health.Exceptions) Explain(sirius.kernel.commons.Explain) Consumer(java.util.function.Consumer) ImportContext(sirius.biz.importer.ImportContext) List(java.util.List) Query(sirius.db.mixing.query.Query) ImportDictionary(sirius.biz.importer.format.ImportDictionary) Importer(sirius.biz.importer.Importer) ProcessContext(sirius.biz.process.ProcessContext) Parameter(sirius.biz.jobs.params.Parameter) ImportContext(sirius.biz.importer.ImportContext) Explain(sirius.kernel.commons.Explain)

Aggregations

Explain (sirius.kernel.commons.Explain)10 Nullable (javax.annotation.Nullable)2 Watch (sirius.kernel.commons.Watch)2 Exceptions (sirius.kernel.health.Exceptions)2 Log (sirius.kernel.health.Log)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AS400 (com.ibm.as400.access.AS400)1 ConnectionString (com.mongodb.ConnectionString)1 MongoClientSettings (com.mongodb.MongoClientSettings)1 MongoCredential (com.mongodb.MongoCredential)1 ReadPreference (com.mongodb.ReadPreference)1 MongoClient (com.mongodb.client.MongoClient)1 MongoClients (com.mongodb.client.MongoClients)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1