This project is an implementation of the server-push mechanism with the use of long-polling technique - designed for Spring Framework.
In order to use this library, client code should do this steps:
- Application controller should inherit from MainController
@RestController
@RequestMapping("/api")
public class AppController extends MainController {
...
}
- You need to create custom class (that implements Resolver), which will be serving as "helper" who determines values of DeferredJSON objects (these are "Promise objects" which represent future result of some operation).
/**
* Resolver that is successfully resolving Promises, when new record has been added to notification table
*/
@Component
public class NewNotificationResolver implements Resolver, Observer {
...
}
- After receiving "long-polling" request there should be created DeferredJSON object, which will represent future result of this request. In the next step - this DeferredJSON object should be appended to tasks queue (by
supervisor.add(result);
)
@RequestMapping(value = "/newNotification", method = RequestMethod.GET)
public @ResponseBody
DeferredJSON deferredResult() {
DeferredJSON result = new DeferredJSON(resolver);
supervisor.add(result);
return result;
}
- First step is to import dependencies
mvn clean install -U
- In next step we can run aplliction by:
mvn exec:java -Dexec.mainClass="pl.edu.agh.kis.Main" --spring.config.location=classpath:/application.properties
wher classpath:/application.properties
means path to apllication's config file
Configuration is located in src/main/resources/application.properties