[akka-user] Restarting Akka Actor with a new State

2017-08-07 Thread Joe San


I have a scenario where I have to restart a child Actor from within a 
parent actor. The restart should happen with the following rules:

   1. The start should happen only after stop has been completed
   2. Both the stop and start should happen asynchronously

I now have the following scenario:


In my parent Actor, I have a Monix Observable which is pushing events as 
below:


class ParentActor extends Actor {
  ...

override def preStart(): Unit = {
super.preStart()

// Observable to stream events regarding PowerPlant's
val powerPlantEventObservable =
// For every config.database.refreshInterval in seconds
  Observable.interval(config.database.refreshInterval)
// We ask the actor for the latest messages
.map(_ => (dbServiceActor ? 
DBServiceActor.PowerPlantEvents).mapTo[PowerPlantEventsSeq])
.concatMap(Observable.fromFuture(_))
.concatMap(Observable.fromIterable(_))

// Subscriber that pipes the messages to this Actor
cancelable := powerPlantEventObservable.subscribe { update =>
  (self ? update).map(_ => Continue)
}
  }
}


So what happens above is that, I'm asking another Actor called 
DBServiceActor for a List of events and when these events are available, 
I'm piping it to the ParentActor (self ? update). The receive method of the 
ParentActor looks like this and this is where I want to restart my child 
actor . asynchronously:


override def receive: Receive = {

case PowerPlantUpdateEvent(id, powerPlantCfg) =>
  log.info(s"Re-starting PowerPlant actor with id = $id and type 
${powerPlantCfg.powerPlantType}")

  // I want to stop the actor first by finding it from the actor system
  // If it exists, do a context.stop on the Actor instance
  // Once it is stopped, I want to start it again by creating a new 
instance of this Actor
  // Once this new Actor instance is created, I want to signal my Monix 
Observer to send me the next event
  }


Any suggestions?

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] [akka-stream] How to provide flow with 'last seen element' backup?

2017-08-07 Thread Alexey Shuksto
Hi, Johan,

Thanks for your reply, but would not `Sink.last` complete it's Future only 
after Source fully completed? I need to check for last passed value 
in-between:

```
val bh = Source.unfold(0)(v => Some((v+1, 
v))).delay(1.minute).runWith(BroadcastHub.sink)
bh.runWith(Sink.ignore)
```

So, if `bh` would be materialized after 2.5 minutes, it would not only 
observer value `3` after another 30 seconds, but also value `2` just after 
materialization.

понедельник, 7 августа 2017 г., 15:49:06 UTC+3 пользователь Akka Team 
написал:
>
> You can achieve this by using Sink.last which will materialize into a 
> Future[T] that completes with the last element emitted. 
>
> It does however not complete the promise with the last element on 
> failures, this can be remedied by prepending it with a 
> .recoverWithRetries(0,  { case _ => Source.empty }) making sure any 
> upstream failure leads to a completion of the stream.
>
> --
> Johan
> Akka Team
>
> On Sat, Jul 29, 2017 at 8:17 AM, Alexey Shuksto  > wrote:
>
>> Hello hAkkers,
>>
>> In our project we use some number of flows that follow same building 
>> logic:
>> ```
>> val input: Source[T, NotUsed] = ???
>> val output = input.runWith(BroadcastHub.sink)
>>
>> output.runWith(Sink.ignore)
>> ```
>>
>> Sink.ignore here used to prevent BroadcastHub inner buffer overflow and, 
>> also, to dump out old stream elements as they are usually do not matter.
>>
>> But in some rare cases we need to provide to clients of our source 'the 
>> last seen element' -- the last element which passed our flow before client 
>> materialization of BroadcastHub' Source.
>>
>> Currently it is done via some private volatile var:
>>
>> ```
>> @volatile private var last: Option[T] = None
>> _output.runForeach(e => last = Some(e))
>>
>> val output = _output.prepend(Source.lazily(() => last).collect { case 
>> Some(e} => e})
>> ```
>>
>> I wonder maybe there is better way to do so, without mutable state and 
>> stuff?
>>
>> -- 
>> >> Read the docs: http://akka.io/docs/
>> >> Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >> 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 https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka , Jdbc Connectivity

2017-08-07 Thread Kiran Sarma
I want to do programs on akka jdbc using java . can anyone send any links 
or code i am beginner to akka 

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Akka-HTTP: How does backpressure work with Futures and execution contexts?

2017-08-07 Thread Akka Team
Each connection is a stream of Request => Response, having a slow Future
inside that stream will backpressure so the same client cannot push another
request through that connection.

The Akka HTTP server by default limits the number of concurrent connections
to 1024 (you can set it using akka.http.server.max-connections) meaning
that at any given time there can be 1024 Request => Response calls running,
however if those calls are all starting a Future on an execution context
with 4 threads there is only 4 threads available to execute, and 1020
requests would queue up to be executed when a thread is available.

If you want to limit the number of requests to a specific number and fail
additional requests rather than queue them up you can do that with a custom
directive  like this:

https://gist.github.com/johanandren/b87a9ed63b4c3e95432dc0497fd73fdb

--
Johan
Akka Team

On Tue, Aug 1, 2017 at 1:39 PM, Josh F  wrote:

> Hi all,
>
> I am just trying out akka-http and haven't been able to find much
> information about how backpressure works when we use futures and run
> operations async.
>
> For example, if I create a REST API with a route that looks like this:
> ```
> val route =
>   (path("users") & post & entity(as[NewUser])) { user =>
> complete(createNewUser(user))
>   }
> ```
> where the method `createNewUser(user)` spawns an async operation which
> interacts with a database and returns a Future[User].
>
> Say the database slows down and there is a backlog of pending requests,
> does akka-http recognize that the futures are taking a long time to
> complete, and then slow down the number of calls to createNewUser?
>
> Also how does the execution context used to execute the futures affect the
> backpressure? For example, if my database operations take place on an
> execution context which only supports 4 concurrent operations, will
> akka-http ensure that there are at most 4 pending futures/calls to
> createNewUser at any time?
>
> Thanks for any insights on this!
>
> Josh
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Re: How to deal with Future in a customized Sink?

2017-08-07 Thread Akka Team
Using the async is how it should be done, you should never use Await or
call the internal methods of the GraphStageLogic from another thread as you
do in your sample code.

Create the async callback in the onPush method though, not inside the
future onComplete callback. You can let the callback accept a
Try[YourThing] and do the pattern matching on the success/failure there and
then just use pass the invoke method as parameter to Future.onComplete.

--
Johan
Akka Team

On Sun, Aug 6, 2017 at 12:34 AM, Gary Struthers 
wrote:

> GraphStageLogic has getAsyncCallback. You define its handler method which
> returns an AsyncCallback. Then call AsyncCallback.invoke This is needed
> to re-enter the GraphStage whenever you return a Future in a custom stage.
>
>
> scalaRSF.onComplete {
>
>   case Success(rs) => {
>
> val successCallback = getAsyncCallback{
>
>   (_: Unit) => {
>
> if(mustFinish) completeStage() else pull(in)
>
> waitForHandler = false
>
>   }
>
> }
>
> successCallback.invoke(rs)
>
>   }
>
> Gary Struthers
>
> https://garyaiki.github.io/dendrites/
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] [akka-stream] How to provide flow with 'last seen element' backup?

2017-08-07 Thread Akka Team
You can achieve this by using Sink.last which will materialize into a
Future[T] that completes with the last element emitted.

It does however not complete the promise with the last element on failures,
this can be remedied by prepending it with a .recoverWithRetries(0,  { case
_ => Source.empty }) making sure any upstream failure leads to a completion
of the stream.

--
Johan
Akka Team

On Sat, Jul 29, 2017 at 8:17 AM, Alexey Shuksto  wrote:

> Hello hAkkers,
>
> In our project we use some number of flows that follow same building logic:
> ```
> val input: Source[T, NotUsed] = ???
> val output = input.runWith(BroadcastHub.sink)
>
> output.runWith(Sink.ignore)
> ```
>
> Sink.ignore here used to prevent BroadcastHub inner buffer overflow and,
> also, to dump out old stream elements as they are usually do not matter.
>
> But in some rare cases we need to provide to clients of our source 'the
> last seen element' -- the last element which passed our flow before client
> materialization of BroadcastHub' Source.
>
> Currently it is done via some private volatile var:
>
> ```
> @volatile private var last: Option[T] = None
> _output.runForeach(e => last = Some(e))
>
> val output = _output.prepend(Source.lazily(() => last).collect { case
> Some(e} => e})
> ```
>
> I wonder maybe there is better way to do so, without mutable state and
> stuff?
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka Stream Messaging Server Poc

2017-08-07 Thread G J


 I'm getting termination message just after sucuss message when my neety client 
connected. I'm new in akka stream. Please help me what i'm missing in my poc. 


import java.net.InetSocketAddress;
import java.util.concurrent.CompletionStage;

import akka.Done;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Tcp;

/**
 * Created by gaurav on 28/7/17.
 */
public class Server {
   public static void main(String[] args) {
  InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 
6000);
  final Sink handler = 
Sink.foreach(conn -> {
 System.out.println("Client connected from: " + conn.remoteAddress());
 conn.handleWith(ActorFlow.actorRef(out -> 
MyWebSocketActor.props(out)), InternalWebSocketHelper.actorMaterializer());
  });
  final CompletionStage bindingFuture = 
Tcp.get(InternalWebSocketHelper.actorSystem())
.bind(serverAddress.getHostString(), 
serverAddress.getPort()).to(handler).run(InternalWebSocketHelper.actorMaterializer());

  bindingFuture.whenComplete((binding, throwable) -> {
 System.out.println("Server started, listening on: " + 
binding.localAddress());
  });

  bindingFuture.exceptionally(e -> {
 System.err.println("Server could not bind to " + serverAddress + " : " 
+ e.getMessage());
 InternalWebSocketHelper.actorSystem().terminate();
 return null;
  });

   }

   private static class MyWebSocketActor extends UntypedActor {

  private final ActorRef out;

  public MyWebSocketActor(ActorRef out) {
 this.out = out;
  }

  public static Props props(ActorRef out) {
 return Props.create(MyWebSocketActor.class, () -> new 
MyWebSocketActor(out));
  }

  public void onReceive(Object message) throws Exception {
 out.tell(message, ActorRef.noSender());
  }
   }
}





/**
 * Created by gaurav on 1/8/17.
 */

import java.util.function.Function;

import org.reactivestreams.Publisher;

import akka.NotUsed;
import akka.actor.*;
import akka.japi.Pair;
import akka.stream.Materializer;
import akka.stream.OverflowStrategy;
import akka.stream.javadsl.*;

public class ActorFlow {

   public static  Flow actorRef(Function props) {
  return actorRef(props, 1000, OverflowStrategy.dropNew(), 
InternalWebSocketHelper.actorSystem(), 
InternalWebSocketHelper.actorMaterializer());
   }

   public static  Flow actorRef(Function props, int bufferSize, OverflowStrategy overflowStrategy,
 ActorRefFactory factory, Materializer mat) {

  Pair pair = Source. actorRef(bufferSize, 
overflowStrategy)
.toMat(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), 
Keep.both()).run(mat);

  return Flow.fromSinkAndSource(

Sink.actorRef(factory.actorOf(Props.create(WebSocketFlowActor.class, () -> new 
WebSocketFlowActor(props, pair.first(,
  new Status.Success(new Object())),
Source.fromPublisher(pair.second()));
   }

   private static class WebSocketFlowActor extends UntypedActor {

  private final ActorRef flowActor;

  public WebSocketFlowActor(Function props, ActorRef ref) {
 flowActor = context().watch(context().actorOf(props.apply(ref), 
"flowActor"));
  }

  @Override
  public void onReceive(Object message) throws Throwable {
 if (message instanceof Status.Success) {
flowActor.tell(PoisonPill.getInstance(), getSelf());
 } else if (message instanceof Terminated) {
context().stop(getSelf());
 } else {
flowActor.tell(message, getSelf());
 }
  }

  @Override
  public SupervisorStrategy supervisorStrategy() {
 return SupervisorStrategy.stoppingStrategy();
  }
   }
}




import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;

public class InternalWebSocketHelper {

   static ActorSystem actorSystem = ActorSystem.create();
   static ActorMaterializer actorMaterializer = 
ActorMaterializer.create(actorSystem);

   static ActorSystem actorSystem() {
  return actorSystem;
   }

   static ActorMaterializer actorMaterializer() {
  return actorMaterializer;
   }
}

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 

Re: [akka-user] Does Akka directive "fileUpload" copies the entire input entity file into memory?

2017-08-07 Thread Akka Team
Hi,

You are putting the entire file into memory by running

byteSource.runFold(ByteString.empty) { case (acc, i) => acc ++ i
}.map(s => s.utf8String)


This means the body is first completely read into memory as a ByteString
and then transformed into a String.

To stream the byte chunks directly to a file you would do something like
this:

val futureWriteResult: Future[IOResult] =
byteSource.runWith(FileIO.toPath(uploadFile))

--
Johan
Akka Team


On Fri, Aug 4, 2017 at 7:01 AM,  wrote:

> Does Akka directive "fileUpload" copies the entire input entity file into
> memory? Is there a way to do multipart upload of large file as 1 GB without
> consuming 1 GB of memory?
>
> My below code to upload 300MB is consuming 300MB of memory. Is this
> expected behavior with "fileUpload" directive?
>
>
> curl -k -i -X PUT --header --form "csv=@myfile300MB.txt"
> https://abc/uploadContent
>
> val uploadFile = File.createTempFile("uploadFile", ".txt")
> extractRequestContext { ctx =>
> implicit val materializer = ctx.materializer
> implicit val ec = ctx.executionContext
> fileUpload("csv") {
>   case (metadata, byteSource) =>
> val sumF = byteSource.runFold(ByteString.empty) { case (acc, i) => 
> acc ++ i }.map(s => s.utf8String)
>
> onSuccess(sumF) { sum =>
>   Files.write(Paths.get(uploadFile.getAbsolutePath), 
> sum.toString.getBytes)
>   logger.info(StatusCodes.OK + "Successfully completed fileUpload ")
>   complete(s"Successfully completed fileUpload") }}
> }
>
> Thanks *johanandren  *for your below response:
>
> Hi @mahadev-khapali , we use the
> issue tracker for bugs and feature requests, please use the mailing list
> https://groups.google.com/forum/#!forum/akka-user or the gitter chat
> https://gitter.im/akka/akka for questions like this, thanks!
>
> (And yes, if you use fold like that you are collecting the entire upload
> into memory, you should instead stream it directly to a file sink if you
> want to avoid that)
>
>
> Can you somebody suggest how do I directly stream to a file sink so that I
> dont upload into memroy?
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka Stream Tcp Messaging Server POC

2017-08-07 Thread G J
I'm new Akka stream, I have to build on poc on Akka stream for instant 
messaging. So I need a help to understand what I'm missing here.


import java.net.InetSocketAddress;
import java.util.concurrent.CompletionStage;

import akka.Done;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Tcp;

/**
 * Created by gaurav on 28/7/17.
 */
public class Server {
   public static void main(String[] args) {
  InetSocketAddress serverAddress = new InetSocketAddress("127.0.0.1", 
6000);
  final Sink handler = 
Sink.foreach(conn -> {
 System.out.println("Client connected from: " + conn.remoteAddress());
 conn.handleWith(ActorFlow.actorRef(out -> 
MyWebSocketActor.props(out)), InternalWebSocketHelper.actorMaterializer());
  });
  final CompletionStage bindingFuture = 
Tcp.get(InternalWebSocketHelper.actorSystem())
.bind(serverAddress.getHostString(), 
serverAddress.getPort()).to(handler).run(InternalWebSocketHelper.actorMaterializer());

  bindingFuture.whenComplete((binding, throwable) -> {
 System.out.println("Server started, listening on: " + 
binding.localAddress());
  });

  bindingFuture.exceptionally(e -> {
 System.err.println("Server could not bind to " + serverAddress + " : " 
+ e.getMessage());
 InternalWebSocketHelper.actorSystem().terminate();
 return null;
  });

   }

   private static class MyWebSocketActor extends UntypedActor {

  private final ActorRef out;

  public MyWebSocketActor(ActorRef out) {
 this.out = out;
  }

  public static Props props(ActorRef out) {
 return Props.create(MyWebSocketActor.class, () -> new 
MyWebSocketActor(out));
  }

  public void onReceive(Object message) throws Exception {
 out.tell(message, ActorRef.noSender());
  }
   }
}








/**
 * Created by gaurav on 1/8/17.
 */

import java.util.function.Function;

import org.reactivestreams.Publisher;

import akka.NotUsed;
import akka.actor.*;
import akka.japi.Pair;
import akka.stream.Materializer;
import akka.stream.OverflowStrategy;
import akka.stream.javadsl.*;

public class ActorFlow {

   public static  Flow actorRef(Function props) {
  return actorRef(props, 1000, OverflowStrategy.dropNew(), 
InternalWebSocketHelper.actorSystem(), 
InternalWebSocketHelper.actorMaterializer());
   }

   public static  Flow actorRef(Function props, int bufferSize, OverflowStrategy overflowStrategy,
 ActorRefFactory factory, Materializer mat) {

  Pair pair = Source. actorRef(bufferSize, 
overflowStrategy)
.toMat(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), 
Keep.both()).run(mat);

  return Flow.fromSinkAndSource(

Sink.actorRef(factory.actorOf(Props.create(WebSocketFlowActor.class, () -> new 
WebSocketFlowActor(props, pair.first(,
  new Status.Success(new Object())),
Source.fromPublisher(pair.second()));
   }

   private static class WebSocketFlowActor extends UntypedActor {

  private final ActorRef flowActor;

  public WebSocketFlowActor(Function props, ActorRef ref) {
 flowActor = context().watch(context().actorOf(props.apply(ref), 
"flowActor"));
  }

  @Override
  public void onReceive(Object message) throws Throwable {
 if (message instanceof Status.Success) {
flowActor.tell(PoisonPill.getInstance(), getSelf());
 } else if (message instanceof Terminated) {
context().stop(getSelf());
 } else {
flowActor.tell(message, getSelf());
 }
  }

  @Override
  public SupervisorStrategy supervisorStrategy() {
 return SupervisorStrategy.stoppingStrategy();
  }
   }
}






import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;

public class InternalWebSocketHelper {

   static ActorSystem actorSystem = ActorSystem.create();
   static ActorMaterializer actorMaterializer = 
ActorMaterializer.create(actorSystem);

   static ActorSystem actorSystem() {
  return actorSystem;
   }

   static ActorMaterializer actorMaterializer() {
  return actorMaterializer;
   }
}

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 

Re: [akka-user] Akka event bus with typed actor Ask Question

2017-08-07 Thread Patrik Nordwall
I don't think that is implemented yet. See
https://github.com/akka/akka/issues/21219
Adapters  might be a
possible workaround.

/Patrik

On Fri, Aug 4, 2017 at 10:05 AM, Politrons  wrote:

> I´m looking in google without success. Anybody knows if it´s possible use
> Akka Event bus to subscribe and send events to typed actors?.
>
> And if you wonder, yes typed actors are mandatory :(
>
> Regards.
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> 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 https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Patrik Nordwall
Akka Tech Lead
Lightbend  -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Re: [Akka-typed] Mutable Behavior testing with EffectfulActorContext

2017-08-07 Thread Nishant Vishwakarma
Hi Konrad,

Thanks for the reply. Meanwhile I am trying to use StubbedActorContext to 
achieve the desired results. I am not getting a stackoverflow error and I 
am successfully getting number of children and their inboxes. However there 
are no messages. One of the child actor sends itself a message to 
initialize which in turn should reply the supervisor. I am not getting any 
messages on the selfInbox or the respective childInbox. I have the test 
available as a gist here 

I will be grateful if you could help.

Thanks and Regards,
Nishant

On Sunday, August 6, 2017 at 8:22:07 PM UTC+5:30, Nishant Vishwakarma wrote:
>
> Hi,
>
> I am trying to test a mutable behavior which spawns a child actor. I am 
> trying to use *EffectfulActorContext* for testing various effects and to 
> avail the child inboxes for testing interaction with the spawned child 
> actor.
>
> However I am getting a StackOverflow where the child actor is spawned.
>
> An exception or error caused a run to abort. 
> java.lang.StackOverflowError
>  at akka.typed.internal.ActorContextImpl.spawnAnonymous(ActorContextImpl.
> scala:51)
>  at akka.typed.internal.ActorContextImpl.spawnAnonymous$(ActorContextImpl.
> scala:50)
>  at akka.typed.testkit.EffectfulActorContext.spawnAnonymous(Effects.scala:
> 81)
>
> I do not get such exception if I use *StubbedActorContext*. However in 
> doing so I loose the testing features of effects.
> I have created a gist of some sample code resembling my original code here 
> .
>
> It will be great if someone could help me with it.
>
> Thanks and Regards,
> Nishant
>
>
>
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.