Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:54:28+00:00 2026-06-04T12:54:28+00:00

I’m implementing long polling in Play 2.0 in potentially a distributed environment. The way

  • 0

I’m implementing long polling in Play 2.0 in potentially a distributed environment. The way I understand it is that when Play gets a request, it should suspend pending notification of an update then go to the db to fetch new data and repeat. I started looking at the chat example that Play 2.0 offers but it’s in websocket. Furthermore it doesn’t look like it’s capable of being distributed. So I thought I will use Akka’s event bus. I took the eventstream implementation and replicated my own with LookupClassification. However I’m stumped as to how I’m gonna get a message back (or for that matter, what should be the subscriber instead of ActorRef)?

EventStream implementation:
https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/event/EventStream.scala

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:54:29+00:00Added an answer on June 4, 2026 at 12:54 pm

    I am not sure that is what you are looking for, but there is quite a simple solution in the comet-clock sample, that you can adapt to use AKKA actors. It uses an infinite iframe instead of long polling. I have used an adapted version for a more complex application doing multiple DB calls and long computation in AKKA actors and it works fine.

      def enum = Action {
        //get your actor
        val myActorRef = Akka.system.actorOf(Props[TestActor]) 
    
       //do some query to your DB here. Promise.timeout is to simulate a blocking call
       def getDatabaseItem(id: Int): Promise[String] = { Promise.timeout("test", 10 milliseconds) } 
    
        //test iterator, you will want something smarter here
        val items1 = 1 to 10 toIterator
    
        // this is a very simple enumerator that takes ints from an existing iterator (for an http request parameters for instance) and do some computations
        def myEnum(it: Iterator[Int]): Enumerator[String] = Enumerator.fromCallback[String] { () =>
          if (!items1.hasNext)
            Promise.pure[Option[String]](None) //we are done with our computations
          else {
    
            // get the next int, query the database and compose the promise with a further query to the AKKA actor
            getDatabaseItem(items1.next).flatMap { dbValue =>
              implicit val timeout = new Timeout(10 milliseconds)
              val future = (myActorRef ? dbValue) mapTo manifest[String]
    
              // here we convert the AKKA actor to the right Promise[Option] output
              future.map(v => Some(v)).asPromise
            }
          }
        }
    
        // finally we stream the result to the infinite iframe. 
        // console.log is the javascript callback, you will want something more interesting.
        Ok.stream(myEnum(items1) &> Comet(callback = "console.log"))
      }
    

    Note that this fromCallback doesn’t allow you to combine enumerators with “andThen”, there is in the trunk version of play2 a generateM method that might be more appropriate if you want to use combinations.

    It’s not long polling, but it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.