com.google.inject.spi.DefaultBindingScopingVisitor Java Examples
The following examples show how to use
com.google.inject.spi.DefaultBindingScopingVisitor.
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: MultipleSingletonPluginUITest.java From n4js with Eclipse Public License 1.0 | 6 votes |
private boolean isSingleton(Binding<?> b) { return b.acceptScopingVisitor(new DefaultBindingScopingVisitor<Boolean>() { @Override public Boolean visitEagerSingleton() { return Boolean.TRUE; } @Override public Boolean visitScope(Scope scope) { return Scopes.SINGLETON.equals(scope); } @Override protected Boolean visitOther() { return Boolean.FALSE; } }); }
Example #2
Source File: GuiceServiceModule.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override protected void configure() { binder().bindListener(Matchers.any(), new ProvisionListener() { @Override public <T> void onProvision(ProvisionInvocation<T> provision) { final Binding<T> binding = provision.getBinding(); logger.debug("provisioning {}", binding.getKey().getTypeLiteral()); final T provisioned = provision.provision(); if (provisioned != null && Service.class.isAssignableFrom(provisioned.getClass())) { final AtomicBoolean start = new AtomicBoolean(false); binding.acceptScopingVisitor(new DefaultBindingScopingVisitor<T>() { @Override public T visitEagerSingleton() { start.set(true); return super.visitEagerSingleton(); } @Override public T visitScope(Scope scope) { if (scope instanceof SingletonScope) { start.set(true); } return super.visitScope(scope); } }); if (start.get()) { serviceList.push(binding.getKey().getTypeLiteral().getRawType()); try { logger.debug("starting {}", binding.getKey().getTypeLiteral()); ((Service) provisioned).start(); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } } } } }); }