• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » StringBuffer in a context variable

#1 2009-03-11 14:03:30

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 911
Website

StringBuffer in a context variable

hi,

I've to keep trace of some informations during job running.
Until now I was made out.println to test the output string infos.
(also test a log file to write any data infos )

Now we're tying to get back those infos via context.
We choice context because we have access on each of them from our "bean j2ee framework".(more efficient than read the log file each time)

So in a tjavaflex I create new context type Object and  name buffer.
and add code :

Code:

String sBuffer = new StringBuffer()
sBuffer.append("some data infos');
context.buffer = sBuffer;

read string in the same tJavaflex :

Code:

System.out.println(context.buffer.toString()); // some data infos

But it's a sub-job , so try to pass object buffer context to his parent with tBufferOut .
but cannot retrieve values in the parent job; stay null !

first it's possible to use context like that ?(use type objetct for stringBuffer value) ... seems working 
Is it a ggod way to use context like that ?

thanks for your help and suggestion


do Svg your graphical language !!!

Offline

#2 2009-03-11 21:19:04

Volker Brehm
Member
Registered: 2007-04-03
Posts: 1139
Website

Re: StringBuffer in a context variable

Hi,

it is not possible to return a context value back from the subjob. I would suggest to use a public static variable in a function to do this. But this not a good design decision...

If I understand you right you tried to do the following:
mainJob:      tRunJob (with context)   - - - - - - - - - - - ->tContextLoad
                                   |                                                     ^
                                  `´                                                    |
subJob:                    do your job   -> tFixedFlowInput -> tBufferOut

I didn't test it, but think it would work....

Bye
Volker

Offline

#3 2009-03-12 11:19:33

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 911
Website

Re: StringBuffer in a context variable

hi Volker,

I've tried several 'solution' to manage context variable ...
I thought that StringBuffer could be a solution , but I think i lost the advantage of it .(like a String, but can be modified) ..
from sub and father job , instances 're  copied!

I'm trying now with a context group  var but still work with object and have problem with cast ...

I spent "a lot of"  time with manage context an perhaps I don't use them in a right way.

the goal of my "work" is to keep a single context var during all job, subjob , parent job and cousin smile  ...
Still thinking that the best way in this case is wrinting in a flat file and read it at the end ...

....

++


do Svg your graphical language !!!

Offline

#4 2009-03-12 21:32:58

Volker Brehm
Member
Registered: 2007-04-03
Posts: 1139
Website

Re: StringBuffer in a context variable

Hi,

so you are searching for an overall solution? What about a custom static class which could be used in all your jobs? But the information will be stored in the JVM session. After starting a new one the information will be lost.

Bye
Volker

Offline

#5 2009-03-13 09:17:38

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 911
Website

Re: StringBuffer in a context variable

hi,

What about a custom static class which could be used in all your jobs?

.. looks great !

But the information will be stored in the JVM session. After starting a new one the information will be lost.

never mind ... user have to know some data during excecution (control data) ! until now standard output (system out) was sufficient , but  with an web interface I have to "redirect" those data in a html format , and just for the session !

Can you give me more explanation about how to this class "workaround" ?

thanks wink

laurent


do Svg your graphical language !!!

Offline

#6 2009-03-13 11:50:59

Volker Brehm
Member
Registered: 2007-04-03
Posts: 1139
Website

Re: StringBuffer in a context variable

Hi laurent,

go to Repository -> Code -> Routines and create a new one.
Now you could write a java class to store a value: The value and any method should be defined as static. So you could access them from every point where you know the classname.

Bye
Volker

Offline

#7 2009-03-13 12:50:57

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 911
Website

Re: StringBuffer in a context variable

.....

so simple ...!

I have to read again definition about  static  in java .  smile

thanks a lot Volker ;
++

Last edited by kzone (2009-03-13 12:52:32)


do Svg your graphical language !!!

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » StringBuffer in a context variable

Board footer

Powered by FluxBB