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 
March 24, 2023, 07:21:51 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 get 'Client UUID' on the node side  (Read 1129 times)

tamas

  • JPPF Master
  • ***
  • Posts: 30
How to get 'Client UUID' on the node side
« on: September 21, 2015, 01:43:33 PM »

Hi all,

I need to obtain the 'Client UUID' on the node side.

Client UUID is defined in constructor of the client JPPFClient(String uuid).

I will use this info to create a unique directory for each client on the node side.

I am sure that is possible to get this info but I cannot see it in the documentation.

JPPF task is defined as
public class JPPF_FTPDownloadTask extends AbstractTask<String> {
}

Thanks,
Tomas
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: How to get 'Client UUID' on the node side
« Reply #1 on: September 21, 2015, 03:12:37 PM »

Hi Tomas,

To get the UUID from a task on the node side, you need to add it as (part of) a custom task attribute, or (recommended) put it in the job's data provider:

client side:
Code: [Select]
JPPFClient client = ...;
DataProvider dataProvider = new MemoryMapDataProvider();
job.setDataProvider(dataProvider);
dataProvider.setParameter("client.uuid", client.getUuid());

node side:
Code: [Select]
public class MyTask extends AbstractTask<String> {
  @Override
  public void run() {
    String clientUuid = getDataProvider().getParameter("client.uuid");
    ...
  }
}

Sincerely,
-Laurent
« Last Edit: September 21, 2015, 03:21:28 PM by lolo »
Logged

tamas

  • JPPF Master
  • ***
  • Posts: 30
Re: How to get 'Client UUID' on the node side
« Reply #2 on: September 21, 2015, 05:48:09 PM »

Hello Laurent,

I know that it could be done as you wrote through the DataProvider.

The problem is that we need to know the client id everywhere inside the code without pass this info through all the program.

We know the client id from the DataProvider in "MyTask extends AbstractTask<String>" but I do not have this info in my instance which is called by other 20 instancies.

We use our own ClassLoader which reads class files from directory identified by client_id = each client has own classes which are loaded dynamically.

I know that is possible to get the client class loader by
ClassLoader loader = Thread.currentThread().getContextClassLoader();

So you allways know which client's code is processed.
As I know from doc each client has own ClassLoader
http://www.jppf.org/doc/v3/index.php?title=Class_loading_in_JPPF

From this I think that should be possible to get the client_id from any part of code. What do you think about it?

Thanks,
Tomas
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: How to get 'Client UUID' on the node side
« Reply #3 on: September 22, 2015, 11:32:46 AM »

Hi Tomas,

I don't know what you mean by "I do not have this info in my instance which is called by other 20 instances", so I do not understand what you're trying to achieve. In particular, what do you mean exactly by "instance" ?

Anyway, if you manage to get a hold of the JPPF class loader that loaded the tasks, you can use AbstractJPPFClassLoaderLifeCycle.getClientUuid() to get the client uuid. Just make sure the class loader is really an instance of AbstractJPPFClassLoaderLifeCycle before using it:

Code: [Select]
String clientUuid = null;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader instanceof AbstractJPPFClassLoaderLifeCycle) {
  clientUuid = ((AbstractJPPFClassLoaderLifeCycle) loader).getClientUuid();
}

Sincerely,
-Laurent
Logged

tamas

  • JPPF Master
  • ***
  • Posts: 30
Re: How to get 'Client UUID' on the node side
« Reply #4 on: September 23, 2015, 01:07:29 PM »

Thanks Laurent,

it is exactly what I need.

By 'instance' I meant object = instance of object.

Thanks for your help.
It is a good way how to know the client id in any part of the code.

Best regards,
Tomas
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