adequate
adequate
adequate
adequate
 

JPPF
 Home   About   Download   Documentation   Forums 
May 25, 2013, 09:34:46 AM *
Welcome,
Please login or register.

Login with username, password and session length
Advanced search  
News: Registered users, your contribution is requested! Please participate in our JDK support poll
New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: non class files with classloader?  (Read 848 times)

ernst

  • JPPF Padawan
  • *
  • Posts: 14
non class files with classloader?
« on: April 30, 2012, 03:54:35 PM »

i want to port a simulation/optimization platform to jppf. this simulation platform uses some "klasses", some annotation for objects and classes to allow multiple inheritance in java. these "klasses" are load by the platform in the same way like classes with the java class loader. is it possible (after reading the user guide i think so) to load this files via the jppf classloader to the node?
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 1436
    • JPPF Web site
Re: non class files with classloader?
« Reply #1 on: May 01, 2012, 10:19:25 AM »

Hello,

I am not sure what you mean exactly. Is there a way you could provide more details on what you want to achieve?
Do you have pointers to online information, or code samples you can share to help us understand?

Thanks,
-Laurent
Logged

ernst

  • JPPF Padawan
  • *
  • Posts: 14
Re: non class files with classloader?
« Reply #2 on: May 02, 2012, 10:08:33 AM »

ok so let me explain this a little bit more:
i have a klass file, this describes a class oder object:

klass Fork storedin ModelNode
{
   properties
   {
      final logic extends de.d3fact.mfslib.fork.Fork : (),   
   }
}

this is a small textfile placed in the classpath. to eaccess this klass in my model (java source code), i call
fork = model.getObject("fork");
the klass is loaded internally with the java class loader.

so and now, i want to move this klass files to the node in the same way like the java class files
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 1436
    • JPPF Web site
Re: non class files with classloader?
« Reply #3 on: May 03, 2012, 08:26:53 AM »

Hello,

Thank you very much for clarifying.
So I would say yes, it should work in JPPF. Getting the "klass" file from the remote client's classpath is not an issue. The one thing you need to ensure is that, on the node, the code that instantiates the class described in the "klass" file uses the same class loader which loaded the class of your JPPF task. Do you know if that's the case?

-Laurent
Logged

ernst

  • JPPF Padawan
  • *
  • Posts: 14
Re: non class files with classloader?
« Reply #4 on: May 03, 2012, 08:33:11 PM »

hi laurent,

after reading source code the whole day, can i tell you hiw the klassloader works. the klass files are textfiles *.klass which are read with an inputstream and parsed to assign the corresponding class/object.
so the interessting part is:

final String klasspath = klassname.replace('.', '/') + ".klass"; //fully qualified name
URL url = Klass.class.getClassLoader().getResource(klasspath);
InputStream in = url.openStream();
cpl = new CPListener(klassname);   //doing klass stuff


so the klass loader is useable like java class loader but i don't know if it the answer of your question. but i think with the url and the inputstream i can tinker something....or not?

update: maybe i ask for a generic way to load any ressource (images, xml, files) through the class loader. a ftp service breaks in my opinion the idea of an p2p system.
« Last Edit: May 03, 2012, 11:23:23 PM by ernst »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 1436
    • JPPF Web site
Re: non class files with classloader?
« Reply #5 on: May 04, 2012, 08:33:27 AM »

Hello,

Thanks for the additional details. Here it should work if "Klass.class.getClassLoader()" is a JPPF classloader. It will allow you to find remote resources on the the JPPF client's or server's classpath, so I don't see any reason why it wouldn't work. The best would certainly be to give it a try, with a small sample JPPF task that would get the .klass file and do the "klass stuff", even though the library that contains the file is not in the node's classpath.

Sincerely,
-Laurent
Logged

ernst

  • JPPF Padawan
  • *
  • Posts: 14
Re: non class files with classloader?
« Reply #6 on: May 06, 2012, 07:24:28 PM »

hi laurent,

so i tried this with
URL url = org.jppf.node.NodeRunner.getJPPFClassLoader().getResource(klasspath);
but it results to null

update:
ClassLoader cl =this.getClass().getClassLoader();
if(cl instanceof JPPFClassLoader) System.out.println(((JPPFClassLoader) cl).findResource


leads also to null
« Last Edit: May 07, 2012, 02:32:07 PM by ernst »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 1436
    • JPPF Web site
Re: non class files with classloader?
« Reply #7 on: May 07, 2012, 04:09:26 PM »

Hi,

Can you tell us where you are doing the call "cl =this.getClass().getClassLoader();" from ? Is it from within the scope of a JPPF task running in the node?
Is there any way you could post a sample code that reproduces the problem?
Also, where is the jar or class folder that contains the "klasspath" resource? Is it in the client's classpath?

Thanks,
-Laurent
Logged

ernst

  • JPPF Padawan
  • *
  • Posts: 14
Re: non class files with classloader?
« Reply #8 on: May 07, 2012, 04:48:01 PM »

"cl =this.getClass().getClassLoader();" was called in the task (-> this), and after play around it works...
but it was not the expected success

klasspath is a string eg "sample/d3fact/demomodel/Fork.klass" that points to the klass file in clients classpath
and, when the task reaches the node, a klass file is requested, the klassloader is triggered:

KlassLoader is a part of the simulation platform, which is started with a InitializationHook.

public class KlassLoader{
...     // runs on the node
    private static final Klass loadClass(final String klassname){
        final String klasspath = klassname.replace('.', '/') + ".klass";
        ClassLoader cl = org.jppf.node.NodeRunner.getJPPFClassLoader();
        URL url = cl.getResource(klasspath);
        InputStream in = url.openStream();
        ....
    }

}


at the node are some native  klass files from a library and those are correctly loaded.
but not user defined klass files from the client

update: so i'm not sure if it's the right instance of the JPPFClassLoader. it's strange when it works within the task and not outside of the task
« Last Edit: May 07, 2012, 04:59:14 PM by ernst »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 1436
    • JPPF Web site
Re: non class files with classloader?
« Reply #9 on: May 07, 2012, 04:55:34 PM »


I think the problem is due to your call to "org.jppf.node.NodeRunner.getJPPFClassLoader();"
This does not return the class loader that you need (in fact it is its parent class loader).
The proper class loader should be the one that loads the JPPF task, because only it has access to the remote client's classpath.
The class loader returned by "NodeRunner.getJPPFClassLoader()" only has access to the server's classpath.
So you need to find a way to propagate the task's class loader to the Klassloader.loadClass() method for this to work.

-Laurent
Logged

ernst

  • JPPF Padawan
  • *
  • Posts: 14
Re: non class files with classloader?
« Reply #10 on: May 07, 2012, 05:47:47 PM »

yes this works.
thanks for your patient help!
Logged
Pages: [1]   Go Up
 
Support This Project Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Powered by Parallel Matters Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads