org.eclipse.sisu.inject.DefaultBeanLocator Java Examples

The following examples show how to use org.eclipse.sisu.inject.DefaultBeanLocator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NexusContextModule.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configure() {

  // we will look these up later...
  requireBinding(GuiceFilter.class);
  requireBinding(BeanManager.class);
  requireBinding(ApplicationVersion.class);

  bind(ServletContext.class).toInstance(servletContext);
  bind(ParameterKeys.PROPERTIES).toInstance(nexusProperties);

  install(new StateGuardModule());
  install(new TransactionModule());
  install(new TimeTypeConverter());
  install(new WebSecurityModule(servletContext));

  // enable OSGi service lookup of Karaf components
  final MutableBeanLocator locator = new DefaultBeanLocator();
  locator.add(new ServiceBindings(bundleContext, ALLOW_SERVICES, IGNORE_SERVICES, Integer.MIN_VALUE));
  bind(MutableBeanLocator.class).toInstance(locator);

  bind(ManagedLifecycleManager.class).toInstance(new NexusLifecycleManager(locator, bundleContext.getBundle(0)));
}
 
Example #2
Source File: EventManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void dispatchOrder() {
  EventManager underTest = new EventManagerImpl(new DefaultBeanLocator(), newEventExecutor());
  ReentrantHandler handler = new ReentrantHandler(underTest);

  underTest.register(handler);
  underTest.post("a string");

  assertThat(handler.firstCalled, is("handle2"));
}
 
Example #3
Source File: EventManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void asyncInheritsIsReplicating() throws Exception {
  EventExecutor executor = newEventExecutor();
  EventManager underTest = new EventManagerImpl(new DefaultBeanLocator(), executor);
  AsyncReentrantHandler handler = new AsyncReentrantHandler(underTest);
  underTest.register(handler);

  executor.start(); // enable multi-threaded mode

  // non-replicating case
  FakeAlmightySubject.forUserId("testUser").execute(
      () -> underTest.post("a string"));

  await().atMost(5, TimeUnit.SECONDS).until(underTest::isCalmPeriod);

  // handled two events, neither were replicating
  assertThat(handler.handledCount.get(), is(2));
  assertThat(handler.replicatingCount.get(), is(0));

  // replicating case
  FakeAlmightySubject.forUserId("testUser").execute(
      () -> EventHelper.asReplicating(
          () -> underTest.post("a string")));

  await().atMost(5, TimeUnit.SECONDS).until(underTest::isCalmPeriod);

  // handled two more events, both were replicating
  assertThat(handler.handledCount.get(), is(4));
  assertThat(handler.replicatingCount.get(), is(2));

  executor.stop(); // go back to single-threaded mode
}
 
Example #4
Source File: EventManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void singleThreadedOnShutdown() throws Exception {
  EventExecutor executor = newEventExecutor();
  EventManager underTest = new EventManagerImpl(new DefaultBeanLocator(), executor);
  AsyncHandler handler = new AsyncHandler();
  underTest.register(handler);

  FakeAlmightySubject.forUserId("testUser").execute(() -> underTest.post("first"));

  // executor is initially in single-threaded mode

  assertThat(handler.handledByThread, hasSize(1));
  assertThat(handler.handledByThread.get(0), is(Thread.currentThread()));

  executor.start(); // enable multi-threaded mode

  FakeAlmightySubject.forUserId("testUser").execute(() -> underTest.post("foo"));
  FakeAlmightySubject.forUserId("testUser").execute(() -> underTest.post("bar"));

  executor.stop(); // waits for threads to finish

  assertThat(handler.handledByThread, hasSize(3));
  assertThat(handler.handledByThread.get(1), is(not(Thread.currentThread())));
  assertThat(handler.handledByThread.get(2), is(not(Thread.currentThread())));
  assertThat(handler.handledByThread.get(1), is(not(handler.handledByThread.get(2))));

  // executor is now back in single-threaded mode

  FakeAlmightySubject.forUserId("testUser").execute(() -> underTest.post("last"));

  assertThat(handler.handledByThread, hasSize(4));
  assertThat(handler.handledByThread.get(3), is(Thread.currentThread()));
}