diff --git a/client/src/main/java/com/metamx/druid/QueryableNode.java b/client/src/main/java/com/metamx/druid/QueryableNode.java index 31d15ee4cfd..0cc348fc2fc 100644 --- a/client/src/main/java/com/metamx/druid/QueryableNode.java +++ b/client/src/main/java/com/metamx/druid/QueryableNode.java @@ -30,7 +30,6 @@ import com.metamx.common.lifecycle.LifecycleStart; import com.metamx.common.lifecycle.LifecycleStop; import com.metamx.common.logger.Logger; import com.metamx.druid.http.RequestLogger; -import com.metamx.druid.index.v1.serde.Registererer; import com.metamx.druid.initialization.Initialization; import com.metamx.druid.initialization.ServerConfig; import com.metamx.druid.initialization.ZkClientConfig; @@ -62,7 +61,7 @@ import java.util.concurrent.ScheduledExecutorService; /** */ -public abstract class QueryableNode implements RegisteringNode +public abstract class QueryableNode extends RegisteringNode { private final Logger log; @@ -91,6 +90,8 @@ public abstract class QueryableNode implements Register ConfigurationObjectFactory configFactory ) { + super(jsonMapper, smileMapper); + this.log = log; this.configFactory = configFactory; this.props = props; @@ -156,7 +157,6 @@ public abstract class QueryableNode implements Register return (T) this; } - @SuppressWarnings("unchecked") public T registerJacksonSubtype(Class... clazzes) { @@ -173,16 +173,6 @@ public abstract class QueryableNode implements Register return (T) this; } - @Override - public void registerHandlers(Registererer... registererers) - { - for (Registererer registererer : registererers) { - registererer.register(); - registererer.registerSubType(jsonMapper); - registererer.registerSubType(smileMapper); - } - } - public Lifecycle getLifecycle() { return lifecycle; diff --git a/client/src/main/java/com/metamx/druid/RegisteringNode.java b/client/src/main/java/com/metamx/druid/RegisteringNode.java index 60e7292870d..0ac5940c812 100644 --- a/client/src/main/java/com/metamx/druid/RegisteringNode.java +++ b/client/src/main/java/com/metamx/druid/RegisteringNode.java @@ -20,10 +20,39 @@ package com.metamx.druid; import com.metamx.druid.index.v1.serde.Registererer; +import org.codehaus.jackson.map.ObjectMapper; + +import java.util.Arrays; /** */ -public interface RegisteringNode +public class RegisteringNode { - public void registerHandlers(Registererer... registererers); + public static void registerHandlers(Iterable registererers, Iterable mappers) + { + for (Registererer registererer : registererers) { + if (!doneRegister) { + registererer.register(); + } + for (ObjectMapper mapper : mappers) { + registererer.registerSubType(mapper); + } + } + doneRegister = true; + } + + private static boolean doneRegister = false; + + private final ObjectMapper[] mappers; + + public RegisteringNode(ObjectMapper... mappers) + { + this.mappers = mappers; + } + + public RegisteringNode registerHandlers(Registererer... registererers) + { + registerHandlers(Arrays.asList(registererers), Arrays.asList(mappers)); + return this; + } } diff --git a/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerConfig.java b/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerConfig.java index c246600e8a8..51244685f77 100644 --- a/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerConfig.java +++ b/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerConfig.java @@ -33,6 +33,7 @@ import com.metamx.common.ISE; import com.metamx.common.MapUtils; import com.metamx.common.guava.FunctionalIterable; import com.metamx.common.logger.Logger; +import com.metamx.druid.RegisteringNode; import com.metamx.druid.index.v1.serde.Registererer; import com.metamx.druid.indexer.data.DataSpec; import com.metamx.druid.indexer.granularity.GranularitySpec; @@ -58,6 +59,7 @@ import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -104,10 +106,8 @@ public class HadoopDruidIndexerConfig } } ); - for (Registererer registererer : registererers) { - registererer.register(); - registererer.registerSubType(jsonMapper); - } + + RegisteringNode.registerHandlers(registererers, Arrays.asList(jsonMapper)); } final HadoopDruidIndexerConfig retVal = jsonMapper.convertValue(argSpec, HadoopDruidIndexerConfig.class); diff --git a/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerNode.java b/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerNode.java index 9236adcf454..5d7c281aef9 100644 --- a/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerNode.java +++ b/indexer/src/main/java/com/metamx/druid/indexer/HadoopDruidIndexerNode.java @@ -4,8 +4,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.metamx.common.lifecycle.LifecycleStart; import com.metamx.common.lifecycle.LifecycleStop; -import com.metamx.druid.RegisteringNode; -import com.metamx.druid.index.v1.serde.Registererer; import org.codehaus.jackson.map.jsontype.NamedType; import org.joda.time.Interval; @@ -15,7 +13,7 @@ import java.util.List; /** */ -public class HadoopDruidIndexerNode implements RegisteringNode +public class HadoopDruidIndexerNode { public static Builder builder() { @@ -61,15 +59,6 @@ public class HadoopDruidIndexerNode implements RegisteringNode return this; } - @Override - public void registerHandlers(Registererer... registererers) - { - for (Registererer registererer : registererers) { - registererer.register(); - registererer.registerSubType(HadoopDruidIndexerConfig.jsonMapper); - } - } - @LifecycleStart public void start() throws Exception { diff --git a/merger/src/main/java/com/metamx/druid/merger/coordinator/http/IndexerCoordinatorNode.java b/merger/src/main/java/com/metamx/druid/merger/coordinator/http/IndexerCoordinatorNode.java index a4c33bf5090..85ca8d2a13b 100644 --- a/merger/src/main/java/com/metamx/druid/merger/coordinator/http/IndexerCoordinatorNode.java +++ b/merger/src/main/java/com/metamx/druid/merger/coordinator/http/IndexerCoordinatorNode.java @@ -43,7 +43,6 @@ import com.metamx.druid.http.GuiceServletConfig; import com.metamx.druid.http.RedirectFilter; import com.metamx.druid.http.RedirectInfo; import com.metamx.druid.http.StatusServlet; -import com.metamx.druid.index.v1.serde.Registererer; import com.metamx.druid.initialization.Initialization; import com.metamx.druid.initialization.ServerConfig; import com.metamx.druid.initialization.ServiceDiscoveryConfig; @@ -109,7 +108,7 @@ import java.util.concurrent.ScheduledExecutorService; /** */ -public class IndexerCoordinatorNode implements RegisteringNode +public class IndexerCoordinatorNode extends RegisteringNode { private static final Logger log = new Logger(IndexerCoordinatorNode.class); @@ -146,6 +145,8 @@ public class IndexerCoordinatorNode implements RegisteringNode ConfigurationObjectFactory configFactory ) { + super(jsonMapper); + this.jsonMapper = jsonMapper; this.lifecycle = lifecycle; this.props = props; @@ -185,15 +186,6 @@ public class IndexerCoordinatorNode implements RegisteringNode this.taskRunnerFactory = taskRunnerFactory; } - @Override - public void registerHandlers(Registererer... registererers) - { - for (Registererer registererer : registererers) { - registererer.register(); - registererer.registerSubType(jsonMapper); - } - } - public void init() throws Exception { scheduledExecutorFactory = ScheduledExecutors.createFactory(lifecycle); diff --git a/merger/src/main/java/com/metamx/druid/merger/worker/http/WorkerNode.java b/merger/src/main/java/com/metamx/druid/merger/worker/http/WorkerNode.java index a32fcbbd676..e69b1e9724c 100644 --- a/merger/src/main/java/com/metamx/druid/merger/worker/http/WorkerNode.java +++ b/merger/src/main/java/com/metamx/druid/merger/worker/http/WorkerNode.java @@ -80,7 +80,7 @@ import java.util.concurrent.ScheduledExecutorService; /** */ -public class WorkerNode implements RegisteringNode +public class WorkerNode extends RegisteringNode { private static final Logger log = new Logger(WorkerNode.class); @@ -113,6 +113,8 @@ public class WorkerNode implements RegisteringNode ConfigurationObjectFactory configFactory ) { + super(jsonMapper); + this.jsonMapper = jsonMapper; this.lifecycle = lifecycle; this.props = props; @@ -149,15 +151,6 @@ public class WorkerNode implements RegisteringNode return this; } - @Override - public void registerHandlers(Registererer... registererers) - { - for (Registererer registererer : registererers) { - registererer.register(); - registererer.registerSubType(jsonMapper); - } - } - public void init() throws Exception { initializeEmitter();