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 <T> void introspectService(WebBuilder builder, Method method, Supplier<Object> beanFactory) { Service service = method.getAnnotation(Service.class); Api api = method.getAnnotation(Api.class); String address = service.value(); /* if (address.isEmpty()) { address = "/" + apiClass.getSimpleName(); } */ Class<T> type = (Class<T>) method.getReturnType(); Supplier<T> supplier = ()->(T) newInstance(beanFactory,method); ServiceBuilder serviceBuilder = builder.service(type, supplier); if (api != null) { serviceBuilder.api(api.value()); } if (! address.isEmpty()) { serviceBuilder.address(address); } Workers workers = method.getAnnotation(Workers.class); if (workers != null) { serviceBuilder.workers(workers.value()); } }
@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); }