You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Daling Xu <da...@yahoo.com> on 2007/01/24 00:51:36 UTC

overhead of new BSFManager()

 
  In my project, I need to execute multiple (dosens, even hundreds) JavaScript files at the same time. And for each script file, I need to register a bean object for it. I need to use that bean in my script file, e.g. 
myBeanName.method1(). But for each scipt, the bean object should be different. Also, I need to be able to stop specific script files at the run time.
  To satisfy all these requirements, I start a new BSFManager() for each script file:
  ...
Map threadMap = new Hashtable(); //
...
...
for( each scriptFileName ) {
 Thread t = new Thread(){
 
  public void run() {
   BSFManager manager = new BSFManager();
     String lang = "JavaScript";
   
   //declare the specific bean object for the script file
   manager.declareBean("beanName", beanObjectForScriptI, MyBeanClass.class );
     manager.exec( lang,
       "Java", 0, 0, 
       IOUtils.getStringFromReader(new FileReader(scriptFileName) ));
  }
   };
 
 threadMap.put( scriptFileName, t ); //keep reference of thread of each script file engie 
}
  Then, later when I call beanName.method1() in each script file, I am sure I called it on the correct beanObject instance. Also, I can stop the runnging script for scriptFileX by:
 Thread t = (Thread) threadMap.get( scriptFileX );
 t.stop();
 
 
But, I have some consern about the drawback which is the overhead of creating a BSFManager object for each script. By looking at the source code, I notice that each BSFManager maintain the loaded class of the script engine, e.g. JavaScriptEngine here.  Does that mean I am holding dosens even hundreds JavaScriptEngine class loaded in the memory by the former code scripet?? 
  Now my question is how big is this overhead? How much memory does it take? Can I avoid it? 
  If I do it this way :
   BSFManager manager = new BSFManager();
 
 for( each scriptFileName ) {
          
      String lang = "JavaScript";
      manager.declareBean("beanName", beanObjectForScriptI, MyBeanClass.class );     
      manager.exec( lang,
       "Java", 0, 0, 
       IOUtils.getStringFromReader(new FileReader(scriptFileName) ));
 
 }
  I am afraid that the declareBean method could overwrite the previously declared bean. Also, how can I stop the script execution for certain script files but keep others running at the runtime?

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
the script is actually very simple now. I am just doing some expriment to see whethere I can run multiple scripts at the same time. The actual script is just like
   
  print("Welcome to the test");
  while( true ) {
     var xyz = mybean.method1();
     print( xyz );
     mybean.method2();
  }
   
  Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,
> Before I try any pooling approach. I did some test on my current code. 
> 
> When I just new 2 BSFManager in my project, my whole project takes about 60M memory. When I start 200 BSFManager instance, I am useing 170M memory; for 100 BSFManager, it took 120M memory. ....
> 
very interesting (half a megabyte per BSFManager instance)! How large
are these scripts/the Java objects to interact with? (Just curious.)

Regards,

---rony




---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org





 
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.

Re: Any open source or comercial javascript engine other than Rhino

Posted by Mario Neè <ma...@xmoon.org>.
try XMoon
http://www.xmoon.org


Daling Xu ha scritto:
> Hi,
>    
>   Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
>    
>   So far, I found only one which is FESI. But it looks pretty old.
>    
>   Anybody here used any javascript engine other than Rhino?
>
> Thanks
>    
>   Linda
>
> "Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
>   Hi Linda,
>
> Daling Xu wrote:
>   
>> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
>>
>> This explains the reason of the exception I ran into. 
>>
>> Now my question is
>> (1) Why BSFFunctions doesn't support the getObjectRegistry method?
>>
>>     
> Don't really know what the developers had in mind here.
>
>   
>> (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
>>
>>     
> You can't. The real reason is with the original authors, maybe Sanjiva,
> if he reads this, could shed some light on this.
>
> However there may be one (good) reason: security. One never can be sure
> who writes which scripts. So for security reasons it makes sense to give
> no one the ability to figure out what the ObjectRegistry holds. The Java
> hosts (Java programs that dispatch scripts via BSF) would know what they
> put into the registry for the scripts to interact/work with, so for the
> scripts that would not really be a shortcoming. In the case that one
> needs to make a collection of Java objects available to the scripts,
> then one is able to register a collection object for the script.
>
> HTH,
>
> ---rony
>
> P.S.: The nice thing about FOSS is that in the case that you really hit
> a barrier you do not want to cope with, that you can go back to the
> sources and enhance/change/tailor the code to your needs.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bsf-user-help@jakarta.apache.org
>
>
>
>  
> ---------------------------------
>  Get your own web address.
>  Have a HUGE year through Yahoo! Small Business.
>   


-- 
Mario Neè

Neex di Neè Mario
Via Vanzeghetto Sotto N. 2
25036 Palazzolo sull'Oglio (BS)
Tel 329.2323782
Fax 178.222.0639
mario.nee@neex.it

www.neex.it
--

CONFIDENZIALE: Questo messaggio e gli eventuali allegati sono confidenziali e riservati. Se vi e' stato recapitato per errore e non siete fra i destinatari elencati, siete pregati di darne immediatamente avviso al mittente. Le informazioni contenute non devono essere mostrate ad altri, ne utilizzate, memorizzate o copiate in qualsiasi forma.
CONFIDENTIALITY : This  e-mail  and  any attachments are confidential and may be privileged. If  you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: Any open source or comercial javascript engine other than Rhino

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
> Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
>    
> So far, I found only one which is FESI. But it looks pretty old.
>    
> Anybody here used any javascript engine other than Rhino?
>   
hmm, I am pretty confident that it is not necessary to apply any changes
to Rhino, just to the BSF-Rhino/Javascript engine. Or with other words,
the speculation (short of knowing the respective Rhino interfaces):
there should be a means on board of Rhino to terminate/cancel a running
script; if so, then you would need to invoke it in the BSF-Rhino engine
(creating a terminate()-method in which you would exercise the Rhino
termination infrastrucgture). Only, if Rhino itself would not cater for
such a functionality would there be a need to apply changes to Rhino itself.

HTH,

---rony


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Any open source or comercial javascript engine other than Rhino

Posted by Daling Xu <da...@yahoo.com>.
Hi,
   
  Because of the concern on the Rhino's GPL license. We would like to find some LGPL or comercial javascript engine supported by BSF. 
   
  So far, I found only one which is FESI. But it looks pretty old.
   
  Anybody here used any javascript engine other than Rhino?

Thanks
   
  Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,

Daling Xu wrote:
> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
> 
> This explains the reason of the exception I ran into. 
> 
> Now my question is
> (1) Why BSFFunctions doesn't support the getObjectRegistry method?
> 
Don't really know what the developers had in mind here.

> (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
> 
You can't. The real reason is with the original authors, maybe Sanjiva,
if he reads this, could shed some light on this.

However there may be one (good) reason: security. One never can be sure
who writes which scripts. So for security reasons it makes sense to give
no one the ability to figure out what the ObjectRegistry holds. The Java
hosts (Java programs that dispatch scripts via BSF) would know what they
put into the registry for the scripts to interact/work with, so for the
scripts that would not really be a shortcoming. In the case that one
needs to make a collection of Java objects available to the scripts,
then one is able to register a collection object for the script.

HTH,

---rony

P.S.: The nice thing about FOSS is that in the case that you really hit
a barrier you do not want to cope with, that you can go back to the
sources and enhance/change/tailor the code to your needs.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org



 
---------------------------------
 Get your own web address.
 Have a HUGE year through Yahoo! Small Business.

Re: Using the ObjectRegistry

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,

Daling Xu wrote:
> I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
>    
>   This explains the reason of the exception I ran into. 
>    
>   Now my question is
>   (1) Why BSFFunctions doesn't support the getObjectRegistry method?
>   
Don't really know what the developers had in mind here.

>   (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
>   
You can't. The real reason is with the original authors, maybe Sanjiva,
if he reads this, could shed some light on this.

However there may be one (good) reason: security. One never can be sure
who writes which scripts. So for security reasons it makes sense to give
no one the ability to figure out what the ObjectRegistry holds. The Java
hosts (Java programs that dispatch scripts via BSF) would know what they
put into the registry for the scripts to interact/work with, so for the
scripts that would not really be a shortcoming. In the case that one
needs to make a collection of Java objects available to the scripts,
then one is able to register a collection object for the script.

HTH,

---rony

P.S.: The nice thing about FOSS is that in the case that you really hit
a barrier you do not want to cope with, that you can go back to the
sources and enhance/change/tailor the code to your needs.


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: Using the ObjectRegistry

Posted by Daling Xu <da...@yahoo.com>.
I continued to drill down on this issue. From reading of the BSF source code, I found that the "bsf" object that was put into the javascript global context is actually a object of BSFFunctions object which only contains a subset of BSFManager methods. The BSFFunctions doesn't have a getObjectRegistry method.
   
  This explains the reason of the exception I ran into. 
   
  Now my question is
  (1) Why BSFFunctions doesn't support the getObjectRegistry method?
  (2) How can I retrieve the bean objects from the ObjectRegiestry inside the script code?
  
Thanks
   
  Linda

Daling Xu <da...@yahoo.com> wrote:
  Hi Rony,

I think I am following the steps you described, here is my code:

final String BEAN_ANME = "myBeanName";
BSFManager manager = new BSFManager();


ObjectRegistry objReg = new ObjectRegistry( manager.getObjectRegistry() );
objReg.register(BEAN_NAME , new MyBeanClass("my String by objReg")); 


manager.setObjectRegistry( objReg );




manager.exec("javascript", "test", 0, 0, "bsf.getObjectRegistry().lookup(\"" + BEAN_NAME +"\")"+ ".myMethod();" ); //try case 1

//manager.exec("javascript", "test", 0, 0, "bsf.lookupBean(\"" + BEAN_NAME +"\")"+ ".myMethod();" ); //try case 2

//manager.exec("javascript", "test", 0, 0, BEAN_NAME + ".myMethod();" ); //try case 3

None of the three tries worked. 

For the try case 1, I got this error:
TypeError: Cannot find function getObjectRegistry. although I can directly call 
Although I can run the following code successfully in my java code:
Object obj = manager.getObjectRegistry().lookup( BEAN_NAME );
((MyBeanClass)obj).myMethod();

For the case 2, I got a java.lang.ClassCastException, here is part of my printstacktrace:
at org.apache.bsf.BSFManager.lookupBean(BSFManager.java:736)
at org.apache.bsf.util.BSFFunctions.lookupBean(BSFFunctions.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


For the case 3, I know conceptly it not the right way to do, just use it to confirm my understanding. As expected, it gave me exception of "myBeanName" is not defined.

Conceptually, I think the case 1 here is the right way to do it, but why it didn't work?

Thanks

Linda


"Rony G. Flatscher" wrote:
bm=new org.apache.bsf.BSFManager();
// ... do whatever you need to do (setup, invoking scripsts, maybe
nothing, whatever)

or=new org.apache.bsf.ObjectRegistry();
// or if you want to use bm's ObjectRegistry object as a parent:
or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
// do whatever you need to do with "or" (registering objects for the
scripts)....

bm.setObjectRegistry(or); // now set "bm" to the new
ObjectRegistry object "or"
// continue to invoke scripts

HTH,

---rony




---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

 	
---------------------------------
Everyone is raving about the all-new Yahoo! Mail beta.

Re: Using the ObjectRegistry

Posted by Daling Xu <da...@yahoo.com>.
Hi Rony,
   
  I think I am following the steps you described, here is my code:
   
  final String BEAN_ANME = "myBeanName";
  BSFManager manager = new BSFManager();
  
   
  ObjectRegistry objReg = new ObjectRegistry( manager.getObjectRegistry() );
  objReg.register(BEAN_NAME , new MyBeanClass("my String by objReg")); 
   
  
  manager.setObjectRegistry( objReg );
  
  
  
   
  manager.exec("javascript", "test", 0, 0, "bsf.getObjectRegistry().lookup(\"" + BEAN_NAME +"\")"+ ".myMethod();" );  //try case 1
   
  //manager.exec("javascript", "test", 0, 0, "bsf.lookupBean(\"" + BEAN_NAME +"\")"+ ".myMethod();" );  //try case 2
   
  //manager.exec("javascript", "test", 0, 0, BEAN_NAME + ".myMethod();" ); //try case 3
   
  None of the three tries worked. 
   
  For the try case 1, I got this error:
  TypeError: Cannot find function getObjectRegistry.  although I can directly call 
  Although I can run the following code successfully in my java code:
  Object obj = manager.getObjectRegistry().lookup( BEAN_NAME );
  ((MyBeanClass)obj).myMethod();
   
  For the case 2, I got a java.lang.ClassCastException, here is part of my printstacktrace:
  at org.apache.bsf.BSFManager.lookupBean(BSFManager.java:736)
  at org.apache.bsf.util.BSFFunctions.lookupBean(BSFFunctions.java:46)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   
   
  For the case 3, I know conceptly it not the right way to do, just use it to confirm my understanding. As expected, it gave me exception of "myBeanName" is not defined.
   
  Conceptually, I think the case 1 here is the right way to do it, but why it didn't work?
  
Thanks
   
  Linda
  

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  bm=new org.apache.bsf.BSFManager();
// ... do whatever you need to do (setup, invoking scripsts, maybe
nothing, whatever)

or=new org.apache.bsf.ObjectRegistry();
// or if you want to use bm's ObjectRegistry object as a parent:
or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
// do whatever you need to do with "or" (registering objects for the
scripts)....

bm.setObjectRegistry(or); // now set "bm" to the new
ObjectRegistry object "or"
// continue to invoke scripts

HTH,

---rony



 
---------------------------------
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.

Using the ObjectRegistry (Re: declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
>   Thank you for you assistance.
>   
You are very welcome, glad that I could help a little bit.

>   I modified my code for the approach using manager.registerBean() :
>    
>   BSFManager manager = new BSFManager();
>   manager.registerBean( "myBeanName", new MyBeanClazz("str for regBean");
>   manager.exec( "javascript", "test", 0,0, "bsf.lookupBean(\"myBeanName\").myMethod();" );
>    
>   This time it works and printed out the string in the console. Thanks.
>   
Fine.

>   It looks that the BSFManager defaultly declared a bean "bsf" so the script can always use it just like a predefined object in the javascript.
>   
It is put into the global context by the Javascript engine.

>   But for my ObjectRegistery approach, even I tried to call bsf.lookupBean in the script code, it still doesn't work, anything still missing here?
>   
Hmm, did you set the the ObjectRegistry object to your BSFManager's
instance?

Something along the lines:

    bm=new org.apache.bsf.BSFManager();
    // ... do whatever you need to do (setup, invoking scripsts, maybe
    nothing, whatever)

    or=new org.apache.bsf.ObjectRegistry();
    // or if you want to use bm's ObjectRegistry object as a parent:
    or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
    // do whatever you need to do with "or" (registering objects for the
    scripts)....

    bm.setObjectRegistry(or);    // now set "bm" to the new
    ObjectRegistry object "or"
    // continue to invoke scripts

HTH,

---rony


Re: declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
Hi Rony,
   
  Thank you for you assistance.
   
  I modified my code for the approach using manager.registerBean() :
   
  BSFManager manager = new BSFManager();
  manager.registerBean( "myBeanName", new MyBeanClazz("str for regBean");
  manager.exec( "javascript", "test", 0,0, "bsf.lookupBean(\"myBeanName\").myMethod();" );
   
  This time it works and printed out the string in the console. Thanks.
   
  It looks that the BSFManager defaultly declared a bean "bsf" so the script can always use it just like a predefined object in the javascript.
   
  But for my ObjectRegistery approach, even I tried to call bsf.lookupBean in the script code, it still doesn't work, anything still missing here?
   
  Linda
   
  

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,

there is a difference between declaring and registering a bean:
declareBean() tries to inform the BSF engine explicitly about the bean,
such - if supported by the language - that it gets implicitly defined
for the script, whereas declared beans need to be looked up by the
script before being able to use it.

Or with other words: have the script look-up the bean before using it.
E.g., in Javascript:

myBean = bsf.lookupBean ("myBean"); /* retrieve a registered Java
object */

HTH,

---rony



 
---------------------------------
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.

declareBean() vs. registerBean() (Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,

there is a difference between declaring and registering a bean:
declareBean() tries to inform the BSF engine explicitly about the bean,
such - if supported by the language - that it gets implicitly defined
for the script, whereas declared beans need to be looked up by the
script before being able to use it.

Or with other words: have the script look-up the bean before using it.
E.g., in Javascript:

    myBean = bsf.lookupBean ("myBean");  /* retrieve a registered Java
    object */

HTH,

---rony


Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
I tried to use both ObjectRegistry and manager.registerBean, neither of them works. 
   
  I am using JDK1.4.1,  BSF2.4 and Rhino 1.6R5.
   
  First here is my bean class defined in java:
  public class MyBeanClazz {
      private String str;
      public MyBeanClazz( String val ) {
         str = val;
      }
   
      public void myMethod() {
         System.out.println( str );
      }
  }
   
  Then I need to create an instance of MyBeanClazz and pass it to the javascript code, so I can call myMethod from javascript code.
   
  I first tried:
   
  BSFManager manager = new BSFManager();
  manager.registerBean( "myBeanName", new MyBeanClazz( "myString")  );
  manager.exec( "javascript" , "test" , 0, 0, "myBeanName.myMethod();");
   
  This gives me a 
  SEVERE: Exception :
  java.security.PrivilegedActionException: org.apache.bsf.BSFException: JavaScript Error: Internal Error: org.mozilla.javascript.EcmaError: ReferenceError: "myBeanName" is not defined.
   
  Then I tried:
  BSFManager manager = new BSFManager();
  ObjectRegistery objReg = manager.getObjectRegistry();
  objReg.register( "myBeanName", new MyBeanClazz("string1"));
  manager.exec( "javascript", "test", 0, 0, "myBeanName.myMethod()" );
   
  This gives me the same exception. 
   
  I finally tried this one:
   
  BSFManager manager = new BSFManager();
  manager.declareBean( "myBeanName", new MyBeanClazz("string2"), MyBeanClazz.class);
  manager.exec( "javascript", "test", 0, 0, "myBeanName.myMethod()" );
   
  This one run successfully and printed the "string2" in the console.
  
But why the first two cases didn't work? Especially the case 1, according to the api documentation, it should work? Anything I did wrongly here? ( I double checked, it's not because any typo in the bean name string  when I registered it).  
   
  And base on my understanding to the api doc, the case one is conceptly the right way to do it, right?
   
  Thanks
   
  Linda
   

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  
> In the JDK 6's script supporting API, I can bind beans into a specific ScriptContext, then evaluate the script code insed that context. By doing this, I can bind different bean objects for different scripts using the same name. Can I do the similar thing using BSF?
> 
Yes, this should be possible with the ObjectRegistry, something like:

* create an ObjectRegistry object, register the beans that you want
to share among different scripts with it,
o while creating an ObjectRegistry you could also supply an
existing ObjectRegistry possessing the registered objects to
the constructor. That passed ObjectRegistry object will
serve as a "parent" which is looked up, if the new
ObjectRegistry does not have the sought entry, serving as a
fall-back registry.
* set the BSFManager's ObjectRegistry using setObjectRegistry().

Also, you could get the ObjectRegistry object from a BSFManager with
getObjectRegistry() and supply it to a different instance of BSFManager,
in the case that scripts created entries there which should be referred
to in other scripts.

Just try it out.

HTH,

---rony



 
---------------------------------
Don't get soaked.  Take a quick peak at the forecast 
 with theYahoo! Search weather shortcut.

Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
> In the JDK 6's script supporting API, I can bind beans into a specific ScriptContext, then evaluate the script code insed that context. By doing this, I can bind different bean objects for different scripts using the same name. Can I do the similar thing using BSF?
>   
Yes, this should be possible with the ObjectRegistry, something like:

    * create an ObjectRegistry object, register the beans that you want
      to share among different scripts with it,
          o while creating an ObjectRegistry you could also supply an
            existing ObjectRegistry possessing the registered objects to
            the constructor. That passed ObjectRegistry object will
            serve as a "parent" which is looked up, if the new
            ObjectRegistry does not have the sought entry, serving as a
            fall-back registry.
    * set the BSFManager's ObjectRegistry using setObjectRegistry().

Also, you could get the ObjectRegistry object from a BSFManager with
getObjectRegistry() and supply it to a different instance of BSFManager,
in the case that scripts created entries there which should be referred
to in other scripts.

Just try it out.

HTH,

---rony


Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
In the JDK 6's script supporting API, I can bind beans into a specific ScriptContext, then evaluate the script code insed that context. By doing this, I can bind different bean objects for different scripts using the same name. Can I do the similar thing using BSF?

Thanks

Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote: Hi Linda,
>   Before I try any pooling approach. I did some test on my current code. 
>    
>   When I just new 2 BSFManager in my project, my whole project takes about 60M memory. When I start 200 BSFManager instance, I am useing 170M memory; for 100 BSFManager, it took 120M memory. ....
>   
very interesting (half a megabyte per BSFManager instance)! How large
are these scripts/the Java objects to interact with? (Just curious.)

Regards,

---rony




---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org



 
---------------------------------
 Get your own web address.
 Have a HUGE year through Yahoo! Small Business.

Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
>   Before I try any pooling approach. I did some test on my current code. 
>    
>   When I just new 2 BSFManager in my project, my whole project takes about 60M memory. When I start 200 BSFManager instance, I am useing 170M memory; for 100 BSFManager, it took 120M memory. ....
>   
very interesting (half a megabyte per BSFManager instance)! How large
are these scripts/the Java objects to interact with? (Just curious.)

Regards,

---rony




---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
Hi,
   
  Before I try any pooling approach. I did some test on my current code. 
   
  When I just new 2 BSFManager in my project, my whole project takes about 60M memory. When I start 200 BSFManager instance, I am useing 170M memory; for 100 BSFManager, it took 120M memory. ....
   
  Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  
Just a few remarks:

* to know for sure, you should profile some test runs,


 
---------------------------------
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.

Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,

>   Thanks for your response.
>   
You are very welcome, especially if I could help at least a little bit...
;)

>   As to the register bean, I may be able to figure out a way to give different names to different script's bean object. But how about stopping a specific script at run time? If I use the same BSFManager instance for different script, is there any way I can stop them discrimitly?
>   
Well, here everyone is on the mercy of the engine implementation. As
Thread.stop() is deprecated (just study the explanations Sun gives with
that method) you may want to consider to enhance the Javascript/Rhino
engine (that's the scripting language you are employing, I think) to
react upon some method you define (e.g. abort() to forcefully stop a
running script with whatever means Rhino exposes for that purpose). This
way you could arrive at a stable and reliable means of doing what you seek.

HTH,

---rony


---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: overhead of new BSFManager()

Posted by Daling Xu <da...@yahoo.com>.
Hi Rony,
   
  Thanks for your response.
   
  As to the register bean, I may be able to figure out a way to give different names to different script's bean object. But how about stopping a specific script at run time? If I use the same BSFManager instance for different script, is there any way I can stop them discrimitly?
   
  Linda
  

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
    Just a few remarks:

* to know for sure, you should profile some test runs,
* a BSFManager instance reuses a loaded script engine, so you could
pool BSFManager instances,

  * ad BSF registry/registering beans:
o you could use the same bean registry and register beans
under different names and supply the script the name of the
bean which is meant for it for retrieval in the script;
o also you could create one bean registry which should be
accessible to a group or all invoked scripts by cascading it
with a new instance of the registry meant for it; cf.
getObjectRegistry(), setObjectRegistry(), and of course the
class "org.apache.bsf.util.ObjectRegistry" which has two
constructors, one for supplying a parent ObjectRegistry (for
cascading)

Please let us know how you fare, o.k.?

---rony




 
---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.

Re: overhead of new BSFManager()

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Daling Xu,

Daling Xu wrote:
>  
>   In my project, I need to execute multiple (dosens, even hundreds) JavaScript files at the same time. 
Wow! What is it about?

> And for each script file, I need to register a bean object for it. I need to use that bean in my script file, e.g. 
> myBeanName.method1(). But for each scipt, the bean object should be different. Also, I need to be able to stop specific script files at the run time.
>   To satisfy all these requirements, I start a new BSFManager() for each script file:
>   ...
> Map threadMap = new Hashtable(); //
> ...
>   
... cut ...

>   Then, later when I call beanName.method1() in each script file, I am sure I called it on the correct beanObject instance. Also, I can stop the runnging script for scriptFileX by:
>  Thread t = (Thread) threadMap.get( scriptFileX );
>  t.stop();
>  
>  
> But, I have some consern about the drawback which is the overhead of creating a BSFManager object for each script. By looking at the source code, I notice that each BSFManager maintain the loaded class of the script engine, e.g. JavaScriptEngine here.  Does that mean I am holding dosens even hundreds JavaScriptEngine class loaded in the memory by the former code scripet?? 
>   Now my question is how big is this overhead? How much memory does it take? Can I avoid it? 
>   If I do it this way :
>    BSFManager manager = new BSFManager();
>  
>  for( each scriptFileName ) {
>           
>       String lang = "JavaScript";
>       manager.declareBean("beanName", beanObjectForScriptI, MyBeanClass.class );     
>       manager.exec( lang,
>        "Java", 0, 0, 
>        IOUtils.getStringFromReader(new FileReader(scriptFileName) ));
>  
>  }
>   I am afraid that the declareBean method could overwrite the previously declared bean. Also, how can I stop the script execution for certain script files but keep others running at the runtime?
>   
... cut ...

Just a few remarks:

    * to know for sure, you should profile some test runs,
    * a BSFManager instance reuses a loaded script engine, so you could
      pool BSFManager instances,
    * ad BSF registry/registering beans:
          o you could use the same bean registry and register beans
            under different names and supply the script the name of the
            bean which is meant for it for retrieval in the script;
          o also you could create one bean registry which should be
            accessible to a group or all invoked scripts by cascading it
            with a new instance of the registry meant for it; cf.
            getObjectRegistry(), setObjectRegistry(), and of course the
            class "org.apache.bsf.util.ObjectRegistry" which has two
            constructors, one for supplying a parent ObjectRegistry (for
            cascading)

Please let us know how you fare, o.k.?

---rony