org.jboss.msc.service.ServiceRegistryException Java Examples

The following examples show how to use org.jboss.msc.service.ServiceRegistryException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DomainServerCommunicationServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void activate(final ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    final ServiceTarget serviceTarget = serviceActivatorContext.getServiceTarget();
    final ServiceName endpointName = managementSubsystemEndpoint ? RemotingServices.SUBSYSTEM_ENDPOINT : ManagementRemotingServices.MANAGEMENT_ENDPOINT;
    final EndpointService.EndpointType endpointType = managementSubsystemEndpoint ? EndpointService.EndpointType.SUBSYSTEM : EndpointService.EndpointType.MANAGEMENT;
    try {
        ManagementWorkerService.installService(serviceTarget);
        // TODO see if we can figure out a way to work in the vault resolver instead of having to use ExpressionResolver.SIMPLE
        @SuppressWarnings("deprecation")
        final OptionMap options = EndpointConfigFactory.create(ExpressionResolver.SIMPLE, endpointConfig, DEFAULTS);
        ManagementRemotingServices.installRemotingManagementEndpoint(serviceTarget, endpointName, WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.NODE_NAME, null), endpointType, options);

        // Install the communication services
        final ServiceBuilder<?> sb = serviceTarget.addService(HostControllerConnectionService.SERVICE_NAME);
        final Supplier<ExecutorService> esSupplier = Services.requireServerExecutor(sb);
        final Supplier<ScheduledExecutorService> sesSupplier = sb.requires(ServerService.JBOSS_SERVER_SCHEDULED_EXECUTOR);
        final Supplier<Endpoint> eSupplier = sb.requires(endpointName);
        final Supplier<ProcessStateNotifier> cpsnSupplier = sb.requires(ControlledProcessStateService.INTERNAL_SERVICE_NAME);
        sb.setInstance(new HostControllerConnectionService(managementURI, serverName, serverProcessName, authKey, initialOperationID, managementSubsystemEndpoint, sslContextSupplier, esSupplier, sesSupplier, eSupplier, cpsnSupplier));
        sb.install();
    } catch (OperationFailedException e) {
        throw new ServiceRegistryException(e);
    }
}
 
Example #2
Source File: MetricsServiceActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    ServiceTarget target = serviceActivatorContext.getServiceTarget();

    MetricsService service = new MetricsService();
    ServiceBuilder<MetricsService> metricsServiceBuilder = target.addService(MetricsService.SERVICE_NAME, service);

    ServiceBuilder<MetricsService> serviceBuilder = metricsServiceBuilder
            .addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.getServerEnvironmentInjector())
            .addDependency(ServiceName.parse("jboss.eclipse.microprofile.config.marker"))
            .addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getModelControllerInjector());

    serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

    BinderService binderService = new BinderService(SWARM_MP_METRICS, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, SWARM_MP_METRICS), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
}
 
Example #3
Source File: TopologyWebAppActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    if (!topologyWebAppFractionInstance.isUnsatisfied()) {
        serviceNames = topologyWebAppFractionInstance.get().proxiedServiceMappings().keySet();
    }

    TopologyProxyService proxyService = new TopologyProxyService(serviceNames);
    ServiceBuilder<TopologyProxyService> serviceBuilder = target
            .addService(TopologyProxyService.SERVICE_NAME, proxyService)
            .addDependency(DefaultNamespaceContextSelectorService.SERVICE_NAME)
            .addDependency(TopologyManagerActivator.CONNECTOR_SERVICE_NAME)
            .addDependency(NamingService.SERVICE_NAME);

    for (String serviceName : serviceNames) {
        serviceBuilder.addDependency(proxyService.mscServiceNameForServiceProxy(serviceName),
                                     HttpHandler.class, proxyService.getHandlerInjectorFor(serviceName));
    }
    serviceBuilder.install();
}
 
Example #4
Source File: TopologyManagerActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    target.addService(TopologyManager.SERVICE_NAME, new ValueService<>(new ImmediateValue<>(TopologyManager.INSTANCE)))
            .install();

    BinderService binderService = new BinderService(Topology.JNDI_NAME, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Topology.JNDI_NAME), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(TopologyManager.INSTANCE))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

}
 
Example #5
Source File: RegistrationAdvertiserActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {

    ServiceTarget target = context.getServiceTarget();


    forEachLine(TopologyArchive.REGISTRATION_CONF, registrationLine -> {
        int separatorIndex = registrationLine.indexOf(TopologyArchive.SERVICE_TAG_SEPARATOR);
        String serviceName = registrationLine;
        List<String> tags = Collections.emptyList();
        if (separatorIndex > 0) {
            serviceName = registrationLine.substring(0, separatorIndex);
            tags = getTags(registrationLine.substring(separatorIndex + 1));
        }
        RegistrationAdvertiser.install(target, serviceName, "http", tags);
        RegistrationAdvertiser.install(target, serviceName, "https", tags);
    });
}
 
Example #6
Source File: RegistrationAdvertiserActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private void forEachLine(String resourceName, Consumer<String> consumer) {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);

    if (in == null) {
        return;
    }

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
        String line;
        while ((line = reader.readLine()) != null) {
            consumer.accept(line.trim());
        }
    } catch (IOException e) {
        throw new ServiceRegistryException(e);
    }
}
 
Example #7
Source File: TopologyManagerActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    TopologyManager.INSTANCE.setServiceTarget(target);

    target.addService(SERVICE_NAME, new ValueService<>(new ImmediateValue<>(TopologyManager.INSTANCE)))
            .install();

    BinderService binderService = new BinderService(Topology.JNDI_NAME, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Topology.JNDI_NAME), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(TopologyManager.INSTANCE))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

}
 
Example #8
Source File: JGroupsTopologyConnectorActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    JGroupsTopologyConnector manager = new JGroupsTopologyConnector();

    target.addService(TopologyConnector.SERVICE_NAME, manager)
            .addDependency(ServiceName.parse("jboss.clustering.dispatcher.default"), CommandDispatcherFactory.class, manager.getCommandDispatcherFactoryInjector())
            //.addDependency(ServiceName.parse("org.wildfly.network.socket-binding.http"), SocketBinding.class, manager.getSocketBindingInjector())
            .addDependency(TopologyManager.SERVICE_NAME, TopologyManager.class, manager.getTopologyManagerInjector())
            .install();

}
 
Example #9
Source File: JGroupsTopologyConnectorActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    JGroupsTopologyConnector manager = new JGroupsTopologyConnector();

    target.addService(TopologyManagerActivator.CONNECTOR_SERVICE_NAME, manager)
            .addDependency(ServiceName.parse("org.wildfly.clustering.default-command-dispatcher-factory"), CommandDispatcherFactory.class, manager.getCommandDispatcherFactoryInjector())
            //.addDependency(ServiceName.parse("org.wildfly.network.socket-binding.http"), SocketBinding.class, manager.getSocketBindingInjector())
            .addDependency(TopologyManagerActivator.SERVICE_NAME, TopologyManager.class, manager.getTopologyManagerInjector())
            .install();

}
 
Example #10
Source File: SwaggerActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(SwaggerArchive.SWAGGER_CONFIGURATION_PATH);

    if (in == null) {
        // No config available. Print a warning and return
        System.err.println("WARN: No swagger configuration found. Swagger not activated.");
        return;
    }
    SwaggerConfig config = new SwaggerConfig(in);

    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setHost((String) config.get(SwaggerConfig.Key.HOST));
    beanConfig.setLicense((String) config.get(SwaggerConfig.Key.LICENSE));
    beanConfig.setLicenseUrl((String) config.get(SwaggerConfig.Key.LICENSE_URL));
    beanConfig.setTermsOfServiceUrl((String) config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL));
    beanConfig.setResourcePackage((String) config.get(SwaggerConfig.Key.PACKAGES));
    beanConfig.setVersion((String) config.get(SwaggerConfig.Key.VERSION));
    beanConfig.setBasePath((String) config.get(SwaggerConfig.Key.ROOT));
    beanConfig.setContact((String) config.get(SwaggerConfig.Key.CONTACT));
    beanConfig.setDescription((String) config.get(SwaggerConfig.Key.DESCRIPTION));
    beanConfig.setTitle((String) config.get(SwaggerConfig.Key.TITLE));
    beanConfig.setPrettyPrint((String) config.get(SwaggerConfig.Key.PRETTY_PRINT));
    beanConfig.setSchemes((String[]) config.get(SwaggerConfig.Key.SCHEMES));

    beanConfig.setScan(true);

}
 
Example #11
Source File: DaemonServiceActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    DaemonService runner = new DaemonService();
    serviceActivatorContext.getServiceTarget()
            .addService(ServiceName.of("wildfly", "swarm", "arquillian", "daemon", "runner"),
                    runner)
            .addDependency(ServiceName.JBOSS.append("as", "service-module-loader"),
                    ModuleLoader.class,
                    runner.getServiceLoader())
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
}
 
Example #12
Source File: ConsulTopologyConnectorActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    ConsulTopologyConnector connector = new ConsulTopologyConnector(this.url);

    target.addService(TopologyConnector.SERVICE_NAME, connector)
            //.addDependency(ServiceName.parse("org.wildfly.network.socket-binding.http"), SocketBinding.class, connector.getSocketBindingInjector())
            .addDependency(TopologyManager.SERVICE_NAME, TopologyManager.class, connector.getTopologyManagerInjector())
            .install();
}
 
Example #13
Source File: RegistrationAdvertiserActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {

    ServiceTarget target = context.getServiceTarget();

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(TopologyArchive.REGISTRATION_CONF);

    if (in == null) {
        return;
    }

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {

        String serviceName = null;

        while ((serviceName = reader.readLine()) != null) {
            serviceName = serviceName.trim();
            if (!serviceName.isEmpty()) {
                installAdvertiser( target, serviceName, "http" );
                installAdvertiser( target, serviceName, "https" );
            }
        }

    } catch (IOException e) {
        throw new ServiceRegistryException(e);
    }
}
 
Example #14
Source File: TestSuspendServiceActivator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    TestUndertowService testUndertowService = new TestUndertowService();
    serviceActivatorContext.getServiceTarget().addService(TestUndertowService.SERVICE_NAME, testUndertowService)
            .addDependency(RequestController.SERVICE_NAME, RequestController.class, testUndertowService.getRequestControllerInjectedValue())
            .addDependency(SocketBindingManager.SOCKET_BINDING_MANAGER, SocketBindingManager.class, testUndertowService.getSocketBindingManagerInjectedValue())
            .install();
}
 
Example #15
Source File: UndertowServiceActivator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public final void activate(final ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    final String address = getAddress();
    assert address != null : "address cannot be null";
    final int port = getPort();
    assert port > 0 : "port must be greater than 0";
    final HttpHandler handler = getHttpHandler();
    assert handler != null : "A handler is required";
    ServiceBuilder<?> builder = serviceActivatorContext.getServiceTarget().addService(getServiceName());
    createService(address, port, handler, builder);
    builder.install();
}
 
Example #16
Source File: SlowServiceActivator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    try {
        long timeout = System.currentTimeMillis() + TimeoutUtil.adjust(60)*1000;
        while (System.currentTimeMillis() - timeout < 0) {
            TimeUnit.SECONDS.sleep(1);
        }
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
 
Example #17
Source File: DelayedBinderServiceActivator.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    BindInfo bindInfo = ContextNames.bindInfoFor("java:/spring/binding/test");
    DelayedBinderService service = new DelayedBinderService(bindInfo.getBindName());
    ManagedReferenceFactory managedReferenceFactory = new ImmediateManagedReferenceFactory(service);

    ServiceTarget serviceTarget = context.getServiceTarget();
    serviceTarget.addService(bindInfo.getBinderServiceName(), service)
        .addInjection(service.getManagedObjectInjector(), managedReferenceFactory)
        .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector())
        .install();
}
 
Example #18
Source File: MonitorServiceActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    Optional<String> securityRealm = Optional.empty();

    if (!monitorFractionInstance.isUnsatisfied()) {
        securityRealm = monitorFractionInstance.get().securityRealm();
    }

    ServiceTarget target = context.getServiceTarget();

    MonitorService service = new MonitorService(securityRealm);

    ServiceBuilder<MonitorService> monitorServiceServiceBuilder = target.addService(MonitorService.SERVICE_NAME, service);

    ServiceBuilder<MonitorService> serviceBuilder = monitorServiceServiceBuilder
            .addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.getServerEnvironmentInjector())
            .addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getModelControllerInjector());

    if (securityRealm.isPresent()) { // configured through the fraction interface
        serviceBuilder.addDependency(
                createRealmName(securityRealm.get()),
                SecurityRealm.class,
                service.getSecurityRealmInjector()
        );
    }

    serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

    BinderService binderService = new BinderService(Monitor.JNDI_NAME, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Monitor.JNDI_NAME), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(service))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

}
 
Example #19
Source File: MonitorServiceActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    Optional<String> securityRealm = Optional.empty();

    if (!healthFractionInstance.isUnsatisfied()) {
        securityRealm = healthFractionInstance.get().securityRealm();
    }

    ServiceTarget target = context.getServiceTarget();

    MonitorService service = new MonitorService(securityRealm);

    ServiceBuilder<MonitorService> monitorServiceServiceBuilder = target.addService(MonitorService.SERVICE_NAME, service);

    ServiceBuilder<MonitorService> serviceBuilder = monitorServiceServiceBuilder
            .addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.getServerEnvironmentInjector())
            .addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getModelControllerInjector());

    if (securityRealm.isPresent()) { // configured through the fraction interface
        serviceBuilder.addDependency(
                createRealmName(securityRealm.get()),
                SecurityRealm.class,
                service.getSecurityRealmInjector()
        );
    }

    serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

    BinderService binderService = new BinderService(Monitor.JNDI_NAME, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Monitor.JNDI_NAME), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(service))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

}
 
Example #20
Source File: ConsulTopologyConnectorActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    ConsulTopologyConnector connector = new ConsulTopologyConnector();

    target.addService(TopologyManagerActivator.CONNECTOR_SERVICE_NAME, connector)
            .addDependency(TopologyManagerActivator.SERVICE_NAME, TopologyManager.class, connector.getTopologyManagerInjector())
            .addDependency(Advertiser.SERVICE_NAME, Advertiser.class, connector.getAdvertiserInjector())
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
}
 
Example #21
Source File: AgentActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {

    ServiceTarget target = context.getServiceTarget();

    ConsulService consul = new ConsulService(this.fraction.url());
    target.addService(ConsulService.SERVICE_NAME, consul)
            .install();

    HealthClientService healthClient = new HealthClientService();
    target.addService(HealthClientService.SERIVCE_NAME, healthClient)
            .addDependency(ConsulService.SERVICE_NAME, Consul.class, healthClient.getConsulInjector())
            .install();


    CatalogClientService catalogClient = new CatalogClientService();
    target.addService(CatalogClientService.SERVICE_NAME, catalogClient)
            .addDependency(ConsulService.SERVICE_NAME, Consul.class, catalogClient.getConsulInjector())
            .install();

    AgentClientService agentClient = new AgentClientService();
    target.addService(AgentClientService.SERVICE_NAME, agentClient)
            .addDependency(ConsulService.SERVICE_NAME, Consul.class, agentClient.getConsulInjector())
            .install();

    Advertiser advertiser = new Advertiser();
    advertiser.setCheckTTL(fraction.ttl());
    target.addService(Advertiser.SERVICE_NAME, advertiser)
            .addDependency(AgentClientService.SERVICE_NAME, AgentClient.class, advertiser.getAgentClientInjector())
            .install();

}
 
Example #22
Source File: CacheActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    Service<Void> service = new AbstractService<Void>() { };
    context.getServiceTarget()
            .addService(ServiceName.of("thorntail", "cache-activator").append(this.cacheContainerName), service)
            .addDependency(this.type.serviceNameBase.append(this.cacheContainerName))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
}
 
Example #23
Source File: OpenShiftTopologyConnectorActivator.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    OpenShiftTopologyConnector connector = new OpenShiftTopologyConnector();

    target.addService(TopologyManagerActivator.CONNECTOR_SERVICE_NAME, connector)
            .addDependency(TopologyManagerActivator.SERVICE_NAME, TopologyManager.class, connector.getTopologyManagerInjector())
            .install();
}
 
Example #24
Source File: MyServiceActivator.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();
    target.addService(ServiceName.of("swarm", "test", "cheese"), new ValueService<>(new ImmediateValue<>("cheddar")))
            .install();
}
 
Example #25
Source File: DaemonServiceActivator.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    DaemonService.addService(serviceActivatorContext.getServiceTarget());
}
 
Example #26
Source File: SwaggerServiceActivator.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(SwaggerArchive.SWAGGER_CONFIGURATION_PATH);

    if (in == null) {
        // try again, we must go deeper.
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream("WEB-INF/classes/" + SwaggerArchive.SWAGGER_CONFIGURATION_PATH);
    }

    if (in == null) {
        // No config available. Print a warning and return
        SwaggerMessages.MESSAGES.noConfigurationFound();
        return;
    }

    try {
        SwaggerConfig config = new SwaggerConfig(in);

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setHost((String) config.get(SwaggerConfig.Key.HOST));
        beanConfig.setLicense((String) config.get(SwaggerConfig.Key.LICENSE));
        beanConfig.setLicenseUrl((String) config.get(SwaggerConfig.Key.LICENSE_URL));
        beanConfig.setTermsOfServiceUrl((String) config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL));

        // some type inconsistencies in the API (String vs String[])
        String[] packages = (String[]) config.get(SwaggerConfig.Key.PACKAGES);

        if (packages != null) {
            StringBuffer sb = new StringBuffer();
            for (String s : packages) {
                sb.append(s).append(',');
            }

            beanConfig.setResourcePackage(sb.toString());
        }

        beanConfig.setVersion((String) config.get(SwaggerConfig.Key.VERSION));
        beanConfig.setBasePath((String) config.get(SwaggerConfig.Key.ROOT));
        beanConfig.setContact((String) config.get(SwaggerConfig.Key.CONTACT));
        beanConfig.setDescription((String) config.get(SwaggerConfig.Key.DESCRIPTION));
        beanConfig.setTitle((String) config.get(SwaggerConfig.Key.TITLE));
        beanConfig.setPrettyPrint((String) config.get(SwaggerConfig.Key.PRETTY_PRINT));
        beanConfig.setSchemes((String[]) config.get(SwaggerConfig.Key.SCHEMES));

        beanConfig.setScan(true);
    } catch (IOException e) {
        throw new ServiceRegistryException(e);
    }

}
 
Example #27
Source File: ServerStartTask.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public AsyncFuture<ServiceContainer> run(final List<ServiceActivator> runServices) {
    final Bootstrap bootstrap = Bootstrap.Factory.newInstance();
    final ProductConfig productConfig = ProductConfig.fromFilesystemSlot(Module.getBootModuleLoader(), home, properties);
    // Create server environment on the server, so that the system properties are getting initialized on the right side
    final ServerEnvironment providedEnvironment = new ServerEnvironment(hostControllerName, properties,
            WildFlySecurityManager.getSystemEnvironmentPrivileged(), null, null, ServerEnvironment.LaunchType.DOMAIN,
            RunningMode.NORMAL, productConfig, Module.getStartTime(), suspend, null, null, null);
    DomainServerCommunicationServices.updateOperationID(initialOperationID);

    // TODO perhaps have ConfigurationPersisterFactory as a Service
    final List<ServiceActivator> services = new ArrayList<ServiceActivator>(startServices);
    final ServerBootOperationsService service = new ServerBootOperationsService();
    // ModelController.boot() will block on this future in order to get the boot updates.
    final Future<ModelNode> bootOperations = service.getFutureResult();
    final ServiceActivator activator = new ServiceActivator() {
        @Override
        public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
            final ServiceTarget target = serviceActivatorContext.getServiceTarget();
            final ServiceBuilder sb = target.addService(ServiceName.JBOSS.append("server-boot-operations"), service);
            sb.requires(Services.JBOSS_AS);
            sb.addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, service.getServerController());
            sb.addDependency(HostControllerConnectionService.SERVICE_NAME, HostControllerClient.class, service.getClientInjector());
            sb.addDependency(Services.JBOSS_SERVER_EXECUTOR, Executor.class, service.getExecutorInjector());
            sb.install();
        }
    };
    services.add(activator);

    final Bootstrap.Configuration configuration = new Bootstrap.Configuration(providedEnvironment);
    final ExtensionRegistry extensionRegistry = configuration.getExtensionRegistry();
    final Bootstrap.ConfigurationPersisterFactory configurationPersisterFactory = new Bootstrap.ConfigurationPersisterFactory() {
        @Override
        public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
            ExtensibleConfigurationPersister persister = new AbstractConfigurationPersister(new StandaloneXml(configuration.getModuleLoader(), executorService, extensionRegistry)) {

                private final PersistenceResource pr = new PersistenceResource() {

                    @Override
                    public void commit() {
                    }

                    @Override
                    public void rollback() {
                    }
                };

                @Override
                public PersistenceResource store(final ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException {
                    return pr;
                }

                @Override
                public List<ModelNode> load() throws ConfigurationPersistenceException {
                    try {
                        final ModelNode operations = bootOperations.get();
                        return operations.asList();
                    } catch (Exception e) {
                        throw new ConfigurationPersistenceException(e);
                    }
                }
            };
            extensionRegistry.setWriterRegistry(persister);
            return persister;
        }
    };
    configuration.setConfigurationPersisterFactory(configurationPersisterFactory);
    return bootstrap.bootstrap(configuration, services);
}
 
Example #28
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ServiceController<T> install() throws ServiceRegistryException, IllegalStateException {
    ContextServiceInstaller installer = this.serviceInstaller;
    return installer == null ? realBuilder.install() : installer.installService(realBuilder);
}
 
Example #29
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private <T> ServiceController<T> installService(ServiceBuilder<T> builder, ServiceName name, Step step)
        throws ServiceRegistryException, IllegalStateException {

    synchronized (realRemovingControllers) {
        boolean intr = false;
        try {
            boolean containsKey = realRemovingControllers.containsKey(name);
            long timeout = getBlockingTimeout().getLocalBlockingTimeout();
            long waitTime = timeout;
            long end = System.currentTimeMillis() + waitTime;
            while (containsKey && waitTime > 0) {
                try {
                    realRemovingControllers.wait(waitTime);
                } catch (InterruptedException e) {
                    intr = true;
                    if (respectInterruption) {
                        cancelled = true;
                        throw ControllerLogger.ROOT_LOGGER.serviceInstallCancelled();
                    } // else keep waiting and mark the thread interrupted at the end
                }
                containsKey = realRemovingControllers.containsKey(name);
                waitTime = end - System.currentTimeMillis();
            }

            if (containsKey) {
                // We timed out
                throw ControllerLogger.ROOT_LOGGER.serviceInstallTimedOut(timeout / 1000, name);
            }

            // If a step removed this ServiceName before, it's no longer responsible
            // for any ill effect
            removalSteps.remove(name);

            ServiceController<T> controller = builder.install();
            step.serviceAdded(controller);
            return controller;
        } finally {
            if (intr) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
 
Example #30
Source File: ServiceActivatorBaseDeployment.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {
    serviceActivatorContext.getServiceTarget().addService(serviceName, this).install();
}