@Override public void run() { try { if (broker != null) { broker.close(); } } finally { deleteTempDirectory(); } } });
public Broker(final SystemContext systemContext) { this.brokerContext = systemContext; LogUtil.doWithMDC(systemContext.getDiagnosticContext(), () -> start()); }
public static void main(final String[] args) throws Exception { final Broker broker; if (args.length == 1) { broker = startBrokerFromConfiguration(args); } else { broker = startDefaultBrokerInTempDirectory(); } getRuntime() .addShutdownHook( new Thread("Broker close Thread") { @Override public void run() { try { if (broker != null) { broker.close(); } } finally { deleteTempDirectory(); } } }); WAITING_LATCH.await(); }
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(); }
public <T> void removeService(final ServiceName<T> name) { try { broker.getBrokerContext().getServiceContainer().removeService(name).get(10, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not remove service " + name.getName() + " in 10 seconds."); } }
public static void printRecords(final Broker broker, final int partitionId) { try { final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); final ServiceName<LogStream> logStreamServiceName = LogStreamServiceNames.logStreamServiceName(Partition.getPartitionName(partitionId)); final PrinterService printerService = new PrinterService(); serviceContainer .createService(PRINTER_SERVICE_NAME, printerService) .dependency(logStreamServiceName, printerService.getLogStreamInjector()) .install() .join(); serviceContainer.removeService(PRINTER_SERVICE_NAME).join(); } catch (final Exception e) { LOGGER.error( "Could not print log entries. This exception is not propagated to avoid interference with the test.", e); } }
private static Broker startDefaultBrokerInTempDirectory() { Loggers.SYSTEM_LOGGER.info("No configuration file specified. Using default configuration."); try { tempFolder = Files.createTempDirectory("zeebe").toAbsolutePath().normalize().toString(); final BrokerCfg cfg = new BrokerCfg(); return new Broker(cfg, tempFolder, null); } catch (final IOException e) { throw new RuntimeException("Could not start broker", e); } }
public <S> S getService(final ServiceName<S> serviceName) { final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); final Injector<S> injector = new Injector<>(); final ServiceName<TestService> accessorServiceName = ServiceName.newServiceName("serviceAccess" + serviceName.getName(), TestService.class); try { serviceContainer .createService(accessorServiceName, new TestService()) .dependency(serviceName, injector) .install() .get(); } catch (final InterruptedException | ExecutionException e) { throw new RuntimeException(e); } serviceContainer.removeService(accessorServiceName); return injector.getValue(); }
private static Broker startBrokerFromConfiguration(final String[] args) { String basePath = System.getProperty("basedir"); if (basePath == null) { basePath = Paths.get(".").toAbsolutePath().normalize().toString(); } return new Broker(args[0], basePath, null); }
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(); }
public <T> void removeService(final ServiceName<T> name) { try { broker.getBrokerContext().getServiceContainer().removeService(name).get(10, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not remove service " + name.getName() + " in 10 seconds."); } }
public void stopBroker() { if (broker != null) { broker.close(); broker = null; System.gc(); } }
public Broker(final SystemContext systemContext) { this.brokerContext = systemContext; LogUtil.doWithMDC(systemContext.getDiagnosticContext(), () -> start()); }
public <T> void installService( Function<ServiceContainer, ServiceBuilder<T>> serviceBuilderFactory) { final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); final ServiceBuilder<T> serviceBuilder = serviceBuilderFactory.apply(serviceContainer); try { serviceBuilder.install().get(10, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not install service: " + serviceBuilder.getName(), e); } }
public void stopBroker() { if (broker != null) { broker.close(); broker = null; System.gc(); } }
public <T> void installService( Function<ServiceContainer, ServiceBuilder<T>> serviceBuilderFactory) { final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); final ServiceBuilder<T> serviceBuilder = serviceBuilderFactory.apply(serviceContainer); try { serviceBuilder.install().get(10, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not install service: " + serviceBuilder.getName(), e); } }
public void stopBroker() { if (broker != null) { broker.close(); broker = null; System.gc(); } }
public <T> void removeService(final ServiceName<T> name) { try { broker.getBrokerContext().getServiceContainer().removeService(name).get(10, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not remove service " + name.getName() + " in 10 seconds."); } }
public void stopBroker() { if (broker != null) { broker.close(); broker = null; System.gc(); } }
public <T> void removeService(final ServiceName<T> name) { try { broker.getBrokerContext().getServiceContainer().removeService(name).get(10, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException("Could not remove service " + name.getName() + " in 10 seconds."); } }