JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   On Github   Forums 
June 04, 2023, 06:22:08 PM *
Welcome,
Please login or register.

Login with username, password and session length
Advanced search  
News: New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: How to Kill JPPFDriver instance in code?  (Read 1965 times)

Bghyun

  • JPPF Padawan
  • *
  • Posts: 3
How to Kill JPPFDriver instance in code?
« on: August 20, 2015, 02:18:40 AM »

In my code, I am instantiating an anonymous class that extends JPPFDriver, and from there running the server manually. That is:

    JPPFDriver server = new JPPFDriver(){}
    server.run();
    // do stuff
        ...
    server.shutdown();

However, it seems like this shutdown() call is not releasing the socket managing the server, because when i go to make another instance of a JPPFDriver I get this error message:

    Could not initialze JPPFDriver: java.net.BindException: Address already in use: bind

Obviously this means that the socket was not released properly, so my question is how do i properly shutdown the driver so that it releases the socket binding as well?


** NOTE: I do not want to kill the JVM to release the socket binding as a solution, thanks.

« Last Edit: August 20, 2015, 02:21:56 AM by Bghyun »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: How to Kill JPPFDriver instance in code?
« Reply #1 on: August 20, 2015, 06:40:48 AM »

Hello,

The driver is designed to run as a separate process. Given the fact that it performs memory-intensive operations and that it can be customized via a number of plugins, there is no other way to guarantee a clean state of its JVM but to kill/restart the JVM.

The method to call to kill/restart a driver is JPPFDriver.initiateShutdownRestart(), however it will kill the JVM, either  with an exit code 0 for a kill command, or an exit code 2 for a restart command.

Perhaps if you could explain what you are trying to accompliish, we might find a different way to achieve it?

Sincerely,
-Laurent
Logged

Bghyun

  • JPPF Padawan
  • *
  • Posts: 3
Re: How to Kill JPPFDriver instance in code?
« Reply #2 on: August 21, 2015, 01:52:42 AM »

Hi Laurent,

I am performing regression tests against my work with JPPF using only 1 client, 1 node and 1 driver via the JUnit framework. I want each of my test to follow the procedure:

    1) configure JPPFDriver, node, client etc
    2) do my regression test with objects configured from 1)
    3) close JPPFDriver, node, client etc

The first test won't encounter any issues, because this is after the JVM starts up and configures the JPPFDriver etc. However, any subsequent tests will fail because JPPFDriver.shutdown() isn't releasing the socket binding configured by the JPPFDriver at step 3). JPPFDriver.initiateShutdownRestart() does release this socket binding, but in doing so it will kill the JVM and hence terminating my regression tests.

What would you suggest I do if I wanted to keep my regression testing procedure? Any feedback is appreciate!
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: How to Kill JPPFDriver instance in code?
« Reply #3 on: August 21, 2015, 09:44:33 AM »

Hello,

Thanks for the explanation, things are much clearer now. I was thinking that maybe you could reuse our own regression testing framework, since it does exactly what you describe (except for the actual tests which cover JPPF features).

This framework works by starting separate processes for the nodes and drivers it requires, and killing these processes whenever the tests end, either normally or when killing the test runner - thus no hanging process is ever left. It supports any grid topology that can be setup locally (on the local test machine), including any number of nodes,  multi-driver setups, SSL communication, etc...

I suggest you at least take a look at it. You can get it from the latest JPPF source distribution. All the tests are grouped in a single project, in "JPPF-5.0.4-full-src/tests". In there the "src" folder is where the interesting stuff happens:
- "src/framework" contains the classes that start the driver and nodes processes, apply custom configurations, and manage the cleanup
- "src/tests" contains the tests themselves, based on JUnit 4
- "src/resources" contains the configuration files used in the tests

A simple example of test classs could be implemented like this:

Code: [Select]
import org.jppf.client.JPPFClient;
import org.junit.*;
import test.org.jppf.test.setup.BaseSetup;

public class ExampleTest {
  private static JPPFClient client;

  @BeforeClass
  public static void setup() throws Exception {
    // start 1 driver and 4 nodes and create a JPPFClient using the default config files in classes/test/config
    client = BaseSetup.setup(1, 4, true, BaseSetup.createDefaultConfiguration());
  }

  @AfterClass
  public static void cleanup() throws Exception {
    // stops or kills all nodes and drivers and closes the client
    BaseSetup.cleanup();
    client = null;
  }

  @Test
  public void myTestMethod() throws Exception {
    // tests are performed here ...
  }
}

Sincerely,
-Laurent
Logged

Bghyun

  • JPPF Padawan
  • *
  • Posts: 3
Re: How to Kill JPPFDriver instance in code?
« Reply #4 on: August 22, 2015, 02:24:03 AM »

Hi Laurent,

Thank you for this suggestion, I will be sticking with your solution for now as it seems like the best way to go about my regression tests!
Logged
Pages: [1]   Go Up
 
JPPF Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads