Search in sources :

Example 6 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class BeanExpirationSchedulerTestCase method testExpire.

@Test
public void testExpire() throws InterruptedException {
    Group group = mock(Group.class);
    Batcher<TransactionBatch> batcher = mock(Batcher.class);
    TransactionBatch batch = mock(TransactionBatch.class);
    BeanFactory<String, Object> factory = mock(BeanFactory.class);
    ExpirationConfiguration<Object> config = mock(ExpirationConfiguration.class);
    RemoveListener<Object> listener = mock(RemoveListener.class);
    BeanEntry<String> entry = mock(BeanEntry.class);
    BeanRemover<String, Object> remover = mock(BeanRemover.class);
    String beanId = "expiring";
    Duration timeout = Duration.ofMillis(10L);
    when(group.isSingleton()).thenReturn(true);
    when(batcher.createBatch()).thenReturn(batch);
    when(config.getTimeout()).thenReturn(timeout);
    when(config.getRemoveListener()).thenReturn(listener);
    when(entry.getLastAccessedTime()).thenReturn(Instant.now());
    when(remover.remove(beanId, listener)).thenReturn(true);
    try (Scheduler<String, ImmutableBeanEntry<String>> scheduler = new BeanExpirationScheduler<>(group, batcher, factory, config, remover, Duration.ZERO)) {
        scheduler.schedule(beanId, entry);
        Thread.sleep(500);
    }
    verify(batch).close();
}
Also used : Group(org.wildfly.clustering.group.Group) TransactionBatch(org.wildfly.clustering.ee.cache.tx.TransactionBatch) Duration(java.time.Duration) Test(org.junit.Test)

Example 7 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class CacheGroupServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceName name = this.getServiceName();
    ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target);
    Consumer<Group> group = new CompositeDependency(this.cache, this.factory).register(builder).provides(name);
    Service service = new FunctionalService<>(group, Functions.identity(), this, Consumers.close());
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : Group(org.wildfly.clustering.group.Group) FunctionalService(org.wildfly.clustering.service.FunctionalService) ServiceName(org.jboss.msc.service.ServiceName) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Example 8 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class ChannelGroupServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceBuilder<?> builder = target.addService(this.getServiceName());
    Consumer<Group> group = this.factory.register(builder).provides(this.getServiceName());
    Service service = new FunctionalService<>(group, Function.identity(), this);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : Group(org.wildfly.clustering.group.Group) FunctionalService(org.wildfly.clustering.service.FunctionalService) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service)

Example 9 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class ConcurrentBroadcastCommandDispatcherFactoryTestCase method getGroup.

@Test
public void getGroup() {
    Group group = mock(Group.class);
    CommandDispatcherFactory factory = new ConcurrentBroadcastCommandDispatcherFactory(this.factory);
    when(this.factory.getGroup()).thenReturn(group);
    Group result = factory.getGroup();
    Assert.assertSame(group, result);
}
Also used : Group(org.wildfly.clustering.group.Group) CommandDispatcherFactory(org.wildfly.clustering.dispatcher.CommandDispatcherFactory) Test(org.junit.Test)

Example 10 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class NodeServiceActivator method install.

private static void install(ServiceTarget target, SingletonServiceBuilderFactory factory, ServiceName name, int quorum) {
    InjectedValue<Group> group = new InjectedValue<>();
    NodeService service = new NodeService(group);
    factory.createSingletonServiceBuilder(name, service).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(PREFERRED_NODE))).requireQuorum(quorum).build(target).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) Group(org.wildfly.clustering.group.Group) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Aggregations

Group (org.wildfly.clustering.group.Group)19 Test (org.junit.Test)7 InjectedValue (org.jboss.msc.value.InjectedValue)6 Node (org.wildfly.clustering.group.Node)6 TransactionBatch (org.wildfly.clustering.ee.cache.tx.TransactionBatch)4 Duration (java.time.Duration)3 Service (org.jboss.msc.Service)3 ServiceRegistryException (org.jboss.msc.service.ServiceRegistryException)3 FunctionalService (org.wildfly.clustering.service.FunctionalService)3 SingletonPolicy (org.wildfly.clustering.singleton.SingletonPolicy)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)2 NamePreference (org.wildfly.clustering.singleton.election.NamePreference)2 PreferredSingletonElectionPolicy (org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)2 SimpleSingletonElectionPolicy (org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy)2 RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)2 AbstractMap (java.util.AbstractMap)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 LinkedList (java.util.LinkedList)1