Search in sources :

Example 1 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class RepositoryPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) {
    if (env.isServer()) {
        LOG.debug("Initializing repository plugin.");
        final MeterRegistry registry = env.service(MeterRegistry.class);
        final IEventBus eventBus = env.service(IEventBus.class);
        // Add event bus based request metrics
        registerRequestMetrics(registry, eventBus);
        final IManagedContainer container = env.container();
        RpcUtil.getInitialServerSession(container).registerServiceLookup(env::service);
        Net4jUtil.prepareContainer(container);
        JVMUtil.prepareContainer(container);
        TCPUtil.prepareContainer(container);
        LifecycleUtil.activate(container);
        final HostAndPort hostAndPort = env.service(RepositoryConfiguration.class).getHostAndPort();
        // open port in server environments
        if (hostAndPort.getPort() > 0) {
            // Starts the TCP transport
            TCPUtil.getAcceptor(container, hostAndPort.toString());
            LOG.info("Listening on {} for connections", hostAndPort);
        }
        // Starts the JVM transport
        JVMUtil.getAcceptor(container, TransportClient.NET_4_J_CONNECTOR_NAME);
        final RepositoryManager repositoryManager = new DefaultRepositoryManager();
        env.services().registerService(RepositoryManager.class, repositoryManager);
        env.services().registerService(RepositoryContextProvider.class, repositoryManager);
        int numberOfWorkers = env.service(RepositoryConfiguration.class).getMaxThreads();
        initializeRequestSupport(env, numberOfWorkers);
        LOG.debug("Initialized repository plugin.");
    } else {
        LOG.debug("Snow Owl application is running in remote mode.");
    }
    if (env.isServer()) {
        try {
            connectSystemUser(env.container());
        } catch (SnowowlServiceException e) {
            throw new SnowowlRuntimeException(e);
        }
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) IManagedContainer(org.eclipse.net4j.util.container.IManagedContainer) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) SnowowlServiceException(com.b2international.snowowl.core.api.SnowowlServiceException) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) IEventBus(com.b2international.snowowl.eventbus.IEventBus) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 2 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class RepositoryPlugin method initializeRequestSupport.

private void initializeRequestSupport(Environment env, int numberOfWorkers) {
    final IEventBus events = env.service(IEventBus.class);
    final ClassLoader classLoader = env.plugins().getCompositeClassLoader();
    for (int i = 0; i < numberOfWorkers; i++) {
        events.registerHandler(Request.ADDRESS, new ApiRequestHandler(env, classLoader));
    }
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus)

Example 3 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class CommitInfoRequestTest method searchCommitInfoByBranch.

@Test
public void searchCommitInfoByBranch() {
    final String oid = UUID.randomUUID().toString();
    final String shortName = "Resource6";
    final String comment = "Code system for commit info 6";
    final String branchName = "Test6";
    final String term = "Test Description 6";
    createCodeSystem(shortName, oid, comment);
    final String branchPath = createBranch(String.format("%s/%s", BRANCH, shortName), branchName);
    createDescription(ResourceURI.branch(CodeSystem.RESOURCE_TYPE, shortName, branchName), term, comment);
    // Search as admin
    assertEquals(1, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByBranch(branchPath).build(REPOSITORY_ID).execute(bus).getSync().getTotal());
    final Permission userPermission = Permission.requireAll(Permission.OPERATION_BROWSE, String.format("%s*", shortName));
    final List<Role> roles = List.of(new Role("Editor", List.of(userPermission)));
    final String userName = "User6";
    final User user = new User(userName, roles);
    final IEventBus authorizedBus = new AuthorizedEventBus(bus, ImmutableMap.of(AuthorizedRequest.AUTHORIZATION_HEADER, Services.service(JWTGenerator.class).generate(user)));
    // Search as user with limited permissions
    assertEquals(1, RepositoryRequests.commitInfos().prepareSearchCommitInfo().filterByBranch(branchPath).build(REPOSITORY_ID).execute(authorizedBus).getSync().getTotal());
}
Also used : Role(com.b2international.snowowl.core.identity.Role) User(com.b2international.snowowl.core.identity.User) JWTGenerator(com.b2international.snowowl.core.identity.JWTGenerator) Permission(com.b2international.snowowl.core.identity.Permission) AuthorizedEventBus(com.b2international.snowowl.core.authorization.AuthorizedEventBus) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 4 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class PipeTest method pipeToWorker.

@Test
public void pipeToWorker() throws Exception {
    IEventBus target = EventBusUtil.getWorkerBus("worker", 2);
    LifecycleUtil.activate(target);
    final CountDownLatch sourceLatch = new CountDownLatch(1);
    final CountDownLatch targetLatch = new CountDownLatch(1);
    bus.registerHandler(ADDRESS, new Pipe(target, ADDRESS));
    target.registerHandler("work-address", new IHandler<IMessage>() {

        @Override
        public void handle(IMessage message) {
            try {
                Thread.sleep(30_000L);
            } catch (InterruptedException ignored) {
            }
        }
    });
    target.registerHandler(ADDRESS, new CountDownHandler(SEND_MESSAGE, targetLatch) {

        @Override
        public void handle(IMessage message) {
            super.handle(message);
            message.reply(REPLY_MESSAGE);
        }
    });
    /* 
		 * XXX: In a regular event bus, the third (reply) registered message handler would be queued after the 
		 * long-running "work-address" handler, and would block.
		 */
    setWaitTime(1);
    target.send("work-address", new Object(), null);
    bus.send(ADDRESS, SEND_MESSAGE, null, new CountDownHandler(REPLY_MESSAGE, sourceLatch));
    wait(targetLatch);
    wait(sourceLatch);
}
Also used : IMessage(com.b2international.snowowl.eventbus.IMessage) Pipe(com.b2international.snowowl.eventbus.Pipe) CountDownLatch(java.util.concurrent.CountDownLatch) CountDownHandler(com.b2international.snowowl.eventbus.util.CountDownHandler) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 5 with IEventBus

use of com.b2international.snowowl.eventbus.IEventBus in project snow-owl by b2ihealthcare.

the class EventBusHandlerRegistrationTest method test_UnregisterHandler_NonNull_Null.

@Test
public void test_UnregisterHandler_NonNull_Null() {
    final IEventBus actual = bus.unregisterHandler(ADDRESS, null);
    assertEquals(bus, actual);
}
Also used : IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Aggregations

IEventBus (com.b2international.snowowl.eventbus.IEventBus)17 Test (org.junit.Test)10 ResourceURI (com.b2international.snowowl.core.ResourceURI)3 Promise (com.b2international.snowowl.core.events.util.Promise)3 TimeUnit (java.util.concurrent.TimeUnit)3 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)2 JWTGenerator (com.b2international.snowowl.core.identity.JWTGenerator)2 Permission (com.b2international.snowowl.core.identity.Permission)2 Role (com.b2international.snowowl.core.identity.Role)2 User (com.b2international.snowowl.core.identity.User)2 JobRequests (com.b2international.snowowl.core.jobs.JobRequests)2 AbstractRestService (com.b2international.snowowl.core.rest.AbstractRestService)2 IMessage (com.b2international.snowowl.eventbus.IMessage)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Parameter (io.swagger.v3.oas.annotations.Parameter)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2 Tag (io.swagger.v3.oas.annotations.tags.Tag)2 HttpStatus (org.springframework.http.HttpStatus)2 ResponseEntity (org.springframework.http.ResponseEntity)2