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