@@ -0,0 +1,2534 @@
+package com.pushtechnology.adapters.rest.polling;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Iterator;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.ScheduledExecutorService;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport org.apache.http.concurrent.FutureCallback;%0A%0Aimport com.pushtechnology.adapters.rest.model.v2.Endpoint;%0Aimport com.pushtechnology.adapters.rest.model.v2.Service;%0Aimport com.pushtechnology.diffusion.datatype.json.JSON;%0A%0A/**%0A * The session for a REST service.%0A *%0A * @author Push Technology Limited%0A */%0Apublic final class ServiceSession %7B%0A    private final Collection%3CFuture%3C?%3E%3E tasks = new ArrayList%3C%3E();%0A    private final ScheduledExecutorService executor;%0A    private final PollClient pollClient;%0A    private final Service service;%0A%0A    /**%0A     * Constructor.%0A     */%0A    public ServiceSession(ScheduledExecutorService executor, PollClient pollClient, Service service) %7B%0A        this.executor = executor;%0A        this.pollClient = pollClient;%0A        this.service = service;%0A    %7D%0A%0A    /**%0A     * Start the session.%0A     */%0A    public synchronized void start() %7B%0A        for (final Endpoint endpoint : service.getEndpoints()) %7B%0A            tasks.add(%0A                executor.schedule(new Runnable() %7B%0A                    @Override%0A                    public void run() %7B%0A                        pollClient.request(%0A                            service,%0A                            endpoint,%0A                            new FutureCallback%3CJSON%3E() %7B%0A                                @Override%0A                                public void completed(JSON json) %7B%0A                                    System.out.println(json.toJsonString());%0A                                %7D%0A%0A                                @Override%0A                                public void failed(Exception e) %7B%0A                                    e.printStackTrace();%0A                                %7D%0A%0A                                @Override%0A                                public void cancelled() %7B%0A                                %7D%0A                            %7D);%0A                    %7D%0A                %7D,%0A                service.getPollPeriod(),%0A                TimeUnit.MILLISECONDS));%0A        %7D%0A    %7D%0A%0A    /**%0A     * Start the session.%0A     */%0A    public synchronized void stop() %7B%0A        final Iterator%3CFuture%3C?%3E%3E taskIterator = tasks.iterator();%0A        while (taskIterator.hasNext()) %7B%0A            taskIterator.next().cancel(false);%0A            taskIterator.remove();%0A        %7D%0A    %7D%0A%7D%0A

Add ServiceSession to manage access to a service.