/** * Get the {@code TransportsConfiguration} represented by a particular configuration file. * * @param configFileLocation configuration file location * @return TransportsConfiguration represented by a particular configuration file */ public TransportsConfiguration getConfiguration(String configFileLocation) { TransportsConfiguration transportsConfiguration; File file = new File(configFileLocation); if (file.exists()) { try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) { Yaml yaml = new Yaml(new CustomClassLoaderConstructor (TransportsConfiguration.class, TransportsConfiguration.class.getClassLoader())); yaml.setBeanAccess(BeanAccess.FIELD); transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class); } catch (IOException e) { throw new RuntimeException( "Error while loading " + configFileLocation + " configuration file", e); } } else { // return a default config LOG.warn("Netty transport configuration file not found in: {} ,hence using default configuration", configFileLocation); transportsConfiguration = new TransportsConfiguration(); } return transportsConfiguration; } }
/** * @deprecated * @return the default transport configuration. */ @Deprecated public static TransportsConfiguration getDefault() { TransportsConfiguration defaultConfig = new TransportsConfiguration(); ListenerConfiguration listenerConfiguration = ListenerConfiguration.getDefault(); HashSet<ListenerConfiguration> listenerConfigurations = new HashSet<>(); listenerConfigurations.add(listenerConfiguration); defaultConfig.setListenerConfigurations(listenerConfigurations); SenderConfiguration senderConfiguration = SenderConfiguration.getDefault(); HashSet<SenderConfiguration> senderConfigurations = new HashSet<>(); senderConfigurations.add(senderConfiguration); defaultConfig.setSenderConfigurations(senderConfigurations); HashSet<TransportProperty> transportProperties = new HashSet<>(); defaultConfig.setTransportProperties(transportProperties); return defaultConfig; }
private TransportsConfiguration buildDefaultTransportConfig() { TransportsConfiguration transportsConfiguration = new TransportsConfiguration(); SenderConfiguration httpSender = new SenderConfiguration("http-sender"); SenderConfiguration httpsSender = new SenderConfiguration("https-sender"); httpsSender.setScheme("https"); TransportProperty latencyMetrics = new TransportProperty(); latencyMetrics.setName("latency.metrics.enabled"); latencyMetrics.setValue(true); TransportProperty serverSocketTimeout = new TransportProperty(); serverSocketTimeout.setName("server.bootstrap.socket.timeout"); serverSocketTimeout.setValue(60); TransportProperty clientSocketTimeout = new TransportProperty(); clientSocketTimeout.setName("client.bootstrap.socket.timeout"); clientSocketTimeout.setValue(60); Set<SenderConfiguration> senderConfigurationSet = new HashSet<>(); senderConfigurationSet.add(httpSender); senderConfigurationSet.add(httpsSender); transportsConfiguration.setSenderConfigurations(senderConfigurationSet); Set<TransportProperty> transportPropertySet = new HashSet<>(); transportPropertySet.add(latencyMetrics); transportPropertySet.add(serverSocketTimeout); transportPropertySet.add(clientSocketTimeout); transportsConfiguration.setTransportProperties(transportPropertySet); return transportsConfiguration; }