ServiceHost implements ServiceRequestSender { public void startFactoryServicesSynchronously(Service... services) throws Throwable { List<Operation> posts = new ArrayList<>(); for (Service s : services) { if (!(s instanceof FactoryService)) { String message = String .format("Service %s is not a FactoryService", s.getClass().getSimpleName()); throw new IllegalArgumentException(message); } URI u = null; if (ReflectionUtils.hasField(s.getClass(), UriUtils.FIELD_NAME_SELF_LINK)) { u = UriUtils.buildUri(this, s.getClass()); } else { Class<? extends Service> childClass = ((FactoryService) s).createServiceInstance() .getClass(); if (ReflectionUtils.hasField(childClass, UriUtils.FIELD_NAME_FACTORY_LINK)) { u = UriUtils.buildFactoryUri(this, childClass); } if (u == null) { String message = String .format("%s field not found in class %s and %s field not found in class %s", UriUtils.FIELD_NAME_SELF_LINK, s.getClass().getSimpleName(), UriUtils.FIELD_NAME_FACTORY_LINK, childClass.getSimpleName()); throw new IllegalArgumentException(message); } } Operation startPost = Operation.createPost(u); posts.add(startPost); } startCoreServicesSynchronously(posts, Arrays.asList(services)); } protected  ServiceHost(); static ServiceHost create(String... args); ServiceHost initialize(String[] args); ServiceHost initialize(Arguments args); String getLocation(); void setLocation(String location); @Override String toString(); boolean isStarted(); boolean isStopping(); boolean isServiceStateCaching(); boolean isTracingEnabled(); ServiceHost setServiceStateCaching(boolean enable); int getPort(); ServiceHost setPort(int port); boolean isAuthorizationEnabled(); void setAuthorizationEnabled(boolean isAuthorizationEnabled); boolean isPeerSynchronizationEnabled(); void setPeerSynchronizationEnabled(boolean enabled); boolean isRequestLoggingEnabled(); RequestLoggingInfo getRequestLoggingInfo(); List<String> getSkipLoggingPragmaDirectives(); void setRequestLoggingInfo(RequestLoggingInfo loggingInfo); int getPeerSynchronizationTimeLimitSeconds(); void setPeerSynchronizationTimeLimitSeconds(int seconds); boolean isAutoBackupEnabled(); void setAutoBackupEnabled(boolean enabled); int getSecurePort(); ServiceHost setSecurePort(int port); ServiceHost setPrivateKeyFileReference(URI fileReference); ServiceHost setPrivateKeyPassphrase(String privateKeyPassphrase); ServiceHost setCertificateFileReference(URI fileReference); ServiceHost setBindAddress(String address); ServiceHost setPublicUri(URI publicUri); URI getStorageSandbox(); long getMaintenanceIntervalMicros(); long getMaintenanceCheckIntervalMicros(); ServiceHost setMaintenanceIntervalMicros(long micros); String getId(); String nextUUID(); long getOperationTimeoutMicros(); ServiceHostState getState(); URI getDocumentIndexServiceUri(); URI getAuthorizationServiceUri(); URI getTransactionServiceUri(); URI getManagementServiceUri(); ServiceHost setDocumentIndexingService(Service service); ServiceHost setAuthorizationService(Service service); ServiceHost setTransactionService(Service service); ServiceHost setManagementService(Service service); ServiceHost setAuthenticationService(Service service); URI getAuthenticationServiceUri(); ScheduledExecutorService getScheduledExecutor(); ExecutorService getExecutor(); ExecutorService allocateExecutor(Service s); ExecutorService allocateExecutor(Service s, int threadCount); @SuppressWarnings("try") ServiceHost start(); void startDefaultCoreServicesSynchronously(); void startDefaultCoreServicesSynchronously(boolean joinPeerNodes); void createOrStartShardsManagerWhenDefaultNodeGroupIsAvailable(); void createOrStartShardsManagerSynchronously(int replicationFactor); List<URI> getInitialPeerHosts(); Path copyResourceToSandbox(URL url, Path resourcePath); Path discoverJarResources(Path path, Service s, Map<Path, String> pathToURIPath,
            Path baseUriPath, String prefix); Path discoverFileResources(Service s, Map<Path, String> pathToURIPath,
            Path baseUriPath,
            String prefix); void joinPeers(List<URI> peers, String nodeGroupUriPath); void startFactoryServicesSynchronously(Service... services); URI startSubscriptionService(
            Operation subscribe,
            Consumer<Operation> notificationConsumer); URI startReliableSubscriptionService(
            Operation subscribe,
            Consumer<Operation> notificationConsumer); URI startSubscriptionService(
            Operation subscribe,
            Consumer<Operation> notificationConsumer,
            ServiceSubscriber request); URI startSubscriptionService(
            Operation subscribe,
            Service notificationTarget,
            ServiceSubscriber request); void stopSubscriptionService(
            Operation unsubscribe,
            URI notificationTarget); static boolean isServiceStartingOrAvailable(ProcessingStage stage); static boolean isServiceStarting(ProcessingStage stage); ServiceHost startService(Service service); ServiceHost startService(Operation post, Service service); ServiceHost startFactory(Service instanceService); ServiceHost startFactory(Class<? extends Service> instServiceClass,
            Supplier<FactoryService> factoryCreator); ServiceHost startFactory(Supplier<FactoryService> factoryCreator, String servicePath); ServiceHost startIdempotentFactory(Service instanceService); static boolean isServiceIndexed(Service s); static boolean isServiceImmutable(Service s); void scheduleNodeGroupChangeMaintenance(String nodeSelectorPath); void setFactoriesAvailabilityIfOwner(boolean isAvailable); boolean isAuthorized(Service service, ServiceDocument document, Operation op); void stopService(Service service); boolean handleRequest(Operation inboundOp); @SuppressWarnings("try") boolean handleRequest(Service service, Operation inboundOp); @Override void sendRequest(Operation op); void stop(); static boolean isServiceCreate(Operation op); static boolean isServiceStop(Operation op); static boolean isServiceDeleteAndStop(Operation op); static boolean isServiceAvailable(Service s); static boolean isForServiceNamespace(Service s, Operation op); static boolean isHelperServicePath(String serviceUriPath); ServiceHost toggleDebuggingMode(boolean enable); ServiceHost setLoggingLevel(Level newLevel); ServiceHost toggleOperationProcessingLogging(boolean loggingEnabled); ServiceHost setOperationProcessingLogFilter(Predicate<Operation> logFilter); ServiceHost setOperationTracingLevel(Level newLevel); Level getOperationTracingLevel(); void log(Level level, String fmt, Object... args); void log(Level level, Supplier<String> messageSupplier); void registerForServiceAvailability(CompletionHandler completion,
            String... servicePaths); void registerForServiceAvailability(CompletionHandler completion, boolean checkReplica,
            String... servicePaths); void registerForServiceAvailability(CompletionHandler completion,
            String nodeSelectorPath, boolean checkReplica, String... servicePaths); void registerForServiceAvailability(Operation opTemplate, String... servicePaths); ServiceHost setRequestRateLimit(String key, double operationsPerSecond); ServiceHost setRequestRateLimit(String key, RequestRateInfo ri); RequestRateInfo getRequestRateLimit(String key); ServiceHost setServiceMemoryLimit(String servicePath, double percentOfTotal); Long getServiceMemoryLimitMB(String servicePath, MemoryLimitType limitType); ProcessingStage getServiceStage(String servicePath); boolean checkServiceAvailable(String servicePath); void checkReplicatedServiceAvailable(CompletionHandler ch, String servicePath); void checkReplicatedServiceAvailable(CompletionHandler ch, String servicePath,
            String nodeSelectorPath); SystemHostInfo getSystemInfo(); SystemHostInfo updateSystemInfo(boolean enumerateNetworkInterfaces); void updateMemoryAndDiskInfo(); void run(Runnable task); void run(ExecutorService executor, Runnable task); ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit); ScheduledFuture<?> scheduleCore(Runnable task, long delay, TimeUnit unit); ServiceHost setOperationTimeOutMicros(long timeoutMicros); ServiceHost setServiceCacheClearDelayMicros(long delayMicros); long getServiceCacheClearDelayMicros(); ServiceHost setProcessOwner(boolean isOwner); boolean isProcessOwner(); void setListener(ServiceRequestListener listener); ServiceRequestListener getSecureListener(); void setSecureListener(ServiceRequestListener listener); ServiceRequestListener getListener(); ServiceClient getClient(); void setClient(ServiceClient client); void broadcastRequest(String selectorPath, boolean excludeThisHost, Operation request); void broadcastRequest(String selectorPath, String key, boolean excludeThisHost,
            Operation request); void selectOwner(String selectorPath, String key, Operation op); SelectOwnerResponse findOwnerNode(String selectorPath, String path); void forwardRequest(String groupPath, Operation request); void forwardRequest(String selectorPath, String key, Operation request); void replicateRequest(EnumSet<ServiceOption> serviceOptions, ServiceDocument state,
            String selectorPath,
            String selectionKey,
            Operation op); void queryServiceUris(String servicePath, Operation get); void queryServiceUris(EnumSet<ServiceOption> options, boolean matchAllOptions,
            Operation get); void queryServiceUris(EnumSet<ServiceOption> options, boolean matchAllOptions,
            Operation get, EnumSet<ServiceOption> exclusionOptions); ServiceDocumentDescription buildDocumentDescription(String servicePath); URI getPublicUri(); String getPublicUriAsString(); URI getUri(); URI getSecureUri(); String getPreferredAddress(); void setRequestPayloadSizeLimit(int limit); void setResponsePayloadSizeLimit(int limit); void cacheAuthorizationContext(Service s, AuthorizationContext ctx); void cacheAuthorizationContext(Service s, String token, AuthorizationContext ctx); void clearAuthorizationContext(Service s, String userLink); AuthorizationContext getAuthorizationContext(Service s, String token); void populateAuthorizationContext(String authToken, String referrerPath, Consumer<AuthorizationContext> callback); Thread getRuntimeShutdownHook(); void registerRuntimeShutdownHook(); boolean unregisterRuntimeShutdownHook(); void failRequestServiceAlreadyStarted(String path, Service s, Operation post); Tracer getTracer(); static final String SERVICE_HOST_STATE_FILE; static final Double DEFAULT_PCT_MEMORY_LIMIT; static final Double DEFAULT_PCT_MEMORY_LIMIT_DOCUMENT_INDEX; static final Double DEFAULT_PCT_MEMORY_LIMIT_SERVICE_CONTEXT_INDEX; static final String LOOPBACK_ADDRESS; static final String LOCAL_HOST; static final String DEFAULT_BIND_ADDRESS; static final int PORT_VALUE_HTTP_DEFAULT; static final int PORT_VALUE_LISTENER_DISABLED; static final int DEFAULT_PORT; static final String ALL_INTERFACES; static final String ROOT_PATH; static final String SERVICE_URI_SUFFIX_STATS; static final String SERVICE_URI_SUFFIX_SUBSCRIPTIONS; static final String SERVICE_URI_SUFFIX_SYNCHRONIZATION; static final String SERVICE_URI_SUFFIX_AVAILABLE; static final String SERVICE_URI_SUFFIX_CONFIG; static final String SERVICE_URI_SUFFIX_TEMPLATE; static final String SERVICE_URI_SUFFIX_UI; static final String SERVICE_URI_SUFFIX_REPLICATION; static final String DCP_ENVIRONMENT_VAR_PREFIX; static final String GIT_COMMIT_PROPERTIES_RESOURCE_NAME; static final String GIT_COMMIT_SOURCE_PROPERTY_PREFIX; static final String GIT_COMMIT_SOURCE_PROPERTY_COMMIT_ID; static final String GIT_COMMIT_SOURCE_PROPERTY_COMMIT_TIME; static final String[] RESERVED_SERVICE_URI_PATHS; static final int DEFAULT_SERVICE_STATE_COST_BYTES; static final int DEFAULT_SERVICE_INSTANCE_COST_BYTES; }
@Test public void registerForFactoryServiceAvailability() throws Throwable { setUp(false); this.host.startFactoryServicesSynchronously(new TestFactoryService.SomeFactoryService(), SomeExampleService.createFactory()); this.host.waitForServiceAvailable(SomeExampleService.FACTORY_LINK); this.host.waitForServiceAvailable(TestFactoryService.SomeFactoryService.SELF_LINK); try { this.host.startFactoryServicesSynchronously(new ExampleService()); throw new IllegalStateException("Should have failed"); } catch (IllegalArgumentException e) { } try { this.host.startFactoryServicesSynchronously(new MinimalFactoryTestService()); throw new IllegalStateException("Should have failed"); } catch (IllegalArgumentException e) { } }