Brian Paulita | 1 Aug 13:50 2007
Picon
Picon

Re: Remote Actors


Thanks for your reply.

For my current research, I'm trying to allow get dynamically generated
actors to receive messages from the network. I was trying to achieve this by
using message passing rather than some sort of external gateway/actor name
server but it seems that I have little choice in the matter.

In addition, I have my eye on researching migrating actors and was wondering
if SCALA could handle such matters. Initially, I thought that simply sending
an object, wrapping it, and then registering it on some remote node would
work, but it doesn't look like the case.

I'll do some more work on this, thanks for your help.

Itay wrote:
> 
> Brian,
> 
> What are you trying to achieve? It seems to me that you either want to be
> able to migrate actors across the network, which is not possible with the
> current framework of actors (as far as I can see) unless you add a lot of
> your own machinery, or that you are trying to be able to communicate
> within your network about how to reach various actors.
> 
> If it is the second one, my suggestion would be to have a known actor name
> server (i.e. ANS), that has a known address and port (i.e. location), and
> which you would send a request, say:
> 
> ANS ! ActorLocation(someActorsName);
(Continue reading)

Itay | 1 Aug 20:43 2007
Picon

Re: Remote Actors


My responses are inline.

Brian Paulita wrote:
> 
> Thanks for your reply.
> 
> For my current research, I'm trying to allow get dynamically generated
> actors to receive messages from the network. I was trying to achieve this
> by using message passing rather than some sort of external gateway/actor
> name server but it seems that I have little choice in the matter.
> 

I still think you can achieve this. As far as I understand from what you say
(which, admittedly, is probably the wrong thing to understand), you could do
something like this:

We have an actor A, which sits on a client C, and wants to communicate with
server S. S has a default actor message receiver, which takes messages of
the form NewActor(name, port). As such, A would send a message to S (like S
! NewActor(actorName, portNum)), wait for the reply that it was created, and
then it can start sending messages to the new actor on S. This way you can
dynamically generate actors to receive messages, without having a central
server. You just have to have some capacity for creating the actors in the
first place (which in your example you have to, as you can send the handle
of the actor somewhere).

Even moreso, given your original example, if A and B already exist, but do
not know of each other, you just need to define a message type like
ActorDiscover(name, port), which A would send to the server, and the server
(Continue reading)

Brian Paulita | 2 Aug 02:30 2007
Picon
Picon

Re: Remote Actors


Thank you once again. I'll mull over your advice.

--

-- 
View this message in context: http://www.nabble.com/Remote-Actors-tf4163753.html#a11956420
Sent from the Scala - Lounge mailing list archive at Nabble.com.

fakechris | 2 Aug 12:31 2007
Picon

How to apply for comprehension on java.util.List?


Here is the senario

// callJavaMethod is defined in java
// function List callJavaMethod(), and return List<String>
var list = callJavaMethod();

1. how to convert List to List[String] in scala?
2. how to iterate List elements through for comprehension? 
3. how to convert Java.util.List into scala List and vice versa?

--

-- 
View this message in context: http://www.nabble.com/How-to-apply-for-comprehension-on-java.util.List--tf4205332.html#a11962045
Sent from the Scala - Lounge mailing list archive at Nabble.com.

Stepan Koltsov | 2 Aug 13:12 2007
Picon

Re: How to apply for comprehension on java.util.List?

1, 3. Use scala.collection.jcl.

===
val x: java.util.List = new java.util.ArrayList
x.add("a")
x.add("b")

val y = new scala.collection.jcl.BufferWrapper[String] {
    override def underlying = x
}

println(y.toList)
===

===
val z = List(1, 2, 3)

val w = new scala.collection.jcl.ArrayList[Int]
w addAll z

println(w)
===

2. for (x <- list) ...

On 8/2/07, fakechris <chris__song@...> wrote:
> Here is the senario
>
> // callJavaMethod is defined in java
> // function List callJavaMethod(), and return List<String>
(Continue reading)

fakechris | 2 Aug 15:44 2007
Picon

Re: How to apply for comprehension on java.util.List?


Thanks for your code.

However, when I compile my code got errors:

compile:
   [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
   [scalac]
E:\workspace\psycoimport\src\org\haibao\app\ImportPsycoTest.scala:32
: error: error overriding method underlying in trait CollectionWrapper of
type =
> java.util.Collection;
   [scalac]  method underlying has incompatible type => java.util.List
   [scalac]       override def underlying = tests
   [scalac]                ^
   [scalac] one error found

My project is a simple hibernate JPA test, here is part  of the code.

val emf = Persistence.createEntityManagerFactory("helloworld")
val em = emf.createEntityManager()
var tests = em.createQuery(
        "from PsycotestPsycotest"
        ).getResultList();

val testsList = new scala.collection.jcl.BufferWrapper[PsycotestPsycotest] {
      override def underlying = tests 
}
println(testsList.toList)

(Continue reading)

Stepan Koltsov | 2 Aug 15:56 2007
Picon

Re: How to apply for comprehension on java.util.List?

What is your scala -version ?

I have

Scala code runner version 2.6.0-RC1 -- (c) 2002-2007 LAMP/EPFL

Did my code work in your environment?

Also, try to specify type of

val tests: java.util.List = ...

--

-- 
Stepan

On 8/2/07, fakechris <chris__song@...> wrote:
>
> Thanks for your code.
>
> However, when I compile my code got errors:
>
> compile:
>    [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
>    [scalac]
> E:\workspace\psycoimport\src\org\haibao\app\ImportPsycoTest.scala:32
> : error: error overriding method underlying in trait CollectionWrapper of
> type =
> > java.util.Collection;
>    [scalac]  method underlying has incompatible type => java.util.List
>    [scalac]       override def underlying = tests
(Continue reading)

fakechris | 2 Aug 16:11 2007
Picon

Re: How to apply for comprehension on java.util.List?


my Scala version 2.5.1-final

Your code is worked in interpret enviorment.

val tests: java.util.List = ... still got error( I compile code with
Xgenerics option ?)

compile:
   [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
   [scalac]
E:\workspace\psycoimport\src\org\haibao\app\ImportPsycoTest.scala:27
: error: trait List takes type parameters
   [scalac]     var tests: java.util.List = em.createQuery(
   [scalac]                         ^
   [scalac] one error found

val tests: java.util.List[PsycotestPsycotest] = ... also produce error code

compile:
   [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
   [scalac]
E:\workspace\psycoimport\src\org\haibao\app\ImportPsycoTest.scala:29
: error: type mismatch;
   [scalac]  found   : java.util.List[E]
   [scalac]  required: java.util.List[org.haibao.app.PsycotestPsycotest]
   [scalac]         ).getResultList();
   [scalac]                        ^
   [scalac] one error found

(Continue reading)

Stepan Koltsov | 2 Aug 16:19 2007
Picon

Re: How to apply for comprehension on java.util.List?

Try to compile without -Xgenerics?

Seems like scala.collection.jcl is compiled without -Xgenerics at least in 2.5.

-- 
Stepan

On 8/2/07, fakechris <chris__song@...> wrote:
> my Scala version 2.5.1-final
>
> Your code is worked in interpret enviorment.
>
> val tests: java.util.List = ... still got error( I compile code with
> Xgenerics option ?)
>
> compile:
>    [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
>    [scalac]
> E:\workspace\psycoimport\src\org\haibao\app\ImportPsycoTest.scala:27
> : error: trait List takes type parameters
>    [scalac]     var tests: java.util.List = em.createQuery(
>
>    [scalac]                         ^
>    [scalac] one error found
>
> val tests: java.util.List[PsycotestPsycotest] = ... also produce error code
>
> compile:
>    [scalac] Compiling 1 source file to E:\workspace\psycoimport\build
>    [scalac]
(Continue reading)

fakechris | 2 Aug 16:47 2007
Picon

Re: How to apply for comprehension on java.util.List?


After -Xgenerics switch removed, the code works ;-) 

What does "-Xgenerics" mean and when should I add this switch?

Stepan Koltsov-2 wrote:
> 
> Try to compile without -Xgenerics?
> 
> Seems like scala.collection.jcl is compiled without -Xgenerics at least in
> 2.5.
> 
> -- 
> Stepan
> 
> 

--

-- 
View this message in context: http://www.nabble.com/How-to-apply-for-comprehension-on-java.util.List--tf4205332.html#a11965945
Sent from the Scala - Lounge mailing list archive at Nabble.com.


Gmane