Ah, the sample assume that you do it inside an Actor, which has the context. 
You need access to a reference to the ActorSystem (system). I'm not sure how 
that is accessed inside a spray endpoint, but in the code you showed it is 
available in the EndPointService.

/Patrik

> 22 jan 2014 kl. 17:52 skrev Amit Mula <amitm...@gmail.com>:
> 
> ok here is code :
> 
> this is a spray http endpoint. the highlighted code is the where I am facing 
> the problem.
> ---------------------------------------------------------------------------------------------------------------------------------------------
> 
> package org.fumigo.endpoint.http
> 
> import scala.concurrent.duration._
> 
> import akka.actor._
> import scala.actor.Actor
> import akka.actor.ActorLogging
> import scala.concurrent.Await
> import akka.pattern._
> import akka.util.Timeout
> import spray.http._
> import spray.http.HttpMethods._
> import spray.http.MediaTypes._
> import spray.httpx.encoding.Deflate
> import spray.routing.HttpService
> import reflect.ClassTag
> 
> import akka.event.Logging;
> import akka.event.LoggingAdapter;
> 
> import akka.contrib.pattern.DistributedPubSubExtension;
> import akka.contrib.pattern.DistributedPubSubMediator;
> 
> class EndPointService extends Actor with EndPoint {
>       val log = Logging(context.system, this)
>       
>       // the HttpService trait defines only one abstract member, which
>       // connects the services environment to the enclosing actor or test
>       def actorRefFactory = context
>       
> 
>       // this actor only runs our route, but you could add
>       // other things here, like request stream processing
>       // or timeout handling
>       def receive = runRoute(serviceRoute)
> }
> 
> trait EndPoint extends HttpService {
>   
>   implicit def executionContext = actorRefFactory.dispatcher
>   implicit val timeout = Timeout(5 seconds)
> 
>   val serviceRoute = {
>       import org.fumigo.security.authz.api.Action
>       import org.fumigo.security.authz.api.Resource
>       import org.fumigo.security.authz.api.Subject
>       import org.fumigo.security.authz.api.AuthZRequest
>       import org.fumigo.security.authz.pep.PEP
>       import org.fumigo.restful.resources.ResourceRequest
>       import DistributedPubSubMediator.Publish
>       
>     
>       val mediator = DistributedPubSubExtension(context.system).mediator
>     //route definition for the URLs starting with '/resource/id/context'
>     get {
>       path("resource" / """\S+""".r / """\S+""".r) { (id, context) =>
>               complete {
>                       val pepActor = actorRefFactory.actorOf(Props[PEP])
>                       val action = new Action("READ")
>                       val resource = new Resource("resource1",id,context)
>                       val subject = new Subject(id,context)
>                       
>                       val authzRequest = new 
> AuthZRequest(subject,resource,action)
>                       val authzResponse = ask(pepActor, authzRequest)
>                       
>                       val resourceRequest = new ResourceRequest(id.toInt)
>                       
>                       // implementing the resource future request here 
>                       val resourceResponse = ask(mediator ! 
> Publish("resource", resourceRequest), timeout);
>                       
>                       for {
>                         a ← authzResponse.mapTo[String]
>                         b ← resourceResponse.mapTo[String]
>                         if a.contains("SUCCESS")
>                       } yield b
>         }
>         }
>       }
>   }
> }
> 
> 
>> On Wednesday, 22 January 2014 22:10:08 UTC+5:30, √ wrote:
>> 
>> 
>> 
>>> On Wed, Jan 22, 2014 at 5:36 PM, Amit Mula <amit...@gmail.com> wrote:
>>> hi Patrik, yes I have switched to scala. I have started learning functional 
>>> programming and scala side by side.
>>> 
>>> For my problem, its more concerned to scala, but not the build script as 
>>> stated by Victor. Regarding the example, I can understand the scala code 
>>> give 
>>> here[http://doc.akka.io/docs/akka/2.2.3/contrib/distributed-pub-sub.html#A_Small_Example_in_Scala]
>>>  what I am not able to understand is how do i initialize the val context 
>>> I am not able to resolve context in this statement : val mediator = 
>>> DistributedPubSubExtension(context.system).mediator
>>> Please let me know how do I initialize it. 
>> 
>> Did you import scala.actors.Actor instead of akka.actor.Actor?
>> 
>> Show us your imports.
>> 
>> Cheers,
>> √
>>  
>>> 
>>> 
>>>> On Wednesday, 22 January 2014 20:00:16 UTC+5:30, Patrik Nordwall wrote:
>>>> Have you switched to Scala?
>>>> Otherwise the java sample code is here: 
>>>> http://doc.akka.io/docs/akka/2.2.3/contrib/distributed-pub-sub.html#A_Small_Example_in_Java
>>>> 
>>>> /Patrik
>>>> 
>>>> 
>>>> 
>>>> 
>>>>> On Wed, Jan 22, 2014 at 3:19 PM, √iktor Ҡlang <viktor...@gmail.com> wrote:
>>>>> Hi Amit,
>>>>> 
>>>>>> On Wed, Jan 22, 2014 at 3:07 PM, Amit Mula <amit...@gmail.com> wrote:
>>>>>> hi guys,
>>>>>> 
>>>>>> I think i am still stuck,
>>>>>> 
>>>>>> A simple actor that publishes to this "content" topic:
>>>>>> 
>>>>>> class Publisher extends Actor {
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>   import DistributedPubSubMediator.Publish
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>   // activate the extension
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>   val mediator = DistributedPubSubExtension(context.system).mediator
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>  
>>>>>>   def receive = {
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>     case in: String ⇒
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>       val out = in.toUpperCase
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>       mediator ! Publish("content", out)
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>   }
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> }
>>>>>> how do i get a reference of context in the above code ?
>>>>>> compiler says : error: not found: value context
>>>>>> I am using maven to build
>>>>> 
>>>>> All our code samples are compiled and tested as a part of the build so 
>>>>> something is wrong is your build definition.
>>>>> 
>>>>> Cheers,
>>>>> √
>>>>>  
>>>>>> -- 
>>>>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>>>>>> --- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Akka User List" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>>> an email to akka-user+...@googlegroups.com.
>>>>>> To post to this group, send email to akka...@googlegroups.com.
>>>>>> 
>>>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Cheers,
>>>>> √
>>>>> 
>>>>> ———————
>>>>> Viktor Klang
>>>>> Chief Architect - Typesafe
>>>>> 
>>>>> Twitter: @viktorklang
>>>>> -- 
>>>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>>>>> --- 
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "Akka User List" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>>> email to akka-user+...@googlegroups.com.
>>>>> To post to this group, send email to akka...@googlegroups.com.
>>>>> 
>>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>> 
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> Patrik Nordwall
>>>> Typesafe -  Reactive apps on the JVM
>>>> Twitter: @patriknw
>>>> 
>>> 
>>> -- 
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>>> --- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "Akka User List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to akka-user+...@googlegroups.com.
>>> To post to this group, send email to akka...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>> 
>> 
>> 
>> -- 
>> Cheers,
>> √
>> 
>> ———————
>> Viktor Klang
>> Chief Architect - Typesafe
>> 
>> Twitter: @viktorklang
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to