Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. @GET
  2. @Path("/progressAfterED")
  3. @Produces(SseFeature.SERVER_SENT_EVENTS)
  4. public Response changeDetectionwithProgressAfterED(@QueryParam("extent") String extent,@QueryParam("event_date") RestTimestampParam eventDate,
  5. @QueryParam("reference_date") RestTimestampParam referenceDate,@QueryParam("polarization") String selectedPolarisations,@QueryParam("username") String username,@QueryParam("password") String password) throws Exception {
  6. Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Query parameters are: "+ extent+" "+selectedPolarisations+" "+eventDate+" "+referenceDate);
  7. // System.out.println(username+" "+password);
  8. final EventOutput eventOutput = new EventOutput();
  9.  
  10. ChangeDetectionParams cdp1 = new ChangeDetectionParams(extent, eventDate, referenceDate, selectedPolarisations, username, password);
  11. try {
  12. if (EDQ.theList.size()<1000) EDQ.enqueue(cdp1); // submit to the queue
  13. } catch (Exception e) {
  14. if(!eventOutput.isClosed())
  15. eventOutput.close();
  16. Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,e.getMessage());
  17. }
  18. return Response.status(200).entity("OK").build(); }
  19.  
  20. private class EventDetectionQueue
  21. {
  22. LinkedList<ChangeDetectionParams> theList;
  23.  
  24. public synchronized void enqueue(ChangeDetectionParams cdp)
  25. {
  26. theList.add(cdp);
  27. notifyAll();
  28. }
  29. public synchronized ChangeDetectionParams fetch() throws InterruptedException // reader thread gets this
  30. {
  31. while(theList.isEmpty()) wait();
  32. return theList.getFirst();
  33. }
  34. }
  35. public class ChangeDetectionParams
  36. {
  37. String extent;
  38. RestTimestampParam eventDate;
  39. RestTimestampParam referenceDate;
  40. String selectedPolarisations;
  41. String username;
  42. String password;
  43.  
  44. public ChangeDetectionParams(String extent, RestTimestampParam eventDate,
  45. RestTimestampParam referenceDate, String selectedPolarisations, String username, String password) {
  46. this.extent = extent;
  47. this.eventDate = eventDate;
  48. this.referenceDate = referenceDate;
  49. this.selectedPolarisations = selectedPolarisations;
  50. this.username = username;
  51. this.password = password;
  52. }
  53.  
  54. }
  55.  
  56. private class ReaderThread implements Runnable
  57. {
  58. EventDetectionQueue EDQ;
  59. ReaderThread(EventDetectionQueue EDQ){ this.EDQ=EDQ;}
  60. public void run()
  61. {
  62. try {
  63. ChangeDetectionParams cdp = EDQ.fetch();
  64. } catch (InterruptedException e) {
  65. // TODO Auto-generated catch block
  66. e.printStackTrace();
  67. }
  68.  
  69.  
  70. // here perform a HTTP-GET on the existing changeDetectionwithProgress service,
  71. // with the arguments in CDCall
  72. }
  73. }
  74.  
  75. EventDetectionQueue EDQ = new EventDetectionQueue();
  76. ReaderThread RT = new ReaderThread(EDQ);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement