GAE JCache NumberFormatException, will I need to write Java to avoid?

Posted by Jasper on Stack Overflow See other posts from Stack Overflow or by Jasper
Published on 2010-04-18T11:42:01Z Indexed on 2010/04/18 11:43 UTC
Read the original article Hit count: 151

This code below produces a NumberFormatException in this line:

val cache = cf.createCache(Collections.emptyMap())

Do you see any errors?
Will I need to write a Java version to avoid this, or is there a Scala way?

...
import java.util.Collections
import net.sf.jsr107cache._

object QueryGenerator extends ServerResource {
  private val log = Logger.getLogger(classOf[QueryGenerator].getName)
}

class QueryGenerator extends ServerResource {
  def getCounter(cache:Cache):long = {
      if (cache.containsKey("counter")) {
        cache.get("counter").asInstanceOf[long]
      } else {
        0l
      }
    }

  @Get("html")
  def getHtml(): Representation = {
    val cf = CacheManager.getInstance().getCacheFactory()
    val cache = cf.createCache(Collections.emptyMap())

    val counter = getCounter(cache)

    cache.put("counter", counter + 1)

    val q = QueueFactory.getQueue("query-generator")
    q.add(TaskOptions.Builder.url("/tasks/query-generator").method(Method.GET).countdownMillis(1000L))

    QueryGenerator.log.warning(counter.toString)

    new StringRepresentation("QueryGenerator started!", MediaType.TEXT_HTML)
  }
}

Thanks!

© Stack Overflow or respective owner

Related posts about scala

Related posts about java