package org.coderthoughts.primes.client;

import org.coderthoughts.primes.service.PrimeNumberService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

@Component
public class PrimeClient {
    @Reference
    private PrimeNumberService primeGenerator;

    private volatile boolean keepRunning = false;

    @Activate
    private void start() {
        keepRunning = true;
        new Thread(() -> {
            while (keepRunning) {
                System.out.print("First 10 primes: ");
                for (int i=0, p=1; i<10; i++) {
                    if (i > 0)
                        System.out.print(", ");
                    p = primeGenerator.nextPrime(p);
                    System.out.print(p);
                }
                System.out.println();
                try { Thread.sleep(1000); } catch (InterruptedException ie) {}
            }
        }).start();
    }

    @Deactivate
    private void stop() {
        keepRunning = false;
    }
}

@@ -322,16 +322,85 @@
 ference;
+%0Aimport org.osgi.service.component.annotations.ReferencePolicyOption;
 %0A%0A@Compo
@@ -445,16 +445,59 @@
 eference
+(policyOption=ReferencePolicyOption.GREEDY)
 %0A    pri

Add greedy reference policy