Search in sources :

Example 1 with Singleton

use of org.wildfly.clustering.singleton.Singleton in project wildfly by wildfly.

the class SingletonMetricExecutor method execute.

@Override
public ModelNode execute(OperationContext context, Metric<Singleton> metric) throws OperationFailedException {
    ServiceName name = this.serviceNameFactory.apply(context.getCurrentAddressValue());
    FunctionExecutor<Singleton> executor = this.executors.get(name.append("singleton"));
    return ((executor != null) ? executor : new LegacySingletonFunctionExecutor(context, name)).execute(new MetricFunction<>(Function.identity(), metric));
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) Singleton(org.wildfly.clustering.singleton.Singleton)

Example 2 with Singleton

use of org.wildfly.clustering.singleton.Singleton in project quickstart by wildfly.

the class QueryingService method start.

@Override
public void start(StartContext context) {
    Singleton singleton = this.singleton.get();
    this.executor = Executors.newSingleThreadScheduledExecutor();
    this.executor.scheduleAtFixedRate(() -> {
        Node primary = singleton.getPrimaryProvider();
        if (primary != null) {
            this.log.infof("Singleton service running on %s.", primary);
        } else {
            this.log.infof("Singleton service not running anywhere.");
        }
    }, 5, 5, TimeUnit.SECONDS);
    this.log.info("Querying service started");
}
Also used : Singleton(org.wildfly.clustering.singleton.Singleton) Node(org.wildfly.clustering.group.Node)

Example 3 with Singleton

use of org.wildfly.clustering.singleton.Singleton in project wildfly by wildfly.

the class SingletonPolicyResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addCapabilities(Capability.class).addRequiredSingletonChildren(SimpleElectionPolicyResourceDefinition.PATH).setResourceTransformation(SingletonPolicyResource::new);
    ServiceValueExecutorRegistry<Singleton> executors = new ServiceValueExecutorRegistry<>();
    ResourceServiceHandler handler = new SingletonPolicyServiceHandler(executors);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    new RandomElectionPolicyResourceDefinition().register(registration);
    new SimpleElectionPolicyResourceDefinition().register(registration);
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new SingletonDeploymentResourceDefinition(executors).register(registration);
        new SingletonServiceResourceDefinition(executors).register(registration);
    }
    return registration;
}
Also used : ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) Singleton(org.wildfly.clustering.singleton.Singleton) ServiceValueExecutorRegistry(org.jboss.as.clustering.controller.ServiceValueExecutorRegistry) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 4 with Singleton

use of org.wildfly.clustering.singleton.Singleton in project wildfly by wildfly.

the class DistributedSingletonServiceConfigurator method build.

@Override
public SingletonServiceBuilder<?> build(ServiceTarget target) {
    ServiceName name = this.getServiceName().append("singleton");
    ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target);
    Consumer<Singleton> singleton = builder.provides(name);
    return new DistributedSingletonServiceBuilder<>(this, new CompositeDependency(this.registry, this.dispatcherFactory).register(builder), singleton);
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) Singleton(org.wildfly.clustering.singleton.Singleton) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Aggregations

Singleton (org.wildfly.clustering.singleton.Singleton)4 ServiceName (org.jboss.msc.service.ServiceName)2 ManagementResourceRegistration (org.jboss.as.clustering.controller.ManagementResourceRegistration)1 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)1 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)1 ServiceValueExecutorRegistry (org.jboss.as.clustering.controller.ServiceValueExecutorRegistry)1 SimpleResourceRegistration (org.jboss.as.clustering.controller.SimpleResourceRegistration)1 Node (org.wildfly.clustering.group.Node)1 AsyncServiceConfigurator (org.wildfly.clustering.service.AsyncServiceConfigurator)1 CompositeDependency (org.wildfly.clustering.service.CompositeDependency)1