nodes no longer inherit from interfaces but instead extend classes

This commit is contained in:
Fangjin Yang 2012-11-13 13:18:31 -08:00
parent 24564d73e1
commit 0ef40171a8
6 changed files with 45 additions and 52 deletions

View File

@ -30,7 +30,6 @@ import com.metamx.common.lifecycle.LifecycleStart;
import com.metamx.common.lifecycle.LifecycleStop; import com.metamx.common.lifecycle.LifecycleStop;
import com.metamx.common.logger.Logger; import com.metamx.common.logger.Logger;
import com.metamx.druid.http.RequestLogger; 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.Initialization;
import com.metamx.druid.initialization.ServerConfig; import com.metamx.druid.initialization.ServerConfig;
import com.metamx.druid.initialization.ZkClientConfig; import com.metamx.druid.initialization.ZkClientConfig;
@ -62,7 +61,7 @@ import java.util.concurrent.ScheduledExecutorService;
/** /**
*/ */
public abstract class QueryableNode<T extends QueryableNode> implements RegisteringNode public abstract class QueryableNode<T extends QueryableNode> extends RegisteringNode
{ {
private final Logger log; private final Logger log;
@ -91,6 +90,8 @@ public abstract class QueryableNode<T extends QueryableNode> implements Register
ConfigurationObjectFactory configFactory ConfigurationObjectFactory configFactory
) )
{ {
super(jsonMapper, smileMapper);
this.log = log; this.log = log;
this.configFactory = configFactory; this.configFactory = configFactory;
this.props = props; this.props = props;
@ -156,7 +157,6 @@ public abstract class QueryableNode<T extends QueryableNode> implements Register
return (T) this; return (T) this;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T registerJacksonSubtype(Class<?>... clazzes) public T registerJacksonSubtype(Class<?>... clazzes)
{ {
@ -173,16 +173,6 @@ public abstract class QueryableNode<T extends QueryableNode> implements Register
return (T) this; return (T) this;
} }
@Override
public void registerHandlers(Registererer... registererers)
{
for (Registererer registererer : registererers) {
registererer.register();
registererer.registerSubType(jsonMapper);
registererer.registerSubType(smileMapper);
}
}
public Lifecycle getLifecycle() public Lifecycle getLifecycle()
{ {
return lifecycle; return lifecycle;

View File

@ -20,10 +20,39 @@
package com.metamx.druid; package com.metamx.druid;
import com.metamx.druid.index.v1.serde.Registererer; 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<Registererer> registererers, Iterable<ObjectMapper> 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;
}
} }

View File

@ -33,6 +33,7 @@ import com.metamx.common.ISE;
import com.metamx.common.MapUtils; import com.metamx.common.MapUtils;
import com.metamx.common.guava.FunctionalIterable; import com.metamx.common.guava.FunctionalIterable;
import com.metamx.common.logger.Logger; import com.metamx.common.logger.Logger;
import com.metamx.druid.RegisteringNode;
import com.metamx.druid.index.v1.serde.Registererer; import com.metamx.druid.index.v1.serde.Registererer;
import com.metamx.druid.indexer.data.DataSpec; import com.metamx.druid.indexer.data.DataSpec;
import com.metamx.druid.indexer.granularity.GranularitySpec; import com.metamx.druid.indexer.granularity.GranularitySpec;
@ -58,6 +59,7 @@ import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -104,10 +106,8 @@ public class HadoopDruidIndexerConfig
} }
} }
); );
for (Registererer registererer : registererers) {
registererer.register(); RegisteringNode.registerHandlers(registererers, Arrays.asList(jsonMapper));
registererer.registerSubType(jsonMapper);
}
} }
final HadoopDruidIndexerConfig retVal = jsonMapper.convertValue(argSpec, HadoopDruidIndexerConfig.class); final HadoopDruidIndexerConfig retVal = jsonMapper.convertValue(argSpec, HadoopDruidIndexerConfig.class);

View File

@ -4,8 +4,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.metamx.common.lifecycle.LifecycleStart; import com.metamx.common.lifecycle.LifecycleStart;
import com.metamx.common.lifecycle.LifecycleStop; 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.codehaus.jackson.map.jsontype.NamedType;
import org.joda.time.Interval; 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() public static Builder builder()
{ {
@ -61,15 +59,6 @@ public class HadoopDruidIndexerNode implements RegisteringNode
return this; return this;
} }
@Override
public void registerHandlers(Registererer... registererers)
{
for (Registererer registererer : registererers) {
registererer.register();
registererer.registerSubType(HadoopDruidIndexerConfig.jsonMapper);
}
}
@LifecycleStart @LifecycleStart
public void start() throws Exception public void start() throws Exception
{ {

View File

@ -43,7 +43,6 @@ import com.metamx.druid.http.GuiceServletConfig;
import com.metamx.druid.http.RedirectFilter; import com.metamx.druid.http.RedirectFilter;
import com.metamx.druid.http.RedirectInfo; import com.metamx.druid.http.RedirectInfo;
import com.metamx.druid.http.StatusServlet; 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.Initialization;
import com.metamx.druid.initialization.ServerConfig; import com.metamx.druid.initialization.ServerConfig;
import com.metamx.druid.initialization.ServiceDiscoveryConfig; 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); private static final Logger log = new Logger(IndexerCoordinatorNode.class);
@ -146,6 +145,8 @@ public class IndexerCoordinatorNode implements RegisteringNode
ConfigurationObjectFactory configFactory ConfigurationObjectFactory configFactory
) )
{ {
super(jsonMapper);
this.jsonMapper = jsonMapper; this.jsonMapper = jsonMapper;
this.lifecycle = lifecycle; this.lifecycle = lifecycle;
this.props = props; this.props = props;
@ -185,15 +186,6 @@ public class IndexerCoordinatorNode implements RegisteringNode
this.taskRunnerFactory = taskRunnerFactory; this.taskRunnerFactory = taskRunnerFactory;
} }
@Override
public void registerHandlers(Registererer... registererers)
{
for (Registererer registererer : registererers) {
registererer.register();
registererer.registerSubType(jsonMapper);
}
}
public void init() throws Exception public void init() throws Exception
{ {
scheduledExecutorFactory = ScheduledExecutors.createFactory(lifecycle); scheduledExecutorFactory = ScheduledExecutors.createFactory(lifecycle);

View File

@ -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); private static final Logger log = new Logger(WorkerNode.class);
@ -113,6 +113,8 @@ public class WorkerNode implements RegisteringNode
ConfigurationObjectFactory configFactory ConfigurationObjectFactory configFactory
) )
{ {
super(jsonMapper);
this.jsonMapper = jsonMapper; this.jsonMapper = jsonMapper;
this.lifecycle = lifecycle; this.lifecycle = lifecycle;
this.props = props; this.props = props;
@ -149,15 +151,6 @@ public class WorkerNode implements RegisteringNode
return this; return this;
} }
@Override
public void registerHandlers(Registererer... registererers)
{
for (Registererer registererer : registererers) {
registererer.register();
registererer.registerSubType(jsonMapper);
}
}
public void init() throws Exception public void init() throws Exception
{ {
initializeEmitter(); initializeEmitter();