Search in sources :

Example 16 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method test50JobsOfAllTypes.

@Test
public void test50JobsOfAllTypes() {
    final IJobManager manager = Job.getJobManager();
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    validationPromises.add(pool.submit(CheckType.EXPENSIVE, createValidatableRunnable(CheckType.EXPENSIVE, manager)));
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.FAST, createValidatableRunnable(CheckType.FAST, manager)));
        validationPromises.add(pool.submit(CheckType.NORMAL, createValidatableRunnable(CheckType.NORMAL, manager)));
        if (i % 3 == 0) {
            validationPromises.add(pool.submit(CheckType.EXPENSIVE, createValidatableRunnable(CheckType.EXPENSIVE, manager)));
        }
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Example 17 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method testConcurrentNormalJobsWithFastOnes.

@Test
public void testConcurrentNormalJobsWithFastOnes() {
    final IJobManager manager = Job.getJobManager();
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.NORMAL, createValidatableRunnable(CheckType.NORMAL, manager)));
        if (i % 2 == 0) {
            validationPromises.add(pool.submit(CheckType.FAST, createValidatableRunnable(CheckType.FAST, manager)));
        }
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Example 18 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class ValidationThreadPoolTest method TestConcurrentNormalJobs.

@Test
public void TestConcurrentNormalJobs() {
    final IJobManager manager = Job.getJobManager();
    final Runnable fastRunnable = createValidatableRunnable(CheckType.NORMAL, manager);
    final List<Promise<Object>> validationPromises = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        validationPromises.add(pool.submit(CheckType.NORMAL, fastRunnable));
    }
    Promise.all(validationPromises).getSync();
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Test(org.junit.Test)

Example 19 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method upgrade.

@Operation(summary = "Start a Code System dependency upgrade (EXPERIMENTAL)", description = "Starts the upgrade process of a Code System to a newer extensionOf Code System dependency than the current extensionOf.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Upgrade created"), @ApiResponse(responseCode = "400", description = "Code System cannot be upgraded") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.CREATED)
public Promise<ResponseEntity<Void>> upgrade(@RequestBody final UpgradeRestInput body) {
    final UriComponentsBuilder uriBuilder = createURIBuilder();
    final ResourceURI upgradeOf = new ResourceURI(body.getUpgradeOf());
    final IEventBus bus = getBus();
    return // TODO move this to generic resource controller
    CodeSystemRequests.prepareGetCodeSystem(upgradeOf.getResourceId()).buildAsync().execute(bus).thenWith(codeSystem -> {
        return CodeSystemRequests.prepareUpgrade(upgradeOf, new ResourceURI(body.getExtensionOf())).setResourceId(body.getCodeSystemId()).buildAsync().execute(bus);
    }).then(upgradeCodeSystemId -> {
        return ResponseEntity.created(uriBuilder.pathSegment(upgradeCodeSystemId).build().toUri()).build();
    });
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) IEventBus(com.b2international.snowowl.eventbus.IEventBus) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) NotFoundException(com.b2international.commons.exceptions.NotFoundException) ResourceURI(com.b2international.snowowl.core.ResourceURI) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 20 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class EclExpression method resolve.

public Promise<Set<String>> resolve(final BranchContext context) {
    if (promise == null) {
        RevisionSearcher searcher = context.service(RevisionSearcher.class);
        boolean cached = context.optionalService(PathWithVersion.class).isPresent();
        promise = resolveToExpression(context).then(expression -> {
            // shortcut to extract IDs from the query itself if possible
            if (SnomedEclEvaluationRequest.canExtractIds(expression)) {
                return SnomedEclEvaluationRequest.extractIds(expression);
            }
            try {
                return newHashSet(searcher.search(Query.select(String.class).from(SnomedConceptDocument.class).fields(SnomedConceptDocument.Fields.ID).where(expression).limit(Integer.MAX_VALUE).cached(cached).build()));
            } catch (IOException e) {
                throw new SnowowlRuntimeException(e);
            }
        });
    }
    return promise;
}
Also used : Query(com.b2international.index.query.Query) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) NestedExpression(com.b2international.snomed.ecl.ecl.NestedExpression) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Nullable(javax.annotation.Nullable) ResourceURI(com.b2international.snowowl.core.ResourceURI) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RevisionDocument(com.b2international.snowowl.core.repository.RevisionDocument) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Set(java.util.Set) IOException(java.io.IOException) IEventBus(com.b2international.snowowl.eventbus.IEventBus) NotNull(javax.validation.constraints.NotNull) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Any(com.b2international.snomed.ecl.ecl.Any) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) List(java.util.List) Expressions(com.b2international.index.query.Expressions) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Expression(com.b2international.index.query.Expression) Preconditions(com.google.common.base.Preconditions) Ecl(com.b2international.snomed.ecl.Ecl) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) EclConceptReference(com.b2international.snomed.ecl.ecl.EclConceptReference) ExpressionConstraint(com.b2international.snomed.ecl.ecl.ExpressionConstraint) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) IOException(java.io.IOException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Aggregations

Promise (com.b2international.snowowl.core.events.util.Promise)22 ResourceURI (com.b2international.snowowl.core.ResourceURI)10 TimeUnit (java.util.concurrent.TimeUnit)10 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)9 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)9 IOException (java.io.IOException)9 List (java.util.List)9 Test (org.junit.Test)9 BranchContext (com.b2international.snowowl.core.domain.BranchContext)8 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)7 IEventBus (com.b2international.snowowl.eventbus.IEventBus)7 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)7 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)7 Trees (com.b2international.snowowl.snomed.core.tree.Trees)7 Function (com.google.common.base.Function)7 Collection (java.util.Collection)7