Re: removing and readding actors to a model

2003-11-24 Thread Edward A Lee
Ah, this sounds like an extremely useful capability...

Java has a hot-swap capability... This is used, for example,
by Eclipse when you modify and recompile a piece of code while
the debugger is running. So to some extent, you get this for
free if you use Eclipse as the development environment.
However, I suspect this hot-swap capability is tricky to use...
Sometimes Eclipse reports that a hot swap isn't
possible for some instances...  I'm not sure what the
criteria are for determining whether hot swap is possible.
Anybody out there know more about this?
BTW: The capabilities you are describing here would probably
be most useful if they were folded in to the main Ptolemy II tree...
However, keep in mind that we can't fold in GPL'd code, because
then the GPL terms spread to the entire system...
Edward



At 08:38 AM 11/24/2003 -0800, Chad Berkley wrote:
hi edward,

sorry, I should have told you what I was doing.  I've already written a 
utility to create actor code, compile it and then put it into the actor 
library.  Now, I'm trying to use the same GUI that I developed to open an 
existing actor, modify it, recompile it then update the relevant models 
(those being the actorLibrary and the model that the edit request came 
from).  Is there an easier way to get the models to update with the new 
actor information?

thanks,
chad
Edward A Lee wrote:
Shouldn't removing the actor also be done in a ChangeRequest?
This seems like a very puzzling thing to do... What are you trying
to accomplish?
Edward
At 10:34 AM 11/21/2003 -0800, Chad Berkley wrote:
hi,

I'm trying to remove and actor from the actorLibrary model, change it, 
then re-add it.  For some reason, when it re-adds, you don't see the 
changes that were made.

Here's the code that I'm using:

List l = actorLibrary.entityList();
for(int i=0; il.size(); i++)
{  //look for the actor in the container.if it's there, remove it
  ComponentEntity ce = (ComponentEntity)l.get(i);
  if(ce.getName().equals(actor.getName()))
  {
try
{
  ce.setContainer(null); //remove the found entity
  StringWriter buffer = new StringWriter();
  ce.exportMoML(buffer, 1);
  ChangeRequest request = new MoMLChangeRequest(ce, actorLibrary,
buffer.toString());
  actorLibrary.requestChange(request);
  break;
}
catch(Exception e)
{
  throw new RuntimeException(Error removing existing actor from  +
container:  + e.getMessage());
}
  }
}
actor.setContainer(actorLibrary);
StringWriter buffer = new StringWriter();
actor.exportMoML(buffer, 1);
ChangeRequest request = new MoMLChangeRequest(actor, actorLibrary,
  buffer.toString());
actorLibrary.requestChange(request);
When the ChangeRequest is made within the loop, it seems to *add* the 
actor to the library instead of remove it, even though I set the 
container to null.  Vergil gives me an error when it hits the 2nd 
ChangeRequest saying that there is already an Entity with the same name 
in the model.  If I remove the ChangeRequest within the loop, it appears 
to work (i.e. it does not give any error when it leaves the loop and 
resets the container) but it does not, in fact, update the model.

Any ideas?

thanks,
chad
--
---
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
---
 

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


--
---
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
---

Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]


Re: removing and readding actors to a model

2003-11-24 Thread Matt Jones
Chad,

I think that you need to consider the classloader issues in order to be 
able to do this.  The JVM loads a class using the default ClassLoader -- 
which I think caches the class so that it needn't load it again. 
So...even if you get it reinserted into the Ptolemy hierarchy, the JVM 
will still use the original class unless you override the ClassLoader. 
In the examples I have seem of dynamic recompilation, the application 
has had to replace the default ClassLoader with a custom one that knows 
to check for new compiled versions when the JVM asks for a class to be 
loaded.  I sent you a Java tutorial a few months ago about this when I 
was thinking about the design of the reloadable actors for Kepler.  I 
can drag this out again if you'd like if you don't have the original email.

Matt

Hope this helps,

Matt

Edward A Lee wrote:

Ah, this sounds like an extremely useful capability...

Java has a hot-swap capability... This is used, for example,
by Eclipse when you modify and recompile a piece of code while
the debugger is running. So to some extent, you get this for
free if you use Eclipse as the development environment.
However, I suspect this hot-swap capability is tricky to use...
Sometimes Eclipse reports that a hot swap isn't
possible for some instances...  I'm not sure what the
criteria are for determining whether hot swap is possible.
Anybody out there know more about this?
BTW: The capabilities you are describing here would probably
be most useful if they were folded in to the main Ptolemy II tree...
However, keep in mind that we can't fold in GPL'd code, because
then the GPL terms spread to the entire system...
Edward



At 08:38 AM 11/24/2003 -0800, Chad Berkley wrote:

hi edward,

sorry, I should have told you what I was doing.  I've already written 
a utility to create actor code, compile it and then put it into the 
actor library.  Now, I'm trying to use the same GUI that I developed 
to open an existing actor, modify it, recompile it then update the 
relevant models (those being the actorLibrary and the model that the 
edit request came from).  Is there an easier way to get the models to 
update with the new actor information?

thanks,
chad
Edward A Lee wrote:

Shouldn't removing the actor also be done in a ChangeRequest?
This seems like a very puzzling thing to do... What are you trying
to accomplish?
Edward
At 10:34 AM 11/21/2003 -0800, Chad Berkley wrote:
hi,

I'm trying to remove and actor from the actorLibrary model, change 
it, then re-add it.  For some reason, when it re-adds, you don't see 
the changes that were made.

Here's the code that I'm using:

List l = actorLibrary.entityList();
for(int i=0; il.size(); i++)
{  //look for the actor in the container.if it's there, remove it
  ComponentEntity ce = (ComponentEntity)l.get(i);
  if(ce.getName().equals(actor.getName()))
  {
try
{
  ce.setContainer(null); //remove the found entity
  StringWriter buffer = new StringWriter();
  ce.exportMoML(buffer, 1);
  ChangeRequest request = new MoMLChangeRequest(ce, actorLibrary,
buffer.toString());
  actorLibrary.requestChange(request);
  break;
}
catch(Exception e)
{
  throw new RuntimeException(Error removing existing actor from 
 +
container:  + e.getMessage());
}
  }
}

actor.setContainer(actorLibrary);
StringWriter buffer = new StringWriter();
actor.exportMoML(buffer, 1);
ChangeRequest request = new MoMLChangeRequest(actor, actorLibrary,
  buffer.toString());
actorLibrary.requestChange(request);
When the ChangeRequest is made within the loop, it seems to *add* 
the actor to the library instead of remove it, even though I set the 
container to null.  Vergil gives me an error when it hits the 2nd 
ChangeRequest saying that there is already an Entity with the same 
name in the model.  If I remove the ChangeRequest within the loop, 
it appears to work (i.e. it does not give any error when it leaves 
the loop and resets the container) but it does not, in fact, update 
the model.

Any ideas?

thanks,
chad
--
---
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
---
 

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: 
[EMAIL PROTECTED]



Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


--
---
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
---



Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal
 

Posted 

Re: removing and readding actors to a model

2003-11-24 Thread Stephen Andrew Neuendorffer
I think it makes more sense to use Java's classloader to do this  (as Matt 
suggests) rather than hot-swap.
With hot-swap, the classes are expected to be consistent with one another 
(as with a debugger, for instance)
Since there is no way to ensure this, an exception will likely result.

We've talked several times about doing this, but it always seemed very 
tricky.  In particular, you'd have to reload the library,
and reload some/all of the loaded models with the new class loader.  There 
is a facility for this in the MoMLParser
(A constructor that takes a class loader).  However, only some changes can 
be made while keeping the classes consistent with the
model, so there seem to be some trickiness in representing this to the user 
in a consistent way.

FYI: The key to doing this in Java is that classes accessible to your class 
loader should not
be accessible to the standard class loader.  (i.e. they must be in a 
classpath that is not accessible from $PTII).
If you follow this constraint, then it is relatively easy to implement 
using the URLClassLoader class.

Steve

At 11:19 AM 11/24/2003 -0900, Matt Jones wrote:
Chad,

I think that you need to consider the classloader issues in order to be 
able to do this.  The JVM loads a class using the default ClassLoader -- 
which I think caches the class so that it needn't load it again. So...even 
if you get it reinserted into the Ptolemy hierarchy, the JVM will still 
use the original class unless you override the ClassLoader. In the 
examples I have seem of dynamic recompilation, the application has had to 
replace the default ClassLoader with a custom one that knows to check for 
new compiled versions when the JVM asks for a class to be loaded.  I sent 
you a Java tutorial a few months ago about this when I was thinking about 
the design of the reloadable actors for Kepler.  I can drag this out again 
if you'd like if you don't have the original email.

Matt

Hope this helps,

Matt

Edward A Lee wrote:

Ah, this sounds like an extremely useful capability...
Java has a hot-swap capability... This is used, for example,
by Eclipse when you modify and recompile a piece of code while
the debugger is running. So to some extent, you get this for
free if you use Eclipse as the development environment.
However, I suspect this hot-swap capability is tricky to use...
Sometimes Eclipse reports that a hot swap isn't
possible for some instances...  I'm not sure what the
criteria are for determining whether hot swap is possible.
Anybody out there know more about this?
BTW: The capabilities you are describing here would probably
be most useful if they were folded in to the main Ptolemy II tree...
However, keep in mind that we can't fold in GPL'd code, because
then the GPL terms spread to the entire system...
Edward
At 08:38 AM 11/24/2003 -0800, Chad Berkley wrote:

hi edward,

sorry, I should have told you what I was doing.  I've already written a 
utility to create actor code, compile it and then put it into the actor 
library.  Now, I'm trying to use the same GUI that I developed to open 
an existing actor, modify it, recompile it then update the relevant 
models (those being the actorLibrary and the model that the edit request 
came from).  Is there an easier way to get the models to update with the 
new actor information?

thanks,
chad
Edward A Lee wrote:

Shouldn't removing the actor also be done in a ChangeRequest?
This seems like a very puzzling thing to do... What are you trying
to accomplish?
Edward
At 10:34 AM 11/21/2003 -0800, Chad Berkley wrote:
hi,

I'm trying to remove and actor from the actorLibrary model, change it, 
then re-add it.  For some reason, when it re-adds, you don't see the 
changes that were made.

Here's the code that I'm using:

List l = actorLibrary.entityList();
for(int i=0; il.size(); i++)
{  //look for the actor in the container.if it's there, remove it
  ComponentEntity ce = (ComponentEntity)l.get(i);
  if(ce.getName().equals(actor.getName()))
  {
try
{
  ce.setContainer(null); //remove the found entity
  StringWriter buffer = new StringWriter();
  ce.exportMoML(buffer, 1);
  ChangeRequest request = new MoMLChangeRequest(ce, actorLibrary,
buffer.toString());
  actorLibrary.requestChange(request);
  break;
}
catch(Exception e)
{
  throw new RuntimeException(Error removing existing actor from  +
container:  + e.getMessage());
}
  }
}
actor.setContainer(actorLibrary);
StringWriter buffer = new StringWriter();
actor.exportMoML(buffer, 1);
ChangeRequest request = new MoMLChangeRequest(actor, actorLibrary,
  buffer.toString());
actorLibrary.requestChange(request);
When the ChangeRequest is made within the loop, it seems to *add* the 
actor to the library instead of remove it, even though I set the 
container to null.  Vergil gives me an error when it hits the 2nd 
ChangeRequest saying that there is already an Entity with the same 
name in the model.  If I remove the 

Re: removing and readding actors to a model

2003-11-22 Thread Edward A Lee
Shouldn't removing the actor also be done in a ChangeRequest?

This seems like a very puzzling thing to do... What are you trying
to accomplish?
Edward

At 10:34 AM 11/21/2003 -0800, Chad Berkley wrote:
hi,

I'm trying to remove and actor from the actorLibrary model, change it, 
then re-add it.  For some reason, when it re-adds, you don't see the 
changes that were made.

Here's the code that I'm using:

List l = actorLibrary.entityList();
for(int i=0; il.size(); i++)
{  //look for the actor in the container.if it's there, remove it
  ComponentEntity ce = (ComponentEntity)l.get(i);
  if(ce.getName().equals(actor.getName()))
  {
try
{
  ce.setContainer(null); //remove the found entity
  StringWriter buffer = new StringWriter();
  ce.exportMoML(buffer, 1);
  ChangeRequest request = new MoMLChangeRequest(ce, actorLibrary,
buffer.toString());
  actorLibrary.requestChange(request);
  break;
}
catch(Exception e)
{
  throw new RuntimeException(Error removing existing actor from  +
container:  + e.getMessage());
}
  }
}
actor.setContainer(actorLibrary);
StringWriter buffer = new StringWriter();
actor.exportMoML(buffer, 1);
ChangeRequest request = new MoMLChangeRequest(actor, actorLibrary,
  buffer.toString());
actorLibrary.requestChange(request);
When the ChangeRequest is made within the loop, it seems to *add* the 
actor to the library instead of remove it, even though I set the container 
to null.  Vergil gives me an error when it hits the 2nd ChangeRequest 
saying that there is already an Entity with the same name in the 
model.  If I remove the ChangeRequest within the loop, it appears to work 
(i.e. it does not give any error when it leaves the loop and resets the 
container) but it does not, in fact, update the model.

Any ideas?

thanks,
chad
--
---
Chad Berkley
National Center for
Ecological Analysis
and Synthesis (NCEAS)
[EMAIL PROTECTED]
---

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]