• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Angular JS : Factory connection to continuously listen to my folder structure in file system.

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts,

I have a made a factory connection (Angular JS) to the back-end RESTful service which is responsible for reading files and folder structure in file-system and returns the response and it works fine when the html page is loaded for the first time.
The requirement is that the moment any update happens on the backend folder structure the updated information should be present in html without any page re-loading.

In short, how to make this factory connection to continuously listen to my folder structure in file system.

Kindly suggest how to achieve this.

Regards,
Faraz
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest way is to send a request to the back end periodically inquiring about whether changes have been made to your folder structure. At the back end, you could possibly use the Watch Service API to identify those changes. Here's a link to the tutorial about that: Watching a Directory for Changes.
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Paul,

Thanks so much. I created a watch service and its working like a charm but with one issue.
Its working for the main directory. I need the service to watch for all the changes in the sub folders and sub files are well.

Any clue whats the direct and easy way to achieve this? I don't want to enhance the same code to loop over the sub-folders to achieve this.

Regards,
Faraz
 
Bartender
Posts: 2968
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is basically a design exercise.

  • Design/choose a representation that captures all the necessary information of the file hierarchy
  • Whenever something in the file hierarchy changes regenerate the representation. (And an ETag value - see next.)
  • Serve this representation through the appropriate URI - BUT ensure that not only the GET request is served but also the HEAD request with an ETag header in the response.
  • After the page skeleton has loaded with the page request, issue the first request as a GET. Process the representation and build the relevant page fragment - and "remember" the ETag value for the representation. Then at regular intervals issue a HEAD request.
  • As long as the HEAD request returns an ETag value that is identical to the "remembered" ETag value there is nothing to do.
  • When the HEAD request returns an ETag value that is different to the "remembered" ETag value - issue a GET request for the updated representation, rebuild the page fragment and update the "remembered" ETag.
  • etc.

  • You can also implement this with just the GET request - provided the service is set up that way. The GET request could contain a "If-None-Match" header with the "remembered" ETag value - the service could then respond with 304-"Not Modified" HTTP status when the representation (and therefore the ETag value) hasn't changed.
     
    When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic