Hi Mike,
Yes, you can do this with Py4J. I actually used it in a similar fashion
with Eclipse. I was tired to restart Eclipse every time I made a change to
a plug-in so I just installed Py4J in Eclipse and then, I accessed Eclipse
using a Python shell. After experimenting for a while with the shell, I
copied the code to a Python program (or translated it to Java when it made
sense).
With Py4J, you can also write a Python class that implements a Java
interface and you can pass it to the JVM. This allows a Python program (or
a Python shell), to receive a callback from Java, which seems to fit your
scenario here. The only thing you cannot do right now is extend a Java
abstract class in Python (it's on my todo list).
Py4J also supports many-to-many connections between Python interpreters
and JVMs: you can safely connect multiple python interpreters on the same
JVM, restart an interpreter and reconnect to the same JVM, etc.
Another handy tool from Py4J is that you can use introspection on Java
objects. This might be helpful if you don't know the types in your agent's
state. For example, in Eclipse, you often get Object instances that you
need to cast. With Py4J, you can call a method on the object and you will
get its type and the methods and fields that are accessible.
Hope this helps,
Barthélémy
On Thu, April 14, 2011 2:05 pm, Bourassa, Mike wrote:
> Hi there. I'm Mike Bourassa. I have a question about whether P4J has a
> functionality I'm seeking.
>
>
>
> I have been working with Netlogo (http://ccl.northwestern.edu/netlogo/),
> an agent development environment. While it is a very nice system, I have
> reached a stage where I would like to do some more exotic agent behaviour.
> While Netlogo is easy to program in, I need to use more
> complex algorithms that exist in libraries for Java, Python, etc. Netlogo
> allows me to write extensions; essentially I write a program, create a
> .jar, and Netlogo can call the contents of the .jar.
>
>
>
>
> In my current set-up, each agent in Netlogo at some point calls the
> extension .jar. The .jar contains methods that provide decision making for
> the agents; state data goes in, a decision comes out. The problem is
> every time I change the decision making algorithm I have to: shut down
> Netlogo, alter program, create .jar, restart Netlogo. So I
> thought, what if the extension just holds the state data and returns a
> decision, while I use a Python program to do the decision making. That
> is, the .jar extension would hold the state data and using P4J, a Python
> program would access the data and return a decision which the extension
> would then pass back to Netlogo. The advantage would be that I could
> alter the Python program without having to recreate a .jar and shutdown
> Netlogo every time.
>
>
>
>
> So: does that make any sense and could P4J help me achieve my goal?
> Thanks in advance for any assistance.
>
>
>
>
> Mike Bourassa
>
>
>
>
> -
>
>
>
>
>
|