#1425 sys::Service problem.

paul Sat 26 Feb 2011

Here is the test code:

const mixin HelloService : Service {
  Str hello(Str name) { "Hello, $name!" }
}

const class HelloServiceImpl : HelloService {
}

class ServiceTest {

  Bool install := false
  Bool clear := false

  Void main() {
    if (install) {
      HelloService hs := HelloServiceImpl()
      hs.install()
    }
    echo("Services by API:")
    Service.findAll(HelloService#).each {
      echo("$it")
    }
    echo("Services by implementation:")
    Service.findAll(HelloServiceImpl#).each {
      echo("$it")
    }
    echo("All services:")
    Service.list.each {
      echo("$it")
      if (clear) {
        uninstall
      }
    }
    version := Pod.find("sys", false)?.version ?: "undefined"
    echo("Fantom version: $version")
  }
}

To reproduce do:

Step 1) Change install field value to true. And run. Here is my output:

Services by API:
fan.04e28e5aa6ebebc0dc107f0000018c31.HelloServiceImpl@132bfeb
Services by implementation:
fan.04e28e5aa6ebebc0dc107f0000018c31.HelloServiceImpl@132bfeb
All services:
fan.04e28e5aa6ebebc0dc107f0000018c31.HelloServiceImpl@132bfeb
Fantom version: 1.0.57

Step 2) Change install field value to false. And run. Here is another output:

Services by API:
Services by implementation:
All services:
fan.04e28e5aa6ebebc0dc107f0000018c31.HelloServiceImpl@132bfeb
Fantom version: 1.0.57

The problem is that Fantom fails to find services that were installed earlier.

Notice: I used http://www.fanzy.net/ (thanks to kaushik). On fanzy environment stays the same for every script. Don't forget to uninstall all installed services (set clear to true in the test code).

msl Sat 26 Feb 2011

I don't think there's any bug with what you have here. Putting fanzy aside for a second (because it may complicate what's really going on), your sample works fine for me locally:

First run (install == true):

Martins-MacBook-Pro:~ martin$ fan HelloService.fan
Services by API:
fan.HelloService_0.HelloServiceImpl@7f033a6f
Services by implementation:
fan.HelloService_0.HelloServiceImpl@7f033a6f
All services:
fan.HelloService_0.HelloServiceImpl@7f033a6f
Fantom version: 1.0.57

Second run (install == false):

Martins-MacBook-Pro:~ martin$ fan HelloService.fan
Services by API:
Services by implementation:
All services:
Fantom version: 1.0.57

I suspect if you're seeing services listed on fanzy, they've stuck around from other people playing around (perhaps Kaushik can comment further on how things are sandboxed (or not))?

M

kaushik Sat 26 Feb 2011

Well, there are two reasons to this. First, app engine sometimes spins off new jvms per request, sometimes dosen't. So there's a possibility either way of finding the service, and sometimes not.

But a more interesting thing about paul's code is this. In the event that the next request goes to the same JVM, why does

Service.list 

return some value while this doesn't

Service.findAll(HelloService#)

The story is, every time you run a script, fanzy creates a new transient pod to enclose the classes. So first time you run the script, HelloService# is actually pod1::HelloService#, and the next time pod2::HelloService#.

paul Sat 26 Feb 2011

Now it's clear to me. Thanks for the replies.

Login or Signup to reply.