public StatReplicator buildAndStart() { buildQueue(); final StatReplicator proxyWithAutoFlush = serviceQueue.createProxyWithAutoFlush(StatReplicator.class, 100, TimeUnit.MILLISECONDS); return proxyWithAutoFlush; }
public ServiceWorkers startServiceWorkers() { serviceQueues = Collections.unmodifiableList(serviceQueues); if (startServices) { serviceQueues.forEach(io.advantageous.qbit.service.ServiceQueue::start); serviceQueues.forEach(io.advantageous.qbit.service.ServiceQueue::startCallBackHandler); } for (ServiceQueue serviceQueue : serviceQueues) { if (flushInterval > 0) { SendQueue<MethodCall<Object>> methodCallSendQueue = serviceQueue.requestsWithAutoFlush(flushInterval, timeUnit); methodCallSendQueue.start(); sendQueues.add(methodCallSendQueue); } else { sendQueues.add(serviceQueue.requests()); } } return this; }
public HealthServiceAsync buildHealthSystemReporter() { return getServiceQueue().createProxy(HealthServiceAsync.class); } }
default ServiceQueue startAll() { startServiceQueue(); startCallBackHandler(); return this; }
@Override public void joinService(final ServiceQueue serviceQueue) { if (services.contains(serviceQueue)) { logger.info("EventManager{}::joinService: Service queue " + "is already a member of this event manager {}", name, serviceQueue.name()); return; } services.add(serviceQueue); logger.info("EventManager{}::joinService:: {} joined {}", name, serviceQueue.name(), name); doListen(serviceQueue.service(), serviceQueue); }
public HealthServiceAsync getProxy() { if (proxy == null) { if (autoFlush) { proxy = getServiceQueue().createProxyWithAutoFlush(HealthServiceAsync.class, 50, TimeUnit.MILLISECONDS); } else { proxy = getServiceQueue().createProxy(HealthServiceAsync.class); } } return proxy; }
@Test public void testUsingProxyWithAutoFlush() { /* Create a service that lives behind a ServiceQueue. */ ServiceQueue serviceQueue = serviceBuilder() .setServiceAddress("/todo-service") .setServiceObject(new TodoService()) .build(); TodoServiceClient todoServiceClient = serviceQueue.createProxyWithAutoFlush(TodoServiceClient.class, 25, TimeUnit.MILLISECONDS); serviceQueue.start(); serviceQueue.startServiceQueue().startCallBackHandler(); todoServiceClient.add(new TodoItem("foo", "foo", null)); AtomicReference<List<TodoItem>> items = new AtomicReference<>(); todoServiceClient.list(todoItems -> items.set(todoItems)); Sys.sleep(2000); ok = items.get() != null || die(); ok = items.get().size() > 0 || die(); ok = items.get().get(0).getDescription().equals("foo") || die(); }
public HealthServiceAsync buildAndStart() { HealthServiceAsync proxy = getProxy(); getServiceQueue().start(); getServiceQueue().startCallBackHandler(); return proxy; }
@Test //Works public void testWithServiceQueue() { final ServiceQueue serviceQueue = ServiceBuilder.serviceBuilder() .setServiceObject(new FeedServiceImpl()).buildAndStartAll(); final FeedService feedService = serviceQueue.createProxyWithAutoFlush(FeedService.class, Duration.ofMillis(100)); final List<FeedMeta> feedMetas = feedService.listFeeds() .blockingGet(Duration.ofSeconds(30)); assertNotNull(feedMetas); assertEquals(1, feedMetas.size()); assertEquals("Hello", feedMetas.get(0).name); serviceQueue.stop(); }
@Override public EventManager systemEventManager() { final EventManager eventManager = eventManagerThreadLocal.get(); if (eventManager != null) { return eventManager; } EventManager proxy; if (systemEventManager.get() == null) { final ServiceQueue serviceQueue = serviceBuilder().setInvokeDynamic(false) .setServiceObject( EventManagerBuilder.eventManagerBuilder().setName("QBIT_SYSTEM").build()).build().startServiceQueue(); systemEventManager.set(serviceQueue); proxy = serviceQueue.createProxyWithAutoFlush(EventManager.class, 100, TimeUnit.MILLISECONDS); } else { proxy = systemEventManager.get().createProxyWithAutoFlush(EventManager.class, 100, TimeUnit.MILLISECONDS); } eventManagerThreadLocal.set(proxy); return proxy; }
final MyServiceInterface serverSenderClient = serviceSenderQueue.createProxyWithAutoFlush( MyServiceInterface.class, 100, TimeUnit.MILLISECONDS); serviceSenderQueue.start(); receiverServiceQueue.start(); receiverServiceQueue2.start(); receiverServiceQueue3.start(); serviceSenderQueue.stop(); receiverServiceQueue.stop(); receiverServiceQueue2.stop(); receiverServiceQueue3.stop();
.setServiceObject(new TodoService()).build().startServiceQueue(); SendQueue<MethodCall<Object>> requests = serviceQueue.requests(); ReceiveQueue<Response<Object>> responses = serviceQueue.responses();
@Before public void setup() { systemManager = new QBitSystemManager(); eventManager = EventManagerBuilder .eventManagerBuilder().setName("Event Bus") .build(); serviceBuilder = ServiceBuilder.serviceBuilder() .setSystemManager(systemManager); eventServiceQueue = serviceBuilder.setServiceObject(eventManager).build().startServiceQueue(); serviceBuilder = ServiceBuilder.serviceBuilder() .setSystemManager(systemManager).setEventManager(eventManager); serviceB = new ServiceB(); serviceBuilder.setServiceObject(serviceB).buildAndStartAll(); serviceBuilder = ServiceBuilder.serviceBuilder() .setSystemManager(systemManager).setEventManager(eventManager); serviceA = new ServiceA(eventServiceQueue.createProxyWithAutoFlush(EventManager.class, Duration.SECOND), QBit.factory().eventBusProxyCreator()); final ServiceQueue serviceAQueue = serviceBuilder .setServiceObject(serviceA).buildAndStartAll(); serviceAQueueProxy = serviceAQueue.createProxy(ServiceAInterface.class); }
@Test public void testMany() { Adder adder = new Adder(); ServiceQueue serviceQueue = Services.jsonService("test", adder); ReceiveQueue<Response<Object>> responses = serviceQueue.responses(); SendQueue<MethodCall<Object>> requests = serviceQueue.requests(); //noinspection unchecked requests.sendMany(MethodCallBuilder.method("add", "[1,2]"), MethodCallBuilder.method("add", "[4,5]")); Response<Object> response = responses.take(); Object o = fromJson(response.body().toString()); ok = o.equals(Integer.valueOf(3)) || die(response); response = responses.take(); ok = response != null || die(response); o = fromJson(response.body().toString()); ok = o.equals(Integer.valueOf(9)) || die(response); synchronized (adder) { ok = adder.all == 12 || die(adder.all); } }
public void addServiceService(final String objectName, final String serviceAddress, final ServiceQueue serviceQueue) { /** add to our list of servicesToStop. */ servicesToStop.add(serviceQueue); servicesToFlush.add(serviceQueue); QueueDispatch dispatch = new QueueDispatch(serviceQueue); /** Add the client given the address if we have an address. */ if (serviceAddress != null && !serviceAddress.isEmpty()) { serviceMapping.put(serviceAddress, dispatch); } if (objectName != null) { /** Put the client incoming requests in our client name, request queue mapping. */ serviceMapping.put(objectName, dispatch); } serviceMapping.put(serviceQueue.name().toLowerCase(), dispatch); serviceMapping.put(serviceQueue.name(), dispatch); serviceMapping.put(serviceQueue.address(), dispatch); serviceMapping.put(serviceQueue.address().toLowerCase(), dispatch); /** Add the request queue to our set of request queues. */ sendQueues.add(dispatch.requests); /** Generate a list of end point addresses based on the client bundle root address. */ final Collection<String> addresses = serviceQueue.addresses(this.rootAddress); if (debug) { logger.debug(ServiceBundleImpl.class.getName() + " addresses: " + addresses); } /** Add mappings to all addresses for this client to our serviceMapping. */ for (String addr : addresses) { serviceMapping.put(addr, dispatch); } }
@Override public void shutdownSystemEventBus() { final ServiceQueue serviceQueue = systemEventManager.get(); if (serviceQueue != null) { serviceQueue.stop(); } }
@Before public void setup() { serviceQueue = new ServiceBuilder().setServiceObject( new MockService()).setInvokeDynamic(false).build().startServiceQueue(); proxy = serviceQueue.createProxy(MockServiceInterface.class); ok = true; }
QueueDispatch(ServiceQueue serviceQueue) { this.serviceQueue = serviceQueue; /* Create an forwardEvent queue for this client. which we access from a single thread. */ requests = serviceQueue.requests(); }
public ServiceQueue buildAsServiceAndStartAll() { final ServiceQueue serviceQueue = buildAsService(); serviceQueue.startAll(); return serviceQueue; } }