[Runtime Code Changes] ideas...

B

Bogus Exception

I'm curious as to which approaches exist for defining and running Java
code at run time in EJB3. For example, programmatically defining an
entity, or other, bean.

My program wants to take code written by a user and incorporate it
into the running system. For speed (and other?) considerations,
BeanShell appears to be an unwise choice, right? This leaves me with
crafting a complete Java class in a string, then compiling and copying
to ./deploy, right?

If BeanShell is parsed (like any other interpreted language) each and
every time it is run, then it may well be a lot slower than writing
source, compiling it, and running in the container, right?

TIA for any experiences and/or insights!
 
D

Daniel Pitts

I'm curious as to which approaches exist for defining and running Java
code at run time in EJB3. For example, programmatically defining an
entity, or other, bean.

My program wants to take code written by a user and incorporate it
into the running system. For speed (and other?) considerations,
BeanShell appears to be an unwise choice, right? This leaves me with
crafting a complete Java class in a string, then compiling and copying
to ./deploy, right?

If BeanShell is parsed (like any other interpreted language) each and
every time it is run, then it may well be a lot slower than writing
source, compiling it, and running in the container, right?

TIA for any experiences and/or insights!

Why not have the end-user compile and upload the code? Or better yet,
use RMI's capability in that regard. BTW, it sounds like a bad idea.
Unless you have really strict and secure access. As soon as someone
can run arbitrary code on your end, then someone can run malicious
code on your end.
 
L

Lew

Daniel said:
Why not have the end-user compile and upload the code? Or better yet,
use RMI's capability in that regard. BTW, it sounds like a bad idea.
Unless you have really strict and secure access. As soon as someone
can run arbitrary code on your end, then someone can run malicious
code on your end.

Actually, Java is a good environment for doing exactly that, with great
caution and not without risk. You can bring foreign classes in via a custom
ClassLoader that isolates the suspect code from doing undo damage.

I'm no expert in that, and I sure wouldn't tread there lightly, but I've heard
tell of such schemes.

This is not the same as to "incorporate it into the running system", perhaps,
if by that the OP means without such walls of protection.

Jini is another approach for runtime discovery and connection to components.

The workable approaches provide mechanisms for "really strict and secure access".

I don't know how one can make /a priori/ judgments about the speed of
BeanShell vs. other approaches. What is it that would make BeanShell slow,
and for what meaning of slow.
 
B

B☼gus Excepti☼n

Great answers Lew & Daniel,

I don't want the user to do any compiling at all.I want them to enter
code in a window/form and have that code run in a bean at runtime. You
know... they enter their own business logic. I'm just curious what the
best way to do so might be.

Thanks!
 
R

Roedy Green

I don't want the user to do any compiling at all.I want them to enter
code in a window/form and have that code run in a bean at runtime. You
know... they enter their own business logic. I'm just curious what the
best way to do so might be.

Obviously SOMETHING has to parse the source and convert it into
something executable. The usual thing to do that is javac or the
on-the-fly equivalents.

Perhaps what you mean is you don't want the user to be involved in any
way with the compilation process. It should happen transparently.

see http://mindprod.com/jgloss/onthefly.html
 
B

B☼gus Excepti☼n

Roedy,

Thanks for writing. See below inline...

On Nov 30, 2:28 am, Roedy Green <[email protected]>
wrote:
[...]
Obviously SOMETHING has to parse the source and convert it into
something executable. The usual thing to do that is javac or the
on-the-fly equivalents.

Exactly. And this is why I have posted the inquiry. There seem to be 2
choices, and I can't determine the differences between them. I see the
choices as:

1. An actual compile into a class, and create/copy that class into a
jar, then copying that jar file into the ./deploy dir (my prototype is
JBoss 4).
2. Have the user fill in BeanShell, and run that.

I am very concerned about the speed of BeanShell in comparison to
compiled classes. Unfortunately, I need performance centered around
creating objects based on the user code at a very high rate. If I need
to parse BeanShell every time an object is instantiated, then it will
probably be exponentially slower than a compiled class, no?
Perhaps what you mean is you don't want the user to be involved in any
way with the compilation process. It should happen transparently.

Exactly. I just want them to configure any business logic, save their
session/work, and it just works.

I just don't know anything about the performance risks associated with
BeanShell, or whether there is another, oblique option I am not even
aware of.

Thanks again for writing!
 
D

Daniel Pitts

Apologies to Bogus, I've had to sanitize the encoding of your name.
Bogus said:
Roedy,

Thanks for writing. See below inline...

On Nov 30, 2:28 am, Roedy Green <[email protected]>
wrote:
[...]
Obviously SOMETHING has to parse the source and convert it into
something executable. The usual thing to do that is javac or the
on-the-fly equivalents.

Exactly. And this is why I have posted the inquiry. There seem to be 2
choices, and I can't determine the differences between them. I see the
choices as:

1. An actual compile into a class, and create/copy that class into a
jar, then copying that jar file into the ./deploy dir (my prototype is
JBoss 4).
2. Have the user fill in BeanShell, and run that.

I am very concerned about the speed of BeanShell in comparison to
compiled classes. Unfortunately, I need performance centered around
creating objects based on the user code at a very high rate. If I need
to parse BeanShell every time an object is instantiated, then it will
probably be exponentially slower than a compiled class, no?
Perhaps what you mean is you don't want the user to be involved in any
way with the compilation process. It should happen transparently.

Exactly. I just want them to configure any business logic, save their
session/work, and it just works.

I just don't know anything about the performance risks associated with
BeanShell, or whether there is another, oblique option I am not even
aware of.

Thanks again for writing!
Or you could have them submit a Java source file and compile on the
remote end, and automatically handle the deployments there.

You might even make it into a HTML form where they can type the Java
source text in there. Although in reality, if the client needs this
kind of customizable software, then they probably should be savvy enough
to use a full fledged compiler/ide/etc...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top