use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.
the class SimpleFileLoggingConsumer method mainFunction.
public void mainFunction(String[] args) throws Exception {
String[] leftOverArgs = processLocalArgs(args);
Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
if (_enableBootStrap) {
clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
}
ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
String[] sources = addSources();
StringBuilder sourcesString = new StringBuilder();
boolean firstSrc = true;
for (String source : sources) {
if (!firstSrc)
sourcesString.append(",");
firstSrc = false;
sourcesString.append(source);
}
if (_httpPort != null) {
startupProps.put("databus.client.container.httpPort", _httpPort);
}
if (_jmxServicePort != null) {
startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
}
if (_checkpointFileRootDir != null) {
startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
}
DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
// set up relay
ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
relayBuilder.setName("DefaultRelay");
if (_relayHost != null) {
relayBuilder.setHost(_relayHost);
}
if (_relayPort != null) {
relayBuilder.setPort(Integer.parseInt(_relayPort));
}
relayBuilder.setSources(sourcesString.toString());
// set up bootstrap
if (_enableBootStrap) {
ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
bootstrapBuilder.setName("DefaultBootstrapServices");
if (_bootstrapHost != null) {
bootstrapBuilder.setHost(_bootstrapHost);
}
if (_bootstrapPort != null) {
bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
}
bootstrapBuilder.setSources(sourcesString.toString());
}
// handler server side filtering, can either pass a config file or set from command line
DbusKeyCompositeFilterConfig filterConfig = createServerSideFilterConfig(_filterConfFile, startupProps);
// set up listeners
DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
// dump decoded payload values and raw (undecoded) events
DatabusFileLoggingConsumer consumer = createTypedConsumer(_valueDumpFile, _eventDumpFile);
if (_eventPattern != null) {
consumer.setEventPattern(_eventPattern);
}
DatabusRegistration reg = client.register(consumer, sources);
if (!(reg instanceof DatabusV2RegistrationImpl)) {
throw new RuntimeException("Unexpected type for registration Object !!");
}
if (null != filterConfig)
reg.withServerSideFilter(filterConfig);
// add pause processor
try {
client.getProcessorRegistry().register(ConsumerPauseRequestProcessor.COMMAND_NAME, new ConsumerPauseRequestProcessor(null, consumer));
client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
} catch (ProcessorRegistrationConflictException e) {
LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
}
DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
Runtime.getRuntime().addShutdownHook(shutdownThread);
//this should automatically start the registration
client.startAndBlock();
}
use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.
the class RelayEventProducer method createServerInfo.
static Set<ServerInfo> createServerInfo(String serverName, String subscriptions) throws InvalidConfigException {
Set<ServerInfo> serverInfo = new HashSet<ServerInfo>();
ServerInfoBuilder sBuilder = new ServerInfoBuilder();
sBuilder.setAddress(serverName + ":" + subscriptions);
// sBuilder.setSources(subscriptions);
serverInfo.add(sBuilder.build());
return serverInfo;
}
use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.
the class DatabusHttpClientImpl method parseServerInfosMap.
private static List<ServerInfo> parseServerInfosMap(Map<String, ServerInfoBuilder> map) throws InvalidConfigException {
ArrayList<ServerInfo> infos = new ArrayList<ServerInfo>((int) (map.size() * 1.3));
for (Map.Entry<String, ServerInfoBuilder> entry : map.entrySet()) {
LOG.info("parseServerInfo: " + entry.toString());
ServerInfoBuilder builder = entry.getValue();
boolean added = infos.add(builder.build());
LOG.info("added=" + added);
}
LOG.info("info size=" + infos.size());
return infos;
}
use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.
the class TestServerInfo method testBuilderSetAddressWithName.
@Test
public void testBuilderSetAddressWithName() throws Exception {
ServerInfoBuilder builder = new ServerInfoBuilder();
String address = ServerInfoBuilder.generateAddress("SeRvEr", "localhost", 99, "com.linkedin.events.source1", "com.linkedin.events.source3");
builder.setAddress(address);
ServerInfo si = builder.build();
assertEquals("SeRvEr", si.getName());
assertEquals(99, si.getAddress().getPort());
assertEquals(2, si.getSources().size());
assertEquals("com.linkedin.events.source1", si.getSources().get(0));
assertEquals("com.linkedin.events.source3", si.getSources().get(1));
}
use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.
the class TestServerInfo method testServerInfoSetBuilder.
@Test
public void testServerInfoSetBuilder() throws Exception {
ServerInfoBuilder sib = new ServerInfoBuilder();
String address1 = ServerInfoBuilder.generateAddress("SeRvEr1", "localhost", 98, "com.linkedin.events.source1", "com.linkedin.events.source3");
sib.setAddress(address1);
ServerInfo si1 = sib.build();
String address2 = ServerInfoBuilder.generateAddress("SeRvEr2", "localhost", 99, "com.linkedin.events.source1", "com.linkedin.events.source3");
sib.setAddress(address2);
ServerInfo si2 = sib.build();
String address3 = ServerInfoBuilder.generateAddress(null, "localhost", 100, "com.linkedin.events.source1", "com.linkedin.events.source2", "com.linkedin.events.source3");
sib.setAddress(address3);
ServerInfo si3 = sib.build();
ServerInfoSetBuilder builder = new ServerInfoSetBuilder();
builder.setServers(address1 + ServerInfoSetBuilder.SERVER_INFO_SEPARATOR + address2 + ServerInfoSetBuilder.SERVER_INFO_SEPARATOR + address3);
List<ServerInfo> res = builder.build();
assertEquals(3, res.size());
assertEquals(true, res.contains(si1));
assertEquals(true, res.contains(si2));
assertEquals(true, res.contains(si3));
}
Aggregations