Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GET
- @Path("/progressAfterED")
- @Produces(SseFeature.SERVER_SENT_EVENTS)
- public Response changeDetectionwithProgressAfterED(@QueryParam("extent") String extent,@QueryParam("event_date") RestTimestampParam eventDate,
- @QueryParam("reference_date") RestTimestampParam referenceDate,@QueryParam("polarization") String selectedPolarisations,@QueryParam("username") String username,@QueryParam("password") String password) throws Exception {
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Query parameters are: "+ extent+" "+selectedPolarisations+" "+eventDate+" "+referenceDate);
- // System.out.println(username+" "+password);
- final EventOutput eventOutput = new EventOutput();
- ChangeDetectionParams cdp1 = new ChangeDetectionParams(extent, eventDate, referenceDate, selectedPolarisations, username, password);
- try {
- if (EDQ.theList.size()<1000) EDQ.enqueue(cdp1); // submit to the queue
- } catch (Exception e) {
- if(!eventOutput.isClosed())
- eventOutput.close();
- Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,e.getMessage());
- }
- return Response.status(200).entity("OK").build(); }
- private class EventDetectionQueue
- {
- LinkedList<ChangeDetectionParams> theList;
- public synchronized void enqueue(ChangeDetectionParams cdp)
- {
- theList.add(cdp);
- notifyAll();
- }
- public synchronized ChangeDetectionParams fetch() throws InterruptedException // reader thread gets this
- {
- while(theList.isEmpty()) wait();
- return theList.getFirst();
- }
- }
- public class ChangeDetectionParams
- {
- String extent;
- RestTimestampParam eventDate;
- RestTimestampParam referenceDate;
- String selectedPolarisations;
- String username;
- String password;
- public ChangeDetectionParams(String extent, RestTimestampParam eventDate,
- RestTimestampParam referenceDate, String selectedPolarisations, String username, String password) {
- this.extent = extent;
- this.eventDate = eventDate;
- this.referenceDate = referenceDate;
- this.selectedPolarisations = selectedPolarisations;
- this.username = username;
- this.password = password;
- }
- }
- private class ReaderThread implements Runnable
- {
- EventDetectionQueue EDQ;
- ReaderThread(EventDetectionQueue EDQ){ this.EDQ=EDQ;}
- public void run()
- {
- try {
- ChangeDetectionParams cdp = EDQ.fetch();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- // here perform a HTTP-GET on the existing changeDetectionwithProgress service,
- // with the arguments in CDCall
- }
- }
- EventDetectionQueue EDQ = new EventDetectionQueue();
- ReaderThread RT = new ReaderThread(EDQ);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement