JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
The open source
grid computing
solution
Home
About
Features
Download
Documentation
On Github
Forums
March 29, 2023, 12:18:57 AM
Welcome,
Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
New users, please read
this message
. Thank you!
Home
Help
Search
Login
Register
« previous
next »
Pages: [
1
]
Go Down
Print
Author
Topic: Initializing Node with startup data (Read 4175 times)
piyushgrover87
JPPF Padawan
Posts: 13
Initializing Node with startup data
«
on:
June 09, 2013, 03:46:43 PM »
Hi
I am new to JPPF and I am trying to implement a web application on top of JPPF & tomcat.
I have done the configuration and work can be performed on many nodes for a web request.
The challenge I am facing is, I want to load data from DB on Node Startup on every node and want
the JPPFTasks running on a node to consume the data . I have tried creating a DataProvider instance on node startup
but I am getting java.lang.NullPointerException while reading from DataProvider instance in the task .
Please suggest me if am I missing something or any other method to load the data on all the nodes.
Logged
lolo
Administrator
JPPF Council Member
Posts: 2272
Re: Initializing Node with startup data
«
Reply #1 on:
June 10, 2013, 08:47:46 AM »
Hello,
What you need can be accomplished by deploying a
node startup class
, which you can use to load data from the DB and provide an API for you tasks to access it.
I hope this helps.
-Laurent
Logged
piyushgrover87
JPPF Padawan
Posts: 13
Re: Initializing Node with startup data
«
Reply #2 on:
June 10, 2013, 11:34:20 AM »
Hi Laurent
Thanks for your response, I am using Node Startup class only, I am able to initialize database pool and am able to store data in StaticData class ( a Singleton class extending Serializable)
which is nothing but a wrapper on a HashMap. But when I am reading data from this class in the JPPFTask I am getting null while reading. The class looks like this:
public class StaticData implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 10293847563L;
private static HashMap<String, Object> staticData;
private StaticData(){}
public static void put(String key, Object value)
{
if(staticData == null)
{
staticData = new HashMap<String, Object>();
}
staticData.put(key, value);
}
public static Object get(String key)
{
return staticData.get(key);
}
}
So basically In the startup class I am initializing DB pool and then retrieving data from DB and storing as
StaticData.put("key", value);
but in the JPPFTask when I am trying to read, I am getting a null value corresponding to the "key"
Can you tell me what I am missing?
Logged
lolo
Administrator
JPPF Council Member
Posts: 2272
Re: Initializing Node with startup data
«
Reply #3 on:
June 10, 2013, 01:19:44 PM »
Hi,
It is possible that your node startup class was not properly deployed. Can you confirm that you have put its code (including the classes it uses) has been put into a jar file, that this jar files contains a file META-INF/services/org.jppf.startup.JPPFNodeStartupSPI (which contains "<mypackage>.<MyNodeStartup>" your implementation of the node startup class), and that this jar was added to the driver's classpath?
You may also check by adding a System.out.println statement in the run() method of your startup class, which should show up in the node's output once it is connected to the driver.
Thanks,
-Laurent
Logged
piyushgrover87
JPPF Padawan
Posts: 13
Re: Initializing Node with startup data
«
Reply #4 on:
June 10, 2013, 01:51:39 PM »
I followed the topic
http://www.jppf.org/forums/index.php?topic=1744.0
and did a little modification in StaticData class, now it looks (public class StaticData implements JPPFNodeStartupSPI and an empty run method)
I have created META-INF/services/org.jppf.startup.JPPFNodeStartupSPI which contains these lines:
com.test.cluster.node.domain.StaticData
com.test.cluster.node.Startup
I have copied the corresponding NodeStartup.jar file in JPPF-3.3.2-driver/lib(copied now only but no luck) and in JPPF-3.3.2-node/lib directory.
The Startup's run method creates a DBpool and stores data as StaticData.put("map", data). I can see the print statements in the node's console.
But when the JPPFTask tries to read the value it gives NullPointerException
java.lang.NullPointerException
at com.test.cluster.node.domain.StaticData.get(StaticData.java:26)
at com.test.service.TripWorker.<init>(TripWorker.java:60)
at com.test.service.TripOrganizer.createJob(TripOrganizer.java:877)
TripWorker.java:60 contains this:
this.dMap = (HashMap<String, Integer>) StaticData.get("map");
Something else I forgot to do??
Logged
piyushgrover87
JPPF Padawan
Posts: 13
Re: Initializing Node with startup data
«
Reply #5 on:
June 10, 2013, 07:35:26 PM »
Laurent,
I found my mistake. I was doing this.dMap = (HashMap<String, Integer>) StaticData.get("map");
in the JPPFTask constructor itself instead of doing it in the run method. The test grid is working now.
Now, I want to explore something from the configuration perspective.
I have two nodes, one running on the server itself with the client and the other node is individual.
When I am running my job, I can see them executing either on node one or on the other but I want all the tasks
in the job to run in parallel utilizing both the nodes. I think I need to do something in the configuration.
How can I do this?
Additionally, when I am shutting down my node I want to close all the DBpool's connections. Is there anything like node shutdown
which can be done similar to node startup?
Thanks
Piyush
Logged
lolo
Administrator
JPPF Council Member
Posts: 2272
Re: Initializing Node with startup data
«
Reply #6 on:
June 11, 2013, 06:07:02 AM »
Hello,
I'm glad it was a simple problem that prevented the startup class from working.
Regarding the distribution of tasks to the nodes, it will be determined be the number of tasks in your job and the
load-balancer
configured for the driver. By default, the driver uses the "proportional" load-balancing algortihm, with a "iniitalSize" parameter of 10. This is a bootstrap parameter for the algorithm which tells it how many tasks will be sent to a node the first time. So, if your first job has 10 tasks, all these tasks will be sent to a single node. Thus I recommend using a lower value for thhe bootstrap parameter. Can you try this and let us know if it improves things?
For the shutdown problem, unfortunately, we do not have a Shutdown class. However we have a
NodeLifeCycleListener
extension which handles, among others, node startup and node ending events. You could perform the data initialization from the nodeStarting() event notfiication and the cleanup fo the DB connections within the nodeEnded() notification. A node lifecycle listener is deployed in exactly the same way as a startup class (with the SPI mechanism), albeit with a dfifferent interface to extend and a different service file name.
Sicerely,
-Laurent
Logged
piyushgrover87
JPPF Padawan
Posts: 13
Re: Initializing Node with startup data
«
Reply #7 on:
June 11, 2013, 08:42:06 AM »
Thanks Laurent,
I will try that and will let you know if everything works smoothly!!
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
JPPF Forums
>
Architecture and Design
>
JPPF In Real Life
>
Initializing Node with startup data
Loading...