Search in sources :

Example 1 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class LocalRouteLocatorTestCase method test.

@Test
public void test() {
    String route = "route";
    RouteLocator locator = new LocalRouteLocator(route);
    String result = locator.locate("abc123");
    Assert.assertSame(route, result);
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Test(org.junit.Test)

Example 2 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class LocalRouteLocatorServiceConfigurator method build.

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

Example 3 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class NullRouteLocatorServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceName name = this.getServiceName();
    ServiceBuilder<?> builder = target.addService(name);
    Consumer<RouteLocator> locator = builder.provides(name);
    Service service = Service.newInstance(locator, new NullRouteLocator());
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) ServiceName(org.jboss.msc.service.ServiceName) Service(org.jboss.msc.Service)

Example 4 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class PrimaryOwnerRouteLocatorServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceName name = this.getServiceName();
    ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target);
    Consumer<RouteLocator> locator = new CompositeDependency(this.registry, this.cache, this.factory).register(builder).provides(name);
    Service service = new FunctionalService<>(locator, Function.identity(), this);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) 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 5 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class PrimaryOwnerRouteLocatorTestCase method test.

@Test
public void test() {
    Function<GroupedKey<String>, Node> locator = mock(Function.class);
    Registry<String, Void> registry = mock(Registry.class);
    Group group = mock(Group.class);
    Node primary = mock(Node.class);
    Node local = mock(Node.class);
    Node missing = mock(Node.class);
    String primaryRoute = "primary";
    String localRoute = "local";
    when(registry.getGroup()).thenReturn(group);
    when(group.getLocalMember()).thenReturn(local);
    when(registry.getEntry(local)).thenReturn(new SimpleImmutableEntry<>(localRoute, null));
    RouteLocator routeLocator = new PrimaryOwnerRouteLocator(locator, registry);
    when(locator.apply(new GroupedKey<>("session"))).thenReturn(primary);
    when(registry.getEntry(primary)).thenReturn(new SimpleImmutableEntry<>(primaryRoute, null));
    String result = routeLocator.locate("session");
    assertSame(primaryRoute, result);
    when(locator.apply(new GroupedKey<>("missing"))).thenReturn(missing);
    when(registry.getEntry(missing)).thenReturn(null);
    result = routeLocator.locate("missing");
    assertSame(localRoute, result);
}
Also used : Group(org.wildfly.clustering.group.Group) RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Node(org.wildfly.clustering.group.Node) GroupedKey(org.wildfly.clustering.ee.infinispan.GroupedKey) Test(org.junit.Test)

Aggregations

RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)8 Service (org.jboss.msc.Service)4 Test (org.junit.Test)4 ServiceName (org.jboss.msc.service.ServiceName)3 FunctionalService (org.wildfly.clustering.service.FunctionalService)3 Group (org.wildfly.clustering.group.Group)2 Node (org.wildfly.clustering.group.Node)2 Address (org.infinispan.remoting.transport.Address)1 SessionIdentifierCodec (org.jboss.as.web.session.SessionIdentifierCodec)1 GroupedKey (org.wildfly.clustering.ee.infinispan.GroupedKey)1 KeyDistribution (org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution)1 AsyncServiceConfigurator (org.wildfly.clustering.service.AsyncServiceConfigurator)1 CompositeDependency (org.wildfly.clustering.service.CompositeDependency)1