Results 1 to 9 of 9
  1. #1
    eddie-w is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default Dynamic loading of a class (passing class definition over the network)

    Hello everyone... I'm new here

    First of all, I apologize for my english and I hope someone will understand what I ask

    I need help with an university project. I'm coding a run time support for a pipeline: the user must have the possibility to define a pipeline computation (which is a sequence of nodes, each one's input being the output of the previous one). Each pipeline node has to be executed on a different computer.
    The computers on which the pipeline nodes will be executed are found with JXTA. But when I find the computers, I'm not able to pass over the network the definition of the function which has to be executed on the computer. To resume, I have to
    - define some classes on a computer
    - load these classes on another computer located somewhere else on the network

    How can I pass the class definition over a socket to dinamically load it on the other PC?

    Hope someone can help me. Please use a simple english to answer
    Thanks!
    Lorenzo

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Look at the ClassLoader API...
    The Java Tutorial. Read it.

  3. #3
    eddie-w is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Steve11235 View Post
    Look at the ClassLoader API...
    I'm asking to you because I didn't find the answer on the APIs... I've a big lack of knowledge in this field, and I don't even know where to find a good tutorial for learning how to do such things.

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by eddie-w View Post
    I'm asking to you because I didn't find the answer on the APIs... I've a big lack of knowledge in this field, and I don't even know where to find a good tutorial for learning how to do such things.

    perhaps also rmi An Overview of RMI Applications (The Java™ Tutorials > RMI) could be what you are looking for.

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I haven't done this either, but I think you need to implement findClass(). I assume findClass() should actually retrieve the bytes that make up the class, using whatever methods make sense. I would suggest looking for OSS projects that implement that method, so you look at their approach.
    The Java Tutorial. Read it.

  6. #6
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    It's pretty starightforward. On the server side, just send the class data as a byte[]. The class data is simply the contents of the .class file read in as a byte[].

    On the client side, use one of the 'defineClass' methods of teh ClassLoader.

    Java Code:
    ClassLoader.getSystemClassLoader().defineClass...
    If more than 1 class is involved, then you have to do this for every one of them, or you can package them up into a jar on the server side and use a URLClassLoader.

  7. #7
    eddie-w is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by j2me64 View Post
    perhaps also rmi An Overview of RMI Applications (The Java™ Tutorials > RMI) could be what you are looking for.
    the problem with rmi is that it's useful when you need to execute a class which is loaded into another JVM. I have to execute remotely a class which is loaded into my JVM. ;)

    I will probably pass the .class location as a parameter... or with an XML file. I think it's the only way to obtain the code and pass it over the network :(

  8. #8
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by eddie-w View Post
    I have to execute remotely a class which is loaded into my JVM. ;)

    but then use a simple ftp, mount the remote drive to your local machine and call java -cp remotedrive ... ;)

  9. #9
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    You can use sockets to directly transfer the byte code from machine to machine, including http if you want. Another common approach would be to use ftp (yes, there's an API for that too). If this is a distributed app running on a closed network, then you can use NFS.

Similar Threads

  1. Error: no class definition found
    By toby in forum New To Java
    Replies: 6
    Last Post: 08-28-2011, 10:32 PM
  2. Dynamic Class Loading from external Jar
    By AndreB in forum Advanced Java
    Replies: 3
    Last Post: 02-08-2010, 01:55 PM
  3. passing text from a class to a gui class
    By rob in forum AWT / Swing
    Replies: 2
    Last Post: 02-13-2009, 11:04 PM
  4. class loading
    By purejoker in forum AWT / Swing
    Replies: 1
    Last Post: 01-20-2009, 12:09 PM
  5. Loading a class within a different class
    By nick2price in forum New To Java
    Replies: 1
    Last Post: 05-30-2008, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •