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>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <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>(){}); final List<Binding<Emitter>> emitterBindings = injector.findBindingsByType(new TypeLiteral<Emitter>(){});
for (Binding<Emitter> binding : emitterBindings) { emitter = findEmitter(emitterType, emitterBindings);
if (Names.named(emitterType).equals(binding.getKey().getAnnotation())) {
emitter = binding.getProvider().get(); if (emitter == null) {
break; emitter = findEmitter(LogEmitterModule.EMITTER_TYPE, emitterBindings);
}
} }
if (emitter == null) { 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 @Override
public Emitter get() public Emitter get()

View File

@ -34,13 +34,15 @@ import com.metamx.emitter.core.LoggingEmitterConfig;
*/ */
public class LogEmitterModule implements Module public class LogEmitterModule implements Module
{ {
public static final String EMITTER_TYPE = "logging";
@Override @Override
public void configure(Binder binder) public void configure(Binder binder)
{ {
JsonConfigProvider.bind(binder, "druid.emitter.logging", LoggingEmitterConfig.class); JsonConfigProvider.bind(binder, "druid.emitter.logging", LoggingEmitterConfig.class);
} }
@Provides @LazySingleton @Named("logging") @Provides @LazySingleton @Named(EMITTER_TYPE)
public Emitter makeEmitter(LoggingEmitterConfig config, ObjectMapper jsonMapper) public Emitter makeEmitter(LoggingEmitterConfig config, ObjectMapper jsonMapper)
{ {
return new LoggingEmitter(config, 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.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.metamx.common.ISE;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -18,22 +17,16 @@ public class DbTablesConfig
@NotNull @NotNull
private final String base; private final String base;
@NotNull
private final String segmentsTable; private final String segmentsTable;
@NotNull
private final String rulesTable; private final String rulesTable;
@NotNull
private final String configTable; private final String configTable;
@NotNull
private final String tasksTable; private final String tasksTable;
@NotNull
private final String taskLogTable; private final String taskLogTable;
@NotNull
private final String taskLockTable; private final String taskLockTable;
@JsonCreator @JsonCreator
@ -60,7 +53,7 @@ public class DbTablesConfig
{ {
if (explicitTableName == null) { if (explicitTableName == null) {
if (base == 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); 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 Properties props;
private JsonConfigurator configurator; private JsonConfigurator configurator;
private Supplier<T> retVal = null;
public JsonConfigProvider( public JsonConfigProvider(
String propertyBase, String propertyBase,
Class<T> classToProvide Class<T> classToProvide
@ -74,7 +76,22 @@ public class JsonConfigProvider<T> implements Provider<Supplier<T>>
@Override @Override
public Supplier<T> get() public Supplier<T> get()
{ {
final T config = configurator.configurate(props, propertyBase, classToProvide); if (retVal != null) {
return Suppliers.ofInstance(config); 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 @Provides @LazySingleton
public Lifecycle getLifecycle(Injector injector) public Lifecycle getLifecycle(final Injector injector)
{ {
Lifecycle lifecycle = new Lifecycle(); Lifecycle lifecycle = new Lifecycle();
scope.setLifecycle(lifecycle); scope.setLifecycle(lifecycle);
for (Key<?> key : eagerClasses) { lifecycle.addHandler(
injector.getInstance(key); // Pull the key so as to "eagerly" load up the class. 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; return lifecycle;
} }

View File

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

View File

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

View File

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