[akka-user] Detecting empty source

2016-03-20 Thread Richard Rodseth
I'm doing a flatMapMerge something like this:

val stream = Source(channelMonths)

  .flatMapMerge(10, channelMonth => {

..Sources.intervalsForChannelMonth(channelMonth, ...)

  })

I'm implementing some monitoring using alsoTo to send stream elements to a
monitoring actor which can keep counts and so forth.

How could I detect that the intervals source is sometimes empty? eg. record
the channels for which there are 0 intervals?

-- 
>>  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: Intercept STDOUT of other process

2016-03-20 Thread Eric Pederson
If your Akka program creates the process (for example, using ProcessBuilder), 
then you can capture the output and do whatever you want with it, including 
routing it into an Akka stream.  

If the process is started by some other means then it would be harder - you 
would need to capture the output as part of launching the program and then 
use a shell pipe to send it to the Akka process using something like nc.  
(program 
| nc hostname port).  The Akka process would need to be listening on port 
(eg, using Akka IO).

If the process is already started then you are out of luck unless you have 
the source code and can do something like System.setOut(new PrintStream(is
)).

On Saturday, March 19, 2016 at 10:52:55 AM UTC-4, Konrad Malawski wrote:
>
> That's what bash pipes are for :-)
>
> -- 
> Cheers,
> Konrad 'ktoso’ Malawski
> Akka  @ Lightbend 
> 
>
> On 19 March 2016 at 15:51:10, Arun Sethia (sethi...@gmail.com 
> ) wrote:
>
> Thanks. 
>
> My question is more on STDOUT of any other process, specially if it is non 
> java.
>
> On Saturday, March 19, 2016 at 6:54:51 AM UTC-5, Konrad Malawski wrote: 
>>
>> Hi there,
>>
>> Please don't *immediately* cross post your questions here and stack 
>> overflow 
>> ,
>>  
>> it makes it harder to track answered questions. It's ok to cross post if 
>> after a while you did not receive an answer, but please don't do so 
>> immediately.
>>
>>
>> In order to "intercept" stdout in Java you can setOut on the System object. 
>> It takes a PrintWriter, which we are able to create by wrapping an 
>> OutputStream "bridge" that Akka Streams provide, here's how:
>>
>>  val is: OutputStream = StreamConverters.asOutputStream()
>>.to(Sink.foreach(println)) // your logic pipeline here
>>.run()
>>  System.setOut(new PrintStream(is))
>>
>>
>> -- 
>> Konrad
>> Akka @ Lightbend
>>
>> W dniu sobota, 19 marca 2016 01:29:33 UTC+1 użytkownik Arun Sethia 
>> napisał: 
>>>
>>> Hi, 
>>>
>>> Is it possible to intercept STDOUT of any other process and stream them 
>>> via akka streaming?
>>>
>>> Thanks
>>> Arun
>>>
>> --
> >> 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] Re: Can this be done with the build in stages?

2016-03-20 Thread john . vieten
I came up with this code:

http://pastebin.com/LNTCvebe

But beware  until now I have only be using akka with java. It is my first 
try on using scala!

As a side note : I could not figure out how to match an non-empty list in 
receive?

Many Greetings
John
 


Am Sonntag, 20. März 2016 14:31:51 UTC+1 schrieb john@gmail.com:
>
> val input  = Source(List(List(1, 2, 3), List(1, 2, 3), List(), 
> List(),List(),List(),List(1, 2, 3))
>
>
> 1) Process input. for example input.via(throttleFlow).mapConcat(t => t)
>
> where throttleFlow show do the *following:*
>
>
> 2) If element of source has size > 0 pass it immediately  downstream.
>
> 3) Or if element of source has size == 0 wait 10 secs
>
>
> Can this be done with the build in stages?
>
>
>  

-- 
>>  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: Can this be done with the build in stages?

2016-03-20 Thread john . vieten
Something very simple which come to my mind is  to mapAsync to the ask 
pattern and then do a "schedule of 10 secs" if the element is an empty list.



Am Sonntag, 20. März 2016 14:31:51 UTC+1 schrieb john@gmail.com:
>
> val input  = Source(List(List(1, 2, 3), List(1, 2, 3), List(), 
> List(),List(),List(),List(1, 2, 3))
>
>
> 1) Process input. for example input.via(throttleFlow).mapConcat(t => t)
>
> where throttleFlow show do the *following:*
>
>
> 2) If element of source has size > 0 pass it immediately  downstream.
>
> 3) Or if element of source has size == 0 wait 10 secs
>
>
> Can this be done with the build in stages?
>
>
>  

-- 
>>  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] Can this be done with the build in stages?

2016-03-20 Thread john . vieten


val input  = Source(List(List(1, 2, 3), List(1, 2, 3), List(), 
List(),List(),List(),List(1, 2, 3))


1) Process input. for example input.via(throttleFlow).mapConcat(t => t)

where throttleFlow show do the *following:*


2) If element of source has size > 0 pass it immediately  downstream.

3) Or if element of source has size == 0 wait 10 secs


Can this be done with the build in stages?


  

-- 
>>  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: Reader Writer Lock using Actor Model in Akka

2016-03-20 Thread Rafał Krzewski
Are you sure you are approaching the problem from the best angle? Akka 
gives you a guarantee that the execution of actor code is single threaded, 
so each time a message is processed, the code has an "exclusive lock" on 
the actor's internal state (quotation marks because there is actually no 
lock involved, just smart thread scheduling). 

Does your writer need to exchange several messages with the target actor, 
and the messages from readers should not be processed over the duration of 
that conversation? In such case, you should be able to implement it with 
little effort using become [1] and Stash [2]. For extra style points, you 
can use FSM [3] :) Just watch out for unbounded mailboxes when using Stash! 
Stashing large number of messages may exhaust heap space.

Cheers,
Rafał

[1] http://doc.akka.io/docs/akka/2.4.2/scala/actors.html#Become_Unbecome
[2] http://doc.akka.io/docs/akka/2.4.2/scala/actors.html#Stash
[3] http://doc.akka.io/docs/akka/2.4.2/scala/fsm.html

W dniu czwartek, 17 marca 2016 16:52:47 UTC+1 użytkownik neel choudhury 
napisał:
>
> I want to implement the famous reader writer model using actor model. We 
> can have multiple reader reading but only one writer can write. Also when a 
> writer writes no reader can read and vice versa.
>
> To solve this problem i thought of using a superviser actor which 
> maintains a set for reader actors and a queue for writer actors. Now a 
> writer can be dequeued and start writing when the set for readers are 
> empty. Also when the writer completes all reader actors from the set can 
> start reading.
>
> Can we have a better problem of solving this famous problem using actor 
> model?
>
> Also is this model better than the original reader writer problem soved 
> using read or write locks?
>

-- 
>>  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 game state

2016-03-20 Thread Konrad Malawski
On Sun, Mar 13, 2016 at 7:12 PM, Владимир Морозов 
wrote:

> If two Player's actors live in two different remote actor systems - how
> safely transfer item from one player to other (read transactionally or
> guaranteed)
>
We don't do distributed transactions, they're  the root of all evil in
distributed systems ;-)

Instead you would send the message over, and expect an acknowlagement from
the other player "ok, I received your item",
and if you didn't receive an ACK, you would try to send it again (because
maybe his node was down, right?).

We have utils to help with that, in Akka Persistence it's
AtLeastOnceDelivery






-- 
Cheers,
Konrad 'ktoso' Malawski
Akka  @ Lightbend 

-- 
>>  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-camel alternatives

2016-03-20 Thread Konrad Malawski
Camel is still very good at what it does IMHO.
It's been around for a long time, and perhaps it shows in some aspects, however 
the number of
integrations it provides is really huge, so that's still a great thing about it.

Akka-Camel has not really seen much chances in the last years, but having that 
said and knowing
it's (and camels) architecture, that seems to be mostly because what it does 
suits the majority of
the use cases (translating to/from actor messaging to camel endpoints).

I know of quite a few projects successfully using both still nowadays, so if 
you think the task at hand seems to fit, give it a shot I'd say.

Happy hakking!


-- 
Cheers,
Konrad 'ktoso’ Malawski
Akka @ Lightbend

On 16 March 2016 at 19:04:37, Jay Hutfles (jayhutf...@gmail.com) wrote:

Hi,  

I've just discovered Apache Camel for enterprise integration patterns, and 
Akka's support through akka-camel. At first I was disappointed in myself for 
not knowing about it sooner. But there isn't much discussion around it. I know 
this may be subjective, but is Camel still a best practice solution when 
writing Scala apps which need to tie in with various services? Where are people 
putting their efforts when considering similar problems?  

Thanks in advance, and sorry for such a vague question...  

--  
>> 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: Akka HTTP Websockets Java with Actor

2016-03-20 Thread Konrad Malawski
New Java API is comign in very large steps, I think the new one you'll like
a lot and come back to plain Akka :-)


On Mon, Mar 14, 2016 at 5:13 PM, Guido Medina  wrote:

> Also there are other aspects you should be aware like back-pressure which
> is better handled at Akka, to be fair both teams are awesome (Vert.x and
> Akka)
> But in my case my decision was influenced by the fact that my company has
> 1 man team for the project => me, so I need things to be done faster than
> normal workflow.
> Also I'm streaming many small messages (prices) and they need to get to
> the client fast so speed is an important factor for me.
>
> HTH,
>
> Guido.
>
>
> On Monday, March 14, 2016 at 4:03:41 PM UTC, Guido Medina wrote:
>>
>> Vert.x is just another reactive framework, I found it easier to use than
>> Akka HTTP for Java that's all, and I think (at least today) it is faster.
>> I cannot really recommend you one or the other just state what I know,
>> the decision is still yours.
>> I know Akka team works very hard on improving things so always be open
>> and treat my recommendation as a biased opinion.
>>
>> HTH,
>>
>> Guido.
>>
>> On Monday, March 14, 2016 at 11:50:57 AM UTC, Alan Klikic wrote:
>>>
>>> Hi Guido,
>>>
>>> thank you for the shared info.
>>> We are planing to use Google's Protocol Buffer (
>>> https://developers.google.com/protocol-buffers/) instead of JSON.
>>> You recommend using Vort.x with Netty implementation instead of Akka
>>> HTTP for now?
>>>
>>> Br,
>>> Alan
>>>
>>> Dana srijeda, 9. ožujka 2016. u 11:11:43 UTC+1, korisnik Guido Medina
>>> napisao je:

 *Disclaimer:* The Akka HTTP performance on that page is outdated, now;
 if Akka HTTP is around 75% performance of Play 2, you can guess where it
 would be on that list.

 On Wednesday, March 9, 2016 at 9:58:04 AM UTC, Guido Medina wrote:
>
> Hi Alan,
>
> I hope the Akka/Java example has helped, I will eventually migrate to
> it when Akka HTTP websockets performance gets better compared to Vert.x
> with Netty implementation:
>
>
> https://www.techempower.com/benchmarks/#section=data-r12&hw=peak&test=json
>
> If you notice on my original source code (in case you still need the
> answer), I'm passing the upgraded socket to the actor so it should just be
> a final property of the newly created actor.
> Such socket has a write method, I'll post here again another -and
> working- example with two paths, notice that for each path a different 
> type
> of actor is created and the upgraded socket is part of the actor creator:
>
>
>   vertx.createHttpServer().requestHandler(request -> {
> switch (request.path()) {
>   case "/price": {
> final ServerWebSocket socket = request.upgrade();
> final ActorRef actorRef = context.actorOf(Props.create(new
> PriceWebsocketCreator(TargetSupervisor.this, socket)));
> socket.setWriteQueueMaxSize(1024).
>   handler(event -> actorRef.tell(event, NO_SENDER)).
>   closeHandler(event ->
> actorRef.tell(PoisonPill.getInstance(), NO_SENDER));
> log.info("Price websocket connection from '{}' to '{}'
> established.", socket.remoteAddress(), socket.localAddress());
> break;
>   }
>   case "/ticket": {
> final ServerWebSocket socket = request.upgrade();
> final ActorRef actorRef = context.actorOf(Props.create(new
> TicketWebsocketCreator(TargetSupervisor.this, socket)));
> socket.setWriteQueueMaxSize(1024).
>   handler(event -> actorRef.tell(event, NO_SENDER)).
>   closeHandler(event ->
> actorRef.tell(PoisonPill.getInstance(), NO_SENDER));
> log.info("Ticket websocket connection from '{}' to '{}'
> established.", socket.remoteAddress(), socket.localAddress());
> break;
>   }
>   default:
> request.response().setStatusCode(400).end();
> }
>   }).listen(config.getInt("http.port"),
> config.getString("http.host"));
>
>
> HTH,
>
> Guido.
>
> On Tuesday, March 8, 2016 at 10:03:23 AM UTC, Alan Klikic wrote:
>>
>> Hi Guido,
>>
>> this post helped me allot. Thanks.
>> How can I send message from the Actor to the "connected" websocket?
>> As a response to initial message received from websocket and as a
>> standalone/push message from Actor to websocket?
>>
>> Thank you in advance.
>>
>> Br,
>> Alan
>>
>> Dana srijeda, 24. veljače 2016. u 13:36:17 UTC+1, korisnik Guido
>> Medina napisao je:
>>>
>>> While Akka HTTP is accessible to Java 8 users I decided to go for an
>>> alternative which I was trying to avoid but at least I know is of high
>>> performance and it fits right 

Re: [akka-user] Akka remote communication roadmap?

2016-03-20 Thread Marek Żebrowski
Great news !
>From my experience current remoting ( cluster that depends on it) is way to 
fragile to be used in boxes that are not in the same data center, and in 
such case of co-location UDP is perfectly fine.
I expect that people trying to deploy in any "enterprise" or "coroprate" 
environments might find that as no-go as getting permission for network 
change takes forever, or is impossible.

-- 
>>  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: Restart does not work with my zipper? What am I doing wrong?

2016-03-20 Thread john . vieten
I guess that I am suffering from deadlock? this post semms to apply to my 
problem 
http://blog.lancearlaus.com/akka/streams/scala/2015/05/27/Akka-Streams-Balancing-Buffer/

-- 
>>  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] How-to restart a RunnableGraph on failure?

2016-03-20 Thread john . vieten
This would be the solution I would use:

http://pastebin.com/pJVnHqcH

I am a little unsure about mat.stop() and the Supervision.stop().

Should the code work? I want to restart on every Exception thrown from any 
Flow,Source,Sink of the Runnable graph 

Am Freitag, 18. März 2016 11:28:23 UTC+1 schrieb drewhk:
>
> Hi,
>
> There is no such thing at the moment.
>
> The onComplete on the sink does not guarantee that the whole stream has 
> actually stopped, it only guarantees that the Sink itself was stopped 
> (which may or may not imply completion of the whole stream; think of 
> graphs).
>
> -Endre
>
> On Fri, Mar 18, 2016 at 11:25 AM, > 
> wrote:
>
>> Hi,
>> If a graph throws an Exception in any flow  I want  to restart the graph.
>>
>> Actually I would love to have something like Akka Actors  
>> OneForOneStrategy(10, Duration.create("1 minute"))
>>
>> I couldn't find the right hints in the docs. What I am trying right now 
>> is this pseudo code:
>>
>> Function decider = exc -> 
>> Supervision.stop();
>> Sink sink = ;
>>
>> RunnableGraph> runnableGraph = takeGraph.toMat(sink, 
>> Keep.right());
>>
>> ActorMaterializer mat = 
>> ActorMaterializer.create(ActorMaterializerSettings.create(system).withSupervisionStrategy(decider),
>>  system);
>>
>> runnableGraph.run(mat).onComplete(new OnComplete() {
>>public void onComplete(Throwable failure, Integer value) {
>>   ActorMaterializer mat2 = 
>> ActorMaterializer.create(ActorMaterializerSettings.create(system).withSupervisionStrategy(decider),
>>  system);
>>   runnableGraph.run(mat2);
>>}
>> }, system.dispatcher());
>>
>> Obviously the above code would only restart once...
>> Anyway is this the right direction?
>> Is there an idiomatic way to setup restart of an Runablegraph when a 
>> Exception happens
>>
>> Write now I am thinking of creating a Supervision Actor and use it to init 
>> and restart the Runablegraph
>>
>> Many Greetings
>> John
>>
>>
>>
>> -- 
>> >> 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.