How to get the default class loader for an ActorSystem

231 views
Skip to first unread message

John Antypas

unread,
Oct 13, 2012, 11:35:49 PM10/13/12
to akka...@googlegroups.com
Many thanks to those who helped -- I'm getting closer.   I'd like to dynamically load a class to create an Actor.  
For a given actor system, I could use the ActorOf and in the props, get the class.   However, that requires I know the default class loader for  that actor system.
I'd then be able to do something like this pseudo-code

modules : List[String]

foreach (item : modules) {
        Class classz = Class.loadClass(item)  
        ActorRef ref = actorsytem.create(classz)
        ref.tell("start")
}

But the question is, for the newly created ActorSystem, how do I get its default class loader to use it?  Or, is there some method in ActorSystem to load a class by string name rather than class reference?

√iktor Ҡlang

unread,
Oct 14, 2012, 5:50:00 AM10/14/12
to akka...@googlegroups.com
Hi John,

I already consider to have answered this question in your previous thread:

"If you create an extension you get an ExtendedActorSystem, which has a DynamicAccess, which lets you load classes dynamically.

Cheers,
V"

Extensions: http://doc.akka.io/docs/akka/2.0.3/scala/extending-akka.html

"

  1. abstract defdynamicAccessDynamicAccess

    ClassLoader wrapper which is used for reflective accesses internally. This is set to use the context class loader, if one is set, or the class loader which loaded the ActorSystem implementation. The context class loader is also set on all threads created by the ActorSystem, if one was set during 

    creation.

"


Does that help?

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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

John Antypas

unread,
Oct 15, 2012, 11:23:50 PM10/15/12
to akka...@googlegroups.com
Almost, I have created the extension and, in my implementation, I can get ahold of the DynamicAccess reference.   However, I should be able to use that interface to do something like:

dynamicRef.getClassFor(className)

However, the compiler (java 1.5) complains the interface won't allow it.

Roland Kuhn

unread,
Oct 15, 2012, 11:27:59 PM10/15/12
to akka...@googlegroups.com
Hi John,

two things:

- the actual complaint (i.e. full error message) would help
- Java 1.6 is required

Regards,

Roland

--
>>>>>>>>>> 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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 

Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


√iktor Ҡlang

unread,
Oct 16, 2012, 4:36:51 AM10/16/12
to akka...@googlegroups.com
On Tue, Oct 16, 2012 at 5:23 AM, John Antypas <jant...@busygeeks.com> wrote:
Almost, I have created the extension and, in my implementation, I can get ahold of the DynamicAccess reference.   However, I should be able to use that interface to do something like:

dynamicRef.getClassFor(className)

If you click on the link to the DynamicAccess class that I pasted in above, you'll see that the signature of the method getClassFor does NOT look like the one you wrote above.
 

However, the compiler (java 1.5) complains the interface won't allow it.

Akka does not run on Java 1.5 (which has been EOLed for quite some time), this is clearly stated:

Prerequisites

Akka requires that you have Java 1.6 or later installed on you machine.


 
Cheers,



On Saturday, October 13, 2012 8:35:50 PM UTC-7, John Antypas wrote:
Many thanks to those who helped -- I'm getting closer.   I'd like to dynamically load a class to create an Actor.  
For a given actor system, I could use the ActorOf and in the props, get the class.   However, that requires I know the default class loader for  that actor system.
I'd then be able to do something like this pseudo-code

modules : List[String]

foreach (item : modules) {
        Class classz = Class.loadClass(item)  
        ActorRef ref = actorsytem.create(classz)
        ref.tell("start")
}

But the question is, for the newly created ActorSystem, how do I get its default class loader to use it?  Or, is there some method in ActorSystem to load a class by string name rather than class reference?

--
>>>>>>>>>> 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 post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Reply all
Reply to author
Forward
0 new messages