java - GlassFish and Angular long-poll notification service stops responding -



java - GlassFish and Angular long-poll notification service stops responding -

i'm trying write simple way angular application able receive notifications application deployed on glassfish 4 container.

this angularjs service, utilize $http phone call api notification resource, linkedblockingqueue block until there notification return.

angular.module('notification',['config','login']) .factory('notificationservice',function($window,$http,$resource,$q,http_host){ var canceller = $q.defer(); var count = 0; var notify = function(canceller){ $http.get(http_host+'/app/notification', {timeout: canceller.promise}) .success(function(data){ console.log(data); notify(canceller); }) .error(function(data,status,headers,config){ console.log("stopped" + headers + status) if(status > 0){ notify(canceller); } }) }; $window.addeventlistener("unload",function(){ if(count > 0){ console.log("stop") canceller.resolve(); count--; } }) homecoming { start: function(){ console.log("start"); if(count == 0){ canceller = $q.defer(); notify(canceller); count++; } }, stop: function(){ if(count > 0){ console.log("stop") canceller.resolve(); count--; } } } });

in chrome console can verify there ever 1 request api endpoint running, others cancelled on logout , refresh appropriately calling resolve() on deferred object.

the unusual behaviour after short while (around 10 start/stop cycles of notificationservice) api stops responding.

is request thats cancelled using promise cancelled?

glass fish still running, there nil unusual in logs, , visual vm shows no excessive memory usage.

how can investigate more whats going on?

below java resource

@path("notification") @shirosecured public class notificationresource { @inject private notificationservice notificationservice; @context private httpservletrequest request; @get @requiresauthentication public response getnotification() throws interruptedexception, jsonprocessingexception { codobjectmapper mapper = new codobjectmapper(); homecoming response.ok(mapper.writevalueasstring(notificationservice.getnotification(request.getremoteuser()))).build(); } }

and relevant notificationservice getnotification()

@applicationscoped public class notificationservice { private static map<string, linkedblockingqueue<notification>> notificationmap; public notification getnotification(string user) throws interruptedexception { homecoming notificationmap.get(user).take(); } } update:

i think i've got temporary solution using .poll(5,seconds) rather .take() there making connection drop , re-establish every 5 seconds. i'd rather not have , able maintain connection open. seeing works, guess when connection cancelled chrome, isn't beingness noticed cancelled glassfish, , thread still occupied, making me run out of threads handle new connection, thats hunch, way check this?

java javascript angularjs java-ee glassfish-4

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -