public TaskManager() { int workers = Runtime.getRuntime().availableProcessors(); if (workers <= 0) { workers = 1; } _workers = workers; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(TaskManager.class.getClassLoader()); _ampManager = ServicesAmp.newManager().start(); _taskService = _ampManager.newService(TaskService.class, TaskServiceImpl::new) .workers(workers) .as(TaskService.class); } finally { thread.setContextClassLoader(oldLoader); } }
private Map<ServiceTestDescriptor,ServiceRef> deployServices(Services manager) { Map<ServiceTestDescriptor,ServiceRef> descriptors = new HashMap<>(); for (ServiceTest service : getServices()) { Class serviceClass = service.value(); serviceClass = resove(serviceClass); ServiceTestDescriptor descriptor = ServiceTestDescriptor.of(serviceClass); ServiceRef ref = manager.newService(serviceClass).auto().ref(); descriptors.put(descriptor, ref); } for (Map.Entry<ServiceTestDescriptor,ServiceRef> e : descriptors.entrySet()) { ServiceTestDescriptor desc = e.getKey(); if (desc.isStart()) { e.getValue().start(); } } return descriptors; }
@OnInit public void onActive() { FileChangeService listener = new FileChangeService(); Services manager = Services.current(); _fileTable.addListener(manager.newService(listener).as(TableListener.class)); // _dirTable.addListener(new DirChangeListener()); }
@OnInit public void onInit() throws Exception { String address = ServiceRef.current().address() + _id; _logger.log(Level.CONFIG, "onInit: id=" + _id + ", service address=" + address); _jdbcConfig = JdbcConfig.from(_config, address); _logger.log(Level.CONFIG, "onInit: config=" + _jdbcConfig); Properties props = new Properties(); if (_jdbcConfig.user() != null) { props.setProperty("user", _jdbcConfig.user()); if (_jdbcConfig.pass() != null) { props.setProperty("password", _jdbcConfig.pass()); } } Supplier<JdbcConnection> supplier = new ConnectionSupplier(_jdbcConfig.url(), props, _jdbcConfig.testQueryBefore(), _jdbcConfig.testQueryAfter()); ServiceBuilder builder = Services.current().newService(JdbcConnection.class, supplier); ServiceRef ref = builder.workers(_jdbcConfig.poolSize()).start(); _conn = ref.as(JdbcConnection.class); }