public ProvisionException createProvisionException( final ProvisionInvocation<?> provision, final Throwable t ) { // On any unexpected provision exception, ensure that we get the full stack trace into the log. // We do this by separating each exception in the causal chain into a separate message. Guice, // by convention, will print the individual causes in a messages list. Unfortunately, we have to // do this because Guice will swallow stack traces for only a single exception. final List<Message> messages = Throwables.getCausalChain(t).stream() .map(cause -> new Message( cause.getClass().getSimpleName() + " during provision of " + provision.getBinding().getKey().getTypeLiteral(), cause )) .collect(Collectors.toList()); return new ProvisionException(messages); } }
@Override public <T> String format(ProvisionInvocation<T> provision, Throwable t) { return String.format("Error creating '%s'. %s", provision.getBinding().getKey().toString(), t.getMessage()); } };
Object source = provision.getBinding().getSource(); if(source != null && source.toString().contains("spring-guice")) { return; preDestroyMonitor.register(injectee, provision.getBinding(), actions.preDestroyActions);
@Override public <T> void onProvision(ProvisionInvocation<T> provision) { Class<?> clazz = provision.getBinding().getKey().getTypeLiteral().getRawType();
@Override public <T> void onProvision(ProvisionInvocation<T> provision) { LOG.trace("Found new binding {}", provision.getBinding()); final T result = provision.provision(); if (result == null) { return; } Class<?> klass = result.getClass(); // Loop over the class and superclasses do { for (final Method m : klass.getDeclaredMethods()) { // Inspect declared methods for @OnStage final OnStage onStage = m.getAnnotation(OnStage.class); if (onStage == null) { continue; } LOG.trace("Will invoke {} on {}", m, onStage.value()); LifecycleInvocation invocation = new LifecycleInvocation(new LifecycleStage(onStage.value()), result, m); if (lifecycle != null) { // If the lifecycle is available, register now addListener(invocation); } else { // Otherwise, do it later, when the lifecycle is injected Preconditions.checkState(foundInvocations != null, "Injection after lifecycle start!"); foundInvocations.add(invocation); } } klass = klass.getSuperclass(); } while (klass != null); }
@Override public <T> void onProvision(ProvisionInvocation<T> provision) { T instance = provision.provision(); if (instance != null) { Binding<T> binding = provision.getBinding(); LifecycleManager manager = lifecycleManager.get(); if (manager != null) { Key<T> bindingKey = binding.getKey(); LOGGER.trace("provisioning instance of {}", bindingKey); TypeLiteral<T> bindingType = bindingKey.getTypeLiteral(); for (LifecycleListener listener : manager.getListeners()) { listener.objectInjected(bindingType, instance); } try { LifecycleMethods methods = lifecycleMethods.get(instance.getClass()); if (methods.hasLifecycleAnnotations()) { manager.add(instance, binding, methods); } } catch (ExecutionException e) { // caching problem throw new RuntimeException(e); } catch (Throwable e) { // unknown problem will abort injector start up throw new Error(e); } } } }
@Override public <T> void onProvision(ProvisionInvocation<T> provision) { final Key<?> key = provision.getBinding().getKey(); if (metrics == null) { LOG.debug("LifecycleProvisionListener not initialized yet : {} source={}", key, provision.getBinding().getSource()); return; } if (doneLoading) { return; } // Instantiate the type and pass to the metrics. This time captured will // include invoking any lifecycle events. metrics.push(key); try { provision.provision(); } finally { metrics.pop(); } }
@Override public <T> void onProvision(final ProvisionInvocation<T> provision) { final T serviceInstance; try { serviceInstance = provision.provision(); } catch (Throwable t) { // If we encounter any errors during provisioning, immediately stop the graph build throw serviceInitErrorHandler.createProvisionException(provision, t); } final IServiceGraphVertex<T> vertex = createGraphVertex(provision.getBinding().getKey(), serviceInstance); serviceGraph.addVertex(vertex); if (serviceScanMatcher.matches(provision.getBinding())) { provision.getBinding().acceptTargetVisitor(this); } }
@Override public <T> void onProvision(final ProvisionInvocation<T> provision) { final Class type = provision.getBinding().getKey().getTypeLiteral().getRawType(); if (contextDebugService == null) { created.add(type); } else { checkType(type); } }
@Override public <T> String format(ProvisionInvocation<T> provision) { return provision.getBinding().getKey().toString(); } };
@Override public <T> void onProvision(final ProvisionInvocation<T> provision) { final Class type = provision.getBinding().getKey().getTypeLiteral().getRawType(); if (contextDebugService == null) { created.add(type); } else { checkType(type); } }