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());
}
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();
}
}
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;
}
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);
}
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());
}
Aggregations