/** * Create a default factory service that starts instances of this service on POST. * This method is optional, {@code FactoryService.create} can be used directly */ public static FactoryService createFactory() { return FactoryService.create(ExampleODLService.class); }
public TableDescription useFactoryService(FactoryService factoryService) { if (factoryService.getHost() == null) { factoryService.setHost(this.host); } try { if (getFactoryLink() == null) { setFactoryLink(factoryService.getSelfLink()); } StatefulService childService = (StatefulService) factoryService.createServiceInstance(); useStatefulService(childService); return this; } catch (Throwable e) { throw new IllegalArgumentException(String.format( "Failed to add factory %s", factoryService.getClass().getCanonicalName()), e); } }
protected String buildDefaultChildSelfLink(ServiceDocument document) { return buildDefaultChildSelfLink(); }
OperationProcessingChain opProcessingChain = getOperationProcessingChain(); if (opProcessingChain != null) { OperationProcessingContext context = opProcessingChain.createContext(getHost()); opProcessingChain.processRequest(op, context, o -> { handleRequest(op, OperationProcessingStage.EXECUTING_SERVICE_HANDLER); }); return; op.nestCompletion((o, e) -> { if (e != null) { logWarning("Service start failed: %s", Utils.toString(e)); op.fail(e); return; handlePostCompletion(op); }); handlePost(op); if (this.getProcessingStage() != ProcessingStage.AVAILABLE) { op.setBody(new ServiceDocumentQueryResult()).complete(); return; handleGet(op); } else if (op.getAction() == Action.DELETE) { if (ServiceHost.isServiceStop(op)) { op.nestCompletion(o -> { handleStopCompletion(op); }); handleStop(op);
private Service newServiceInstance() throws InstantiationError { try { if (this.factoryCreator != null) { FactoryService factoryService = this.factoryCreator.get(); return factoryService.createServiceInstance(); } else { return this.serviceClass.newInstance(); } } catch (Throwable thr) { throw new InstantiationError("Failed to create an instance of " + this.serviceClass + ". Details: " + Utils.toString(thr)); } }
ServiceDocument initialState = null; try { childService = createChildService(); suffix = buildDefaultChildSelfLink(initialState); } else { if (initialState == null) { suffix = buildDefaultChildSelfLink(); initialState = new ServiceDocument(); } else { if (initialState.documentSelfLink == null) { suffix = buildDefaultChildSelfLink(); } else { if (!UriUtils.isValidDocumentId(suffix, this.getSelfLink())) { o.fail(new IllegalArgumentException(suffix + " is an invalid id")); return; if (UriUtils.isChildPath(suffix, getSelfLink())) { serviceUri = UriUtils.buildUri(getHost(), suffix); } else { serviceUri = UriUtils.extendUri(getUri(), suffix); logSevere(e); o.fail(e); return; initialState.documentKind = Utils.buildKind(this.stateType);
private ServiceDocument getChildTemplate(String childLink) { if (this.childTemplate == null) { try { Service s = createServiceInstance(); s.setHost(getHost()); s.setSelfLink(childLink); s.toggleOption(ServiceOption.FACTORY_ITEM, true); this.childTemplate = s.getDocumentTemplate(); } catch (Throwable e) { logSevere(e); return null; } } return this.childTemplate; }
if (!factoryService.hasChildOption(ServiceOption.PERSISTENCE) && !service.hasOption(ServiceOption.PERSISTENCE)) { op.complete(); + "index", factoryService.getStateType().getCanonicalName()); op.complete(); return; if (!factoryService.hasChildOption(ServiceOption.PERIODIC_MAINTENANCE)) { factoryService.setAvailable(true); .buildUriPath(factoryService.getSelfLink(), "child-template"); .getDocumentTemplate()).documents.get(childLink); Class<? extends ServiceDocument> stateType = factoryService.getStateType(); host.log(Level.INFO, "Initializing Postgres DB for %s under %s", stateType.getCanonicalName(), factoryService.getSelfLink()); indexService.getDao().initForDocument(factoryService.getSelfLink(), stateType, childTemplate.documentDescription); } catch (Exception e2) {
private Service createChildService() throws Throwable { Service childService; childService = createServiceInstance(); this.childOptions = childService.getOptions(); toggleOption(ServiceOption.REPLICATION, true); if (!ServiceUriPaths.DEFAULT_NODE_SELECTOR.equals(childService .getPeerNodeSelectorPath())) { toggleOption(ServiceOption.HTML_USER_INTERFACE, true); toggleOption(ServiceOption.INSTRUMENTATION, true); if (this.hasOption(ServiceOption.IDEMPOTENT_POST)) { childService.toggleOption(ServiceOption.IDEMPOTENT_POST, true);
if (this.parent != null && this.parent.hasChildOption(ServiceOption.PERSISTENCE) && !this.parent.hasChildOption(ServiceOption.PERIODIC_MAINTENANCE) && this.isCheckpointEnabled) { CheckpointService.CheckpointState s = new CheckpointService.CheckpointState(); s.timestamp = task.startTimeMicros; s.factoryLink = this.parent.getSelfLink(); if (this.isDetailedLoggingEnabled) { log(Level.INFO, "synchronization task for %s has been re-scheduled", this.parent.getSelfLink()); SynchronizationTaskService.State scheduleTask = this.parent.createSynchronizationTaskState( task.membershipUpdateTimeMicros); Operation.createPost(this, ServiceUriPaths.SYNCHRONIZATION_TASKS) this.getHost().broadcastRequest(this.parent.getPeerNodeSelectorPath(), CheckpointService.FACTORY_LINK, false, post); return;
factoryInstance.setHost(host); Service serviceInstance = factoryInstance.createServiceInstance(); serviceInstance.setHost(host); assertNotNull(serviceInstance);
public static FactoryService createFactory() { return FactoryService.createIdempotent(ResourceMetricsService.class); }
getSelfLink()); completePostRequest(o, childService); return; getSelfLink(), null); if (initialState.documentSelfLink.startsWith(getSelfLink())) { initialState.documentSelfLink = initialState.documentSelfLink .substring(getSelfLink().length()); getHost().sendRequest(forwardOp); }); getHost().selectOwner(getPeerNodeSelectorPath(), o.getUri().getPath(), selectOp);
String serviceSelectorPath = factoryService.getPeerNodeSelectorPath(); if (!nodeSelectorPath.equals(serviceSelectorPath)) { continue; if (!factoryService.hasChildOption(Service.ServiceOption.PERIODIC_MAINTENANCE)) { continue;
@Override public void handlePost(Operation request) { checkAndNestCompletionForAuthzCacheClear(this, request); super.handlePost(request); } };
if (parent instanceof FactoryService) { FactoryService factory = (FactoryService) parent; if (factory.hasChildOption(ServiceOption.OWNER_SELECTION)) { options.add(ServiceOption.OWNER_SELECTION); if (factory.hasChildOption(ServiceOption.REPLICATION)) { options.add(ServiceOption.REPLICATION); if (factory.hasChildOption(ServiceOption.PERSISTENCE)) { options.add(ServiceOption.PERSISTENCE);
private Collection<InterceptorData> checkForInterceptor(Service service) { Collection<InterceptorData> data = this.serviceInterceptors.get(service.getClass()); if (data != null) { return data; } if (service instanceof FactoryService) { try { Service actualInstance = ((FactoryService) service).createServiceInstance(); data = this.factoryServiceInterceptors.get(actualInstance.getClass()); } catch (Throwable e) { service.getHost().log(Level.WARNING, "Failure instantiating service instance: %s", Utils.toString(e)); } } return data; }
public static FactoryService createFactory() { return FactoryService.createIdempotent(InMemoryResourceMetricService.class); }
String serviceSelectorPath = factoryService.getPeerNodeSelectorPath(); if (!nodeSelectorPath.equals(serviceSelectorPath)) { continue; if (!factoryService.hasChildOption(Service.ServiceOption.PERIODIC_MAINTENANCE)) { continue;
@Override public void handlePost(Operation request) { checkAndNestCompletionForAuthzCacheClear(this, request); super.handlePost(request); } };