in curator-examples/src/main/java/pubsub/SubPubTest.java [130:187]
private void publishSomething(Publisher publisher) {
// randomly do some publishing - either single items or lists of items in a transaction
switch (ThreadLocalRandom.current().nextInt(6)) {
case 0: {
Instance instance =
new Instance(nextId(), random(InstanceType.values()), random(hostnames), random(ports));
System.out.println("Publishing 1 instance");
publisher.publishInstance(instance);
break;
}
case 1: {
List<Instance> instances = IntStream.range(1, 10)
.mapToObj(__ ->
new Instance(nextId(), random(InstanceType.values()), random(hostnames), random(ports)))
.collect(Collectors.toList());
System.out.printf("Publishing %d instances%n", instances.size());
publisher.publishInstances(instances);
break;
}
case 2: {
LocationAvailable locationAvailable = new LocationAvailable(
nextId(), random(Priority.values()), random(locations), random(durations));
System.out.println("Publishing 1 locationAvailable");
publisher.publishLocationAvailable(random(groups), locationAvailable);
break;
}
case 3: {
List<LocationAvailable> locationsAvailable = IntStream.range(1, 10)
.mapToObj(__ -> new LocationAvailable(
nextId(), random(Priority.values()), random(locations), random(durations)))
.collect(Collectors.toList());
System.out.printf("Publishing %d locationsAvailable%n", locationsAvailable.size());
publisher.publishLocationsAvailable(random(groups), locationsAvailable);
break;
}
case 4: {
UserCreated userCreated =
new UserCreated(nextId(), random(Priority.values()), random(locations), random(positions));
System.out.println("Publishing 1 userCreated");
publisher.publishUserCreated(random(groups), userCreated);
break;
}
case 5: {
List<UserCreated> usersCreated = IntStream.range(1, 10)
.mapToObj(__ -> new UserCreated(
nextId(), random(Priority.values()), random(locations), random(positions)))
.collect(Collectors.toList());
System.out.printf("Publishing %d usersCreated%n", usersCreated.size());
publisher.publishUsersCreated(random(groups), usersCreated);
break;
}
}
}