com.google.inject.spi.Message Java Examples

The following examples show how to use com.google.inject.spi.Message. 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: HiveMQExceptionHandlerBootstrap.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private static void checkGuiceErrorsForUnrecoverable(final Collection<Message> errorMessages) {
    if (errorMessages == null) {
        return;
    }

    //when more than one Exception is caught by Guice the ProvisionException or CreationException contains as cause null,
    //but all the caught Exceptions are in the messages field of the ProvisionException/CreationException so we have
    //to check them as well

    for (final Message message : errorMessages) {
        if (message.getCause() instanceof UnrecoverableException) {
            log.error("An unrecoverable Exception occurred. Exiting HiveMQ");
            System.exit(1);
        }
    }
}
 
Example #2
Source File: PrometheusConnectorConfig.java    From presto with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void checkConfig()
{
    long maxQueryRangeDuration = (long) getMaxQueryRangeDuration().getValue(TimeUnit.SECONDS);
    long queryChunkSizeDuration = (long) getQueryChunkSizeDuration().getValue(TimeUnit.SECONDS);
    if (maxQueryRangeDuration < queryChunkSizeDuration) {
        throw new ConfigurationException(ImmutableList.of(new Message("prometheus.max.query.range.duration must be greater than prometheus.query.chunk.size.duration")));
    }
}
 
Example #3
Source File: HiveMQExceptionHandlerBootstrapTest.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Test
public void test_creationException() {
    exit.expectSystemExitWithStatus(1);
    final CreationException creationException = new CreationException(Collections.singletonList(new Message("test",
            new UnrecoverableException(false))));

    HiveMQExceptionHandlerBootstrap.handleUncaughtException(Thread.currentThread(), creationException);
}
 
Example #4
Source File: HiveMQExceptionHandlerBootstrapTest.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Test
public void test_provisionException() {
    exit.expectSystemExitWithStatus(1);
    final ProvisionException provisionException = new ProvisionException(Collections.singletonList(new Message(
            "test",
            new UnrecoverableException(false))));

    HiveMQExceptionHandlerBootstrap.handleUncaughtException(Thread.currentThread(), provisionException);
}
 
Example #5
Source File: InjectedApplication.java    From android-arscblamer with Apache License 2.0 5 votes vote down vote up
/**
 * Gets an instance from Guice for the provided class. Any missing flags or bindings will be
 * printed in the error message if there was a problem retrieving the class instance.
 *
 * @param cls The class type to retrieve from the Guice injector.
 * @param <T> The type of the class that is being returned.
 * @return The class instance retrieved from Guice.
 */
public <T> T get(Class<T> cls) {
  try {
    return injector.getInstance(cls);
  } catch (ProvisionException e) {
    System.err.println("Could not start application:");
    for (Message msg : e.getErrorMessages()) {
      System.err.println("  " + msg.toString());
    }
    System.exit(1);
  }

  throw new IllegalStateException("Did not get an instance, and did not get an exception?");
}
 
Example #6
Source File: Opt4JModule.java    From opt4j with MIT License 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {

	/**
	 * Configure injected constants.
	 */
	PropertyModule module = new PropertyModule(this);
	for (Property property : module.getProperties()) {
		for (Annotation annotation : property.getAnnotations()) {
			if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null) {
				Class<?> type = property.getType();
				Object value = property.getValue();

				ConstantBindingBuilder builder = bindConstant(annotation);
				if (type.equals(Integer.TYPE)) {
					builder.to((Integer) value);
				} else if (type.equals(Long.TYPE)) {
					builder.to((Long) value);
				} else if (type.equals(Double.TYPE)) {
					builder.to((Double) value);
				} else if (type.equals(Float.TYPE)) {
					builder.to((Float) value);
				} else if (type.equals(Byte.TYPE)) {
					builder.to((Byte) value);
				} else if (type.equals(Short.TYPE)) {
					builder.to((Short) value);
				} else if (type.equals(Boolean.TYPE)) {
					builder.to((Boolean) value);
				} else if (type.equals(Character.TYPE)) {
					builder.to((Character) value);
				} else if (type.equals(String.class)) {
					builder.to((String) value);
				} else if (type.equals(Class.class)) {
					builder.to((Class<?>) value);
				} else if (value instanceof Enum<?>) {
					builder.to((Enum) value);
				} else {
					String message = "Constant type not bindable: " + type + " of field " + property.getName() + " in module "
							+ this.getClass().getName();
					throw new ConfigurationException(Arrays.asList(new Message(message)));
				}
			}
		}
	}

	multi(OptimizerStateListener.class);
	multi(OptimizerIterationListener.class);
	multi(IndividualStateListener.class);

	config();
}
 
Example #7
Source File: ElementInspector.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
protected V message(Object source, String text) {
    return visit(new Message(source, text));
}
 
Example #8
Source File: ElementPrinter.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Void visit(Message message) {
    out.println(message.getMessage() + " (at " + message.getSource() + ")");
    return null;
}
 
Example #9
Source File: ElementLogger.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Void visit(Message message) {
    logger.log(level, message.getMessage() + " (at " + message.getSource() + ")");
    return null;
}