@Override public void build(WebBuilderAmp webBuilder) { ServiceRef.ServiceBuilder builder = null; if (_supplier != null) { //builder = webBuilder.service(_supplier); } else if (_key != null) { builder = webBuilder.service(_key, _serviceClass); Objects.requireNonNull(builder); } else if (_serviceClass != null) { builder = webBuilder.service(_serviceClass); Objects.requireNonNull(builder); } else { throw new IllegalStateException(); } if (_address != null) { builder.address(_address); } else { builder.auto(); } //builder.ref(); }
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; }
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); }
@Override public void init(ServicesBuilder manager) { //ServicesAmp managerAmp = (ServicesAmp) manager; EventServiceRamp eventsScheme = new EventServiceRamp("event:"); ServiceRef eventsRef = manager.service(eventsScheme) .address("event:") .ref(); EventServerImpl eventsPod = eventsScheme.getEventServer(); ServiceRefAmp eventsPodRef = (ServiceRefAmp) eventsRef.pin(eventsPod); //eventsPodRef.bind("pod://" + EventsPodServerRamp.PATH); eventsPodRef.bind("local://" + EventServerImpl.PATH); eventsRef.start(); } }
@Override public void init(ServicesBuilder builder) { SchemePipeImpl pipeScheme = new SchemePipeImpl("pipe:"); builder.service(pipeScheme) .address("pipe:") .start(); InjectorBuilder injector = builder.injector(); injector.bean(PipeInMethodGenerator.class) .to(Key.of(MethodOnInitGenerator.class, PipeIn.class)); // builder.in //pipeRef.start(); //services. } }
/** * Creates a proxy to the underlying Service where proxy implements supplied * api, which can be interface for cleaner code or a service class. * <p> * * @param api Service interface or implementation * @param <T> type * @return proxy which implements api specified interface or extends * implementation if api is a class */ default <T> T as(Class<T> api) { return ref().as(api); } }
ProfileAsync(ProfileContext context, ServiceClient client, MethodRefAmp methodRef, Object []args, int count, int batchCount) { _context = context; _methodRef = methodRef; _args = args; _count = count; _batchCount = Math.max(1, batchCount); client.newService(this).as(HelloAsyncApi.class).start(); }
@Override public void init(ServicesBuilder manager) { SchemePubSubRamp scheme = new SchemePubSubRamp("pubsub:", manager.get()); ServiceRef pubsubRef = manager.service(scheme) .address("pubsub:") .ref(); // pubsubRef.bind("pubsub:"); //PubSubServiceRamp eventsPod = eventsScheme.getEventServer(); //ServiceRef eventsPodRef = eventsRef.pin(eventsPod); //eventsPodRef.bind("pod://" + EventsPodServerRamp.PATH); //eventsPodRef.bind("local://" + PubSubServiceRamp.PATH); } }
/** * Starts service if not already started, calls service method marked with @OnInit. * Terminal call after which configuration should be complete and service started. * * @return instance of ServiceRef for this service * @see OnInit */ default ServiceRef start() { return ref().start(); }
@Override public Object get() { if (_bean == null) { _bean = _serviceBuilder.as(_type); } return _bean; } }
@OnInit public void onActive() { FileChangeService listener = new FileChangeService(); Services manager = Services.current(); _fileTable.addListener(manager.newService(listener).as(TableListener.class)); // _dirTable.addListener(new DirChangeListener()); }