1) A bunch more changes to make things actually run. Not quite done, but close!

This commit is contained in:
cheddar 2013-06-20 17:19:51 -07:00
parent 11ea15fc1a
commit 149c2e3560
9 changed files with 61 additions and 26 deletions

View File

@ -164,7 +164,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -98,11 +98,10 @@ public class EmitterModule implements Module
{
final List<Binding<Emitter>> emitterBindings = injector.findBindingsByType(new TypeLiteral<Emitter>(){});
for (Binding<Emitter> binding : emitterBindings) {
if (Names.named(emitterType).equals(binding.getKey().getAnnotation())) {
emitter = binding.getProvider().get();
break;
}
emitter = findEmitter(emitterType, emitterBindings);
if (emitter == null) {
emitter = findEmitter(LogEmitterModule.EMITTER_TYPE, emitterBindings);
}
if (emitter == null) {
@ -117,6 +116,16 @@ public class EmitterModule implements Module
}
}
private Emitter findEmitter(String emitterType, List<Binding<Emitter>> emitterBindings)
{
for (Binding<Emitter> binding : emitterBindings) {
if (Names.named(emitterType).equals(binding.getKey().getAnnotation())) {
return binding.getProvider().get();
}
}
return null;
}
@Override
public Emitter get()

View File

@ -34,13 +34,15 @@ import com.metamx.emitter.core.LoggingEmitterConfig;
*/
public class LogEmitterModule implements Module
{
public static final String EMITTER_TYPE = "logging";
@Override
public void configure(Binder binder)
{
JsonConfigProvider.bind(binder, "druid.emitter.logging", LoggingEmitterConfig.class);
}
@Provides @LazySingleton @Named("logging")
@Provides @LazySingleton @Named(EMITTER_TYPE)
public Emitter makeEmitter(LoggingEmitterConfig config, ObjectMapper jsonMapper)
{
return new LoggingEmitter(config, jsonMapper);

View File

@ -2,7 +2,6 @@ package com.metamx.druid.db;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.metamx.common.ISE;
import javax.validation.constraints.NotNull;
@ -18,22 +17,16 @@ public class DbTablesConfig
@NotNull
private final String base;
@NotNull
private final String segmentsTable;
@NotNull
private final String rulesTable;
@NotNull
private final String configTable;
@NotNull
private final String tasksTable;
@NotNull
private final String taskLogTable;
@NotNull
private final String taskLockTable;
@JsonCreator
@ -60,7 +53,7 @@ public class DbTablesConfig
{
if (explicitTableName == null) {
if (base == null) {
throw new ISE("table[%s] unknown! Both base and %s were null!", defaultSuffix, defaultSuffix);
return null;
}
return String.format("%s_%s", base, defaultSuffix);
}

View File

@ -52,6 +52,8 @@ public class JsonConfigProvider<T> implements Provider<Supplier<T>>
private Properties props;
private JsonConfigurator configurator;
private Supplier<T> retVal = null;
public JsonConfigProvider(
String propertyBase,
Class<T> classToProvide
@ -74,7 +76,22 @@ public class JsonConfigProvider<T> implements Provider<Supplier<T>>
@Override
public Supplier<T> get()
{
final T config = configurator.configurate(props, propertyBase, classToProvide);
return Suppliers.ofInstance(config);
if (retVal != null) {
return retVal;
}
try {
final T config = configurator.configurate(props, propertyBase, classToProvide);
retVal = Suppliers.ofInstance(config);
}
catch (RuntimeException e) {
// When a runtime exception gets thrown out, this provider will get called again if the object is asked for again.
// This will have the same failed result, 'cause when it's called no parameters will have actually changed. For
// Guice will then report the same error multiple times, which is pretty annoying. Cache a null supplier and
// return that instead. This is technically enforcing a singleton, but such is life.
retVal = Suppliers.ofInstance(null);
throw e;
}
return retVal;
}
}

View File

@ -60,14 +60,29 @@ public class LifecycleModule implements Module
}
@Provides @LazySingleton
public Lifecycle getLifecycle(Injector injector)
public Lifecycle getLifecycle(final Injector injector)
{
Lifecycle lifecycle = new Lifecycle();
scope.setLifecycle(lifecycle);
for (Key<?> key : eagerClasses) {
injector.getInstance(key); // Pull the key so as to "eagerly" load up the class.
}
lifecycle.addHandler(
new Lifecycle.Handler()
{
@Override
public void start() throws Exception
{
for (Key<?> key : eagerClasses) {
injector.getInstance(key); // Pull the key so as to "eagerly" load up the class.
}
}
@Override
public void stop()
{
}
}
);
return lifecycle;
}

View File

@ -302,8 +302,8 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -163,7 +163,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -76,9 +76,8 @@ public class MasterMain
final ServiceAnnouncer serviceAnnouncer = injector.getInstance(ServiceAnnouncer.class);
try {
lifecycle.start();
Initialization.announceDefaultService(nodeConfig, serviceAnnouncer, lifecycle);
lifecycle.start();
}
catch (Throwable t) {
log.error(t, "Error when starting up. Failing.");