Java Code Examples for com.google.inject.spi.Message

The following examples show how to use com.google.inject.spi.Message. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 Project: presto   Source File: PrometheusConnectorConfig.java    License: 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
@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
@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 Project: android-arscblamer   Source File: InjectedApplication.java    License: 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 Project: opt4j   Source File: Opt4JModule.java    License: 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
protected V message(Object source, String text) {
    return visit(new Message(source, text));
}
 
Example 8
@Override
public Void visit(Message message) {
    out.println(message.getMessage() + " (at " + message.getSource() + ")");
    return null;
}
 
Example 9
@Override
public Void visit(Message message) {
    logger.log(level, message.getMessage() + " (at " + message.getSource() + ")");
    return null;
}