public BrokerCfg getConfig() { return brokerContext.getBrokerConfiguration(); } }
@Override public void init(final SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); initClusterBaseLayer(context, serviceContainer); }
public Broker(final BrokerCfg cfg, final String basePath, final ActorClock clock) { this(new SystemContext(cfg, basePath, clock)); }
@Override public void close() { LogUtil.doWithMDC( brokerContext.getDiagnosticContext(), () -> { if (!isClosed) { brokerContext.close(); isClosed = true; LOG.info("Broker closed"); } }); }
protected void start() { LOG.info("Version: {}", VERSION); LOG.info("Starting broker with configuration {}", getConfig().toJson()); brokerContext.addComponent(new SystemComponent()); brokerContext.addComponent(new TransportComponent()); brokerContext.addComponent(new LogStreamsComponent()); brokerContext.addComponent(new SubscriptionComponent()); brokerContext.addComponent(new ClusterComponent()); brokerContext.addComponent(new GatewayComponent()); brokerContext.addComponent(new ExporterComponent()); brokerContext.init(); }
@Override public void init(final SystemContext context) { final EmbeddedGatewayCfg config = context.getBrokerConfiguration().getGateway(); if (config.isEnable()) { try { final Gateway gateway = new Gateway(config); gateway.start(); context.setGatewayResourceReleasingDelegate(gateway::stop); } catch (final IOException e) { throw new RuntimeException("Gateway was not able to start", e); } } } }
@Override public void init(SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); final List<ExporterCfg> exporters = context.getBrokerConfiguration().getExporters(); if (!exporters.isEmpty()) { final ExporterManagerService exporterManagerService = new ExporterManagerService(exporters); serviceContainer .createService(EXPORTER_MANAGER, exporterManagerService) .dependency( STREAM_PROCESSOR_SERVICE_FACTORY, exporterManagerService.getStreamProcessorServiceFactoryInjector()) .groupReference( LEADER_PARTITION_GROUP_NAME, exporterManagerService.getPartitionsGroupReference()) .install(); } } }
private void createClientTransports(final SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); final BrokerCfg brokerCfg = context.getBrokerConfiguration(); final NetworkCfg networkCfg = brokerCfg.getNetwork(); final int nodeId = brokerCfg.getCluster().getNodeId(); final SocketAddress managementEndpoint = networkCfg.getManagement().toSocketAddress(); final SocketAddress subscriptionEndpoint = networkCfg.getSubscription().toSocketAddress(); final ActorFuture<ClientTransport> managementClientFuture = createClientTransport( serviceContainer, MANAGEMENT_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), Collections.singletonList(new IntTuple<>(nodeId, managementEndpoint))); context.addRequiredStartAction(managementClientFuture); final ActorFuture<ClientTransport> replicationClientFuture = createClientTransport( serviceContainer, REPLICATION_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), null); context.addRequiredStartAction(replicationClientFuture); final ActorFuture<ClientTransport> subscriptionClientFuture = createClientTransport( serviceContainer, SUBSCRIPTION_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), Collections.singletonList(new IntTuple<>(nodeId, subscriptionEndpoint))); context.addRequiredStartAction(subscriptionClientFuture); }
@Before public void setup() { context = spy( new SystemContext( brokerConfig, temporaryFolder.getRoot().getAbsolutePath(), new DefaultActorClock())); doAnswer(i -> serviceContainerRule.get()).when(context).getServiceContainer(); }
private void initClusterBaseLayer( final SystemContext context, final ServiceContainer serviceContainer) { final BrokerCfg brokerConfig = context.getBrokerConfiguration(); final NetworkCfg networkCfg = brokerConfig.getNetwork(); final CompositeServiceBuilder baseLayerInstall = initPartitions(baseLayerInstall, context); context.addRequiredStartAction(baseLayerInstall.install());
protected ActorFuture<BufferingServerTransport> createBufferingServerTransport( final SystemContext systemContext, final ServiceContainer serviceContainer, final String name, final InetSocketAddress bindAddress, final ByteValue sendBufferSize, final ByteValue receiveBufferSize) { final ServiceName<Dispatcher> receiveBufferName = createReceiveBuffer(serviceContainer, name, receiveBufferSize); final BufferingServerTransportService service = new BufferingServerTransportService(name, bindAddress, sendBufferSize); systemContext.addResourceReleasingDelegate(service.getReleasingResourcesDelegate()); return serviceContainer .createService(TransportServiceNames.bufferingServerTransport(name), service) .dependency(receiveBufferName, service.getReceiveBufferInjector()) .install(); }
public Broker(final SystemContext systemContext) { this.brokerContext = systemContext; LogUtil.doWithMDC(systemContext.getDiagnosticContext(), () -> start()); }
public void init() { serviceContainer.start(); for (final Component brokerComponent : components) { try { brokerComponent.init(this); } catch (final RuntimeException e) { close(); throw e; } } try { for (final ActorFuture<?> requiredStartAction : requiredStartActions) { requiredStartAction.get(20, TimeUnit.SECONDS); } } catch (final Exception e) { LOG.error("Could not start broker", e); close(); throw new RuntimeException(e); } }
serviceContainer.close(getCloseTimeout().toMillis(), TimeUnit.MILLISECONDS); } catch (final TimeoutException e) { LOG.error("Failed to close broker within {} seconds.", CLOSE_TIMEOUT, e); scheduler.stop().get(getCloseTimeout().toMillis(), TimeUnit.MILLISECONDS); } catch (final TimeoutException e) { LOG.error("Failed to close scheduler within {} seconds", CLOSE_TIMEOUT, e);
@Override public void init(SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); final List<ExporterCfg> exporters = context.getBrokerConfiguration().getExporters(); if (!exporters.isEmpty()) { final ExporterManagerService exporterManagerService = new ExporterManagerService(exporters); serviceContainer .createService(EXPORTER_MANAGER, exporterManagerService) .dependency( STREAM_PROCESSOR_SERVICE_FACTORY, exporterManagerService.getStreamProcessorServiceFactoryInjector()) .groupReference( LEADER_PARTITION_GROUP_NAME, exporterManagerService.getPartitionsGroupReference()) .install(); } } }
private void createClientTransports(final SystemContext context) { final ServiceContainer serviceContainer = context.getServiceContainer(); final BrokerCfg brokerCfg = context.getBrokerConfiguration(); final NetworkCfg networkCfg = brokerCfg.getNetwork(); final int nodeId = brokerCfg.getCluster().getNodeId(); final SocketAddress managementEndpoint = networkCfg.getManagement().toSocketAddress(); final SocketAddress subscriptionEndpoint = networkCfg.getSubscription().toSocketAddress(); final ActorFuture<ClientTransport> managementClientFuture = createClientTransport( serviceContainer, MANAGEMENT_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), Collections.singletonList(new IntTuple<>(nodeId, managementEndpoint))); context.addRequiredStartAction(managementClientFuture); final ActorFuture<ClientTransport> replicationClientFuture = createClientTransport( serviceContainer, REPLICATION_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), null); context.addRequiredStartAction(replicationClientFuture); final ActorFuture<ClientTransport> subscriptionClientFuture = createClientTransport( serviceContainer, SUBSCRIPTION_API_CLIENT_NAME, new ByteValue(networkCfg.getDefaultSendBufferSize()), Collections.singletonList(new IntTuple<>(nodeId, subscriptionEndpoint))); context.addRequiredStartAction(subscriptionClientFuture); }
@Before public void setup() { context = spy( new SystemContext( brokerConfig, temporaryFolder.getRoot().getAbsolutePath(), new DefaultActorClock())); doAnswer(i -> serviceContainerRule.get()).when(context).getServiceContainer(); }
@Override public void init(final SystemContext context) { final EmbeddedGatewayCfg config = context.getBrokerConfiguration().getGateway(); if (config.isEnable()) { try { final Gateway gateway = new Gateway(config); gateway.start(); context.setGatewayResourceReleasingDelegate(gateway::stop); } catch (final IOException e) { throw new RuntimeException("Gateway was not able to start", e); } } } }
private void initClusterBaseLayer( final SystemContext context, final ServiceContainer serviceContainer) { final BrokerCfg brokerConfig = context.getBrokerConfiguration(); final NetworkCfg networkCfg = brokerConfig.getNetwork(); final CompositeServiceBuilder baseLayerInstall = initPartitions(baseLayerInstall, context); context.addRequiredStartAction(baseLayerInstall.install());
@Override public void close() { LogUtil.doWithMDC( brokerContext.getDiagnosticContext(), () -> { if (!isClosed) { brokerContext.close(); isClosed = true; LOG.info("Broker closed"); } }); }