public static void main(String[] args) throws Throwable { ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); host.startFactory(TaskDemoService.class, TaskDemoService::createFactory); host.startFactory(ExampleService.class, ExampleService::createFactory); }
public static void main(String[] args) throws Throwable { ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); // A stateless service that enumerates all the // factory services started on the Service host. host.startService(new RootNamespaceService()); // start an example factory for folks that want to experiment with service instances host.startFactory(ExampleService.class, ExampleService::createFactory); }
public static void main(String[] args) throws Throwable { ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new MyStatelessService()); host.startService(new MyNamespaceService()); }
@Override public ServiceHost start() throws Throwable { super.start();
public static void main(String[] args) throws Throwable { host.start(); host.startDefaultCoreServicesSynchronously();
@Override public ServiceHost start() throws Throwable { super.start(); startDefaultCoreServicesSynchronously(); // Start a factory for gathering test statistics super.startService( Operation.createPost(UriUtils.buildUri(this, TestResultsFactoryService.class)), new TestResultsFactoryService()); return this; } }
public static boolean restartStatefulHost(ServiceHost host, boolean failOnIndexDeletion) throws Throwable { long exp = Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros()); do { Thread.sleep(2000); try { if (host.isAuthorizationEnabled()) { host.setAuthenticationService(new AuthorizationContextService()); } host.start(); return true; } catch (Throwable e) { Logger.getAnonymousLogger().warning(String .format("exception on host restart: %s", e.getMessage())); try { host.stop(); } catch (Throwable e1) { return false; } if (e instanceof LockObtainFailedException && !failOnIndexDeletion) { Logger.getAnonymousLogger() .warning("Lock held exception on host restart, retrying"); continue; } return false; } } while (Utils.getSystemNowMicrosUtc() < exp); return false; }
static ServiceHost createAndStartHost(String... args) throws Throwable { ServiceHost host = ServiceHost.create(args); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new UpgradeDemoEmployeeService()); // In order to support upgrading your Xenon application, you need to start the MigrationTaskService host.startFactory(new MigrationTaskService()); return host; }
public static void main(String[] args) throws Throwable { ServiceHost host = ServiceHost.create("--sandbox=/tmp/xenon-query/" + UUID.randomUUID().toString()); host.start(); host.startDefaultCoreServicesSynchronously(); host.startFactory(ExampleService.class, ExampleService::createFactory); host.registerForServiceAvailability((o, e) -> handleFactoryAvailability(host, e), ExampleService.FACTORY_LINK); }
@Override public ServiceHost start() throws Throwable { super.start(); startDefaultCoreServicesSynchronously(); // Start a factory for gathering test statistics super.startService( Operation.createPost(UriUtils.buildUri(this, TestResultsFactoryService.class)), new TestResultsFactoryService()); return this; } }
public static boolean restartStatefulHost(ServiceHost host, boolean failOnIndexDeletion) throws Throwable { long exp = Utils.fromNowMicrosUtc(host.getOperationTimeoutMicros()); do { Thread.sleep(2000); try { if (host.isAuthorizationEnabled()) { host.setAuthenticationService(new AuthorizationContextService()); } host.start(); return true; } catch (Throwable e) { Logger.getAnonymousLogger().warning(String .format("exception on host restart: %s", e.getMessage())); try { host.stop(); } catch (Throwable e1) { return false; } if (e instanceof LockObtainFailedException && !failOnIndexDeletion) { Logger.getAnonymousLogger() .warning("Lock held exception on host restart, retrying"); continue; } return false; } } while (Utils.getSystemNowMicrosUtc() < exp); return false; }
public static void main(String[] args) throws Throwable { // create adhoc ServiceHost. // In real application, you should create own ServiceHost implementation. ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new BookService()); host.startService(new Top10BookRankingService()); // Subscription // Let's create a subscription that will be called when BookService is created. // Create a consumer of subscription callbacks // >> IMPLEMENT HERE << // start subscription when factory became available // For reliable subscription, use "startReliableSubscriptionService()" instead of "startSubscriptionService()" host.registerForServiceAvailability((o, e) -> { // Register subscription to the factory of BookService // >> IMPLEMENT HERE << }, BookService.FACTORY_LINK); }
@Test public void create() throws Throwable { ServiceHost h = ServiceHost.create("--port=0"); try { h.start(); h.startDefaultCoreServicesSynchronously(); // Start the example service factory h.startFactory(ExampleService.class, ExampleService::createFactory); boolean[] isReady = new boolean[1]; h.registerForServiceAvailability((o, e) -> { isReady[0] = true; }, ExampleService.FACTORY_LINK); Duration timeout = Duration.of(ServiceHost.ServiceHostState.DEFAULT_MAINTENANCE_INTERVAL_MICROS * 5, ChronoUnit.MICROS); TestContext.waitFor(timeout, () -> { return isReady[0]; }, "ExampleService did not start"); // verify ExampleService exists TestRequestSender sender = new TestRequestSender(h); Operation get = Operation.createGet(h, ExampleService.FACTORY_LINK); sender.sendAndWait(get); } finally { if (h != null) { h.unregisterRuntimeShutdownHook(); h.stop(); } } }
static ServiceHost createAndStartHost(String... args) throws Throwable { ServiceHost host = ServiceHost.create(args); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new UpgradeDemoEmployeeService()); // In order to support upgrading your Xenon application, you need to start the MigrationTaskService host.startFactory(new MigrationTaskService()); host.startService(new UpgradeDemoEmployeeServiceTransformService()); host.log(Level.INFO, "Starting host [add-logging] with args these args:%n[id=%s]%n[port=%d]%n[sandbox=%s]%n[peerNodes=%s]", host.getId(), host.getPort(), host.getStorageSandbox(), host.getInitialPeerHosts()); return host; }
@Test public void create() throws Throwable { ServiceHost h = ServiceHost.create("--port=0"); try { h.start(); h.startDefaultCoreServicesSynchronously(); // Start the example service factory h.startFactory(ExampleService.class, ExampleService::createFactory); boolean[] isReady = new boolean[1]; h.registerForServiceAvailability((o, e) -> { isReady[0] = true; }, ExampleService.FACTORY_LINK); Duration timeout = Duration.of(ServiceHost.ServiceHostState.DEFAULT_MAINTENANCE_INTERVAL_MICROS * 5, ChronoUnit.MICROS); TestContext.waitFor(timeout, () -> { return isReady[0]; }, "ExampleService did not start"); // verify ExampleService exists TestRequestSender sender = new TestRequestSender(h); Operation get = Operation.createGet(h, ExampleService.FACTORY_LINK); sender.sendAndWait(get); } finally { if (h != null) { h.unregisterRuntimeShutdownHook(); h.stop(); } } }
static ServiceHost createAndStartHost(String... args) throws Throwable { ServiceHost host = ServiceHost.create(args); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new UpgradeDemoEmployeeService()); // In order to support upgrading your Xenon application, you need to start the MigrationTaskService host.startFactory(new MigrationTaskService()); // Added for 'add-logging' project. host.log(Level.INFO, "Starting host [add-logging] with args these args:%n[id=%s]%n[port=%d]%n[sandbox=%s]%n[peerNodes=%s]", host.getId(), host.getPort(), host.getStorageSandbox(), host.getInitialPeerHosts()); return host; }
public static void main(String[] args) throws Throwable { ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); // Start the root namespace factory: this will respond to the root URI (/) and list all // the factory services. host.startService(new RootNamespaceService()); host.startFactory(MySubscriptionService.class, MySubscriptionService::createFactory); // subscription callback Consumer<Operation> target = (notifyOp) -> { System.out.println("notification: " + notifyOp); notifyOp.complete(); }; Operation createSub = Operation.createPost( UriUtils.buildUri(host, MySubscriptionService.FACTORY_LINK)) .setReferer(host.getUri()); // start subscription when factory became available // For reliable subscription, use "startReliableSubscriptionService()" instead of "startSubscriptionService()" host.registerForServiceAvailability((o, e) -> { host.startSubscriptionService(createSub, target); }, MySubscriptionService.FACTORY_LINK); }
public static void main(String[] args) throws Throwable { // create adhoc ServiceHost. // In real application, you should create own ServiceHost implementation. ServiceHost host = ServiceHost.create(); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new BookService()); host.startService(new Top10BookRankingService()); // Create a consumer of subscription callbacks // subscription callback Consumer<Operation> target = (notifyOp) -> { host.log(Level.INFO, "notification: %s", notifyOp); if (notifyOp.getAction() == Service.Action.POST) { BookService.BookState state = notifyOp.getBody(BookService.BookState.class); host.log(Level.INFO, "title=%s, sold=%d", state.title, state.sold); } notifyOp.complete(); }; // start subscription when factory became available // For reliable subscription, use "startReliableSubscriptionService()" instead of "startSubscriptionService()" host.registerForServiceAvailability((o, e) -> { // Register subscription to the factory of BookService Operation createSub = Operation.createPost( UriUtils.buildUri(host, BookService.FACTORY_LINK)).setReferer(host.getUri()); host.startSubscriptionService(createSub, target); }, BookService.FACTORY_LINK); }