You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by "Craig Rickle (JIRA)" <ji...@apache.org> on 2012/08/13 22:26:38 UTC
[jira] [Created] (PYLUCENE-21) JCC Nested Java Object Access from
Python
Craig Rickle created PYLUCENE-21:
------------------------------------
Summary: JCC Nested Java Object Access from Python
Key: PYLUCENE-21
URL: https://issues.apache.org/jira/browse/PYLUCENE-21
Project: PyLucene
Issue Type: Question
Environment: generic
Reporter: Craig Rickle
Priority: Minor
Is it possible to access a nested object from python using jcc?
package home;
public class App
{
public class Embedded {
public void hello2() {
System.out.println("hello from App.Embedded method");
}
}
public void hello() {
System.out.println("hello from App method");
}
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Once processed by jcc,
$ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello();"
hello from App method
is ok, but,
$ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello2();"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'App' object has no attribute 'hello2'
does not resolve. We might say, ok, makes sense, lets try to --rename home.App\$Embedded=AppEmbedded, then, import an AppEmbedded object, but this approach has not worked either in the numerous forms that I have tried.
For completeness, a jar listing follows:
$ jar tf jcc-hello/target/jcc-hello-1.0-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
home/
home/App$Embedded.class
home/App.class
META-INF/maven/
META-INF/maven/home/
META-INF/maven/home/jcc-hello/
META-INF/maven/home/jcc-hello/pom.xml
META-INF/maven/home/jcc-hello/pom.properties
In reality, hello2() will effectively be a result set iterator written by an external group back to the python caller. Current thinking is to segment this portion of code as a new java method and apply jcc for subsequent integration. This would avoid the need to access the nested logic from python, but, would require blocking up the resulting data. Would appreciate any thoughts on this.
Thanks in advance,
Craig
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (PYLUCENE-21) JCC Nested Java Object Access from
Python
Posted by "Andi Vajda (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PYLUCENE-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andi Vajda resolved PYLUCENE-21.
--------------------------------
Resolution: Not A Problem
Please ask questions on pylucene-dev@lucene.apache.org, JIRA is for bugs.
To your question: you didn't give me your JCC invocation so I can only guess that you didn't ask for App$Embedded to be wrapped. The following steps work for me:
$ python -m jcc.__main__ --shared --arch x86_64 --classpath `pwd` home.App home.App\$Embedded --rename home.App\$Embedded=AppEmbedded --python jcchello --build --install
$ python
>>> from jcchello import *
>>> initVM()
<jcc.JCCEnv object at 0x10040a0d8>
>>> App().hello()
hello from App method
>>> AppEmbedded(App()).hello2()
hello from App.Embedded method
>>>
> JCC Nested Java Object Access from Python
> -----------------------------------------
>
> Key: PYLUCENE-21
> URL: https://issues.apache.org/jira/browse/PYLUCENE-21
> Project: PyLucene
> Issue Type: Question
> Environment: generic
> Reporter: Craig Rickle
> Priority: Minor
>
> Is it possible to access a nested object from python using jcc?
> package home;
> public class App
> {
> public class Embedded {
> public void hello2() {
> System.out.println("hello from App.Embedded method");
> }
> }
>
> public void hello() {
> System.out.println("hello from App method");
> }
> public static void main( String[] args )
> {
> System.out.println( "Hello World!" );
> }
> }
> Once processed by jcc,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello();"
> hello from App method
> is ok, but,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello2();"
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> AttributeError: 'App' object has no attribute 'hello2'
> does not resolve. We might say, ok, makes sense, lets try to --rename home.App\$Embedded=AppEmbedded, then, import an AppEmbedded object, but this approach has not worked either in the numerous forms that I have tried.
> For completeness, a jar listing follows:
> $ jar tf jcc-hello/target/jcc-hello-1.0-SNAPSHOT.jar
> META-INF/
> META-INF/MANIFEST.MF
> home/
> home/App$Embedded.class
> home/App.class
> META-INF/maven/
> META-INF/maven/home/
> META-INF/maven/home/jcc-hello/
> META-INF/maven/home/jcc-hello/pom.xml
> META-INF/maven/home/jcc-hello/pom.properties
> In reality, hello2() will effectively be a result set iterator written by an external group back to the python caller. Current thinking is to segment this portion of code as a new java method and apply jcc for subsequent integration. This would avoid the need to access the nested logic from python, but, would require blocking up the resulting data. Would appreciate any thoughts on this.
> Thanks in advance,
> Craig
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (PYLUCENE-21) JCC Nested Java Object Access from
Python
Posted by "Craig Rickle (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PYLUCENE-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436650#comment-13436650 ]
Craig Rickle commented on PYLUCENE-21:
--------------------------------------
apology for continuing in the wrong place
> JCC Nested Java Object Access from Python
> -----------------------------------------
>
> Key: PYLUCENE-21
> URL: https://issues.apache.org/jira/browse/PYLUCENE-21
> Project: PyLucene
> Issue Type: Question
> Environment: generic
> Reporter: Craig Rickle
> Priority: Minor
>
> Is it possible to access a nested object from python using jcc?
> package home;
> public class App
> {
> public class Embedded {
> public void hello2() {
> System.out.println("hello from App.Embedded method");
> }
> }
>
> public void hello() {
> System.out.println("hello from App method");
> }
> public static void main( String[] args )
> {
> System.out.println( "Hello World!" );
> }
> }
> Once processed by jcc,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello();"
> hello from App method
> is ok, but,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello2();"
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> AttributeError: 'App' object has no attribute 'hello2'
> does not resolve. We might say, ok, makes sense, lets try to --rename home.App\$Embedded=AppEmbedded, then, import an AppEmbedded object, but this approach has not worked either in the numerous forms that I have tried.
> For completeness, a jar listing follows:
> $ jar tf jcc-hello/target/jcc-hello-1.0-SNAPSHOT.jar
> META-INF/
> META-INF/MANIFEST.MF
> home/
> home/App$Embedded.class
> home/App.class
> META-INF/maven/
> META-INF/maven/home/
> META-INF/maven/home/jcc-hello/
> META-INF/maven/home/jcc-hello/pom.xml
> META-INF/maven/home/jcc-hello/pom.properties
> In reality, hello2() will effectively be a result set iterator written by an external group back to the python caller. Current thinking is to segment this portion of code as a new java method and apply jcc for subsequent integration. This would avoid the need to access the nested logic from python, but, would require blocking up the resulting data. Would appreciate any thoughts on this.
> Thanks in advance,
> Craig
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (PYLUCENE-21) JCC Nested Java Object Access from
Python
Posted by "Craig Rickle (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PYLUCENE-21?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Craig Rickle updated PYLUCENE-21:
---------------------------------
Very much appreciate your response. I did exclude my jcc invocation. This is a snapshot, where I paired down the pylucene Makefile and adapted to a simple Maven archetype generated project:
python -m jcc.__main__ --arch x86_64 --jar /Users/crickle/jcc/jcc-hello/target/jcc-hello-1.0-SNAPSHOT.jar --rename home.App\$Embedded=AppEmbedded --package java.lang java.lang.System java.lang.Runtime java.lang.IllegalStateException java.lang.IndexOutOfBoundsException --package java.util java.util.Arrays java.util.HashMap java.util.HashSet java.util.No
SuchElementException java.text.SimpleDateFormat java.text.DecimalFormat java.text.Collator --package java.util.regex --package java.io java.io.StringReader java.io.InputStreamRea
der java.io.FileInputStream --python jcchello --mapping java.util.Properties 'getProperty:(Ljava/lang/String;)Ljava/lang/String;' --sequence java.util.AbstractList 'size:()I' 'ge
t:(I)Ljava/lang/Object;' --version 1.0 --files 4 --install
Very much appreciate your simplified example. I replicated it and understand a few points that I was missing. In the above invocation, am I equivalently asking for wrapping by specifying the --jar option for the archive that contains the code to be wrapped? Do I still need --classpath per your provided example?
For now, I have arrived at a solution that is working for us that uses a supplemental function (as described in my initial question) to provide the iteration over the query result set. So far, we haven't really found any problem with this approach, except that the logic spans python and java.
This is an Apache Accumulo interface. The particular class containing the nested class, analogous to App.Embedded.hello2(), is TabletServerBatchReaderIterator:
http://svn.apache.org/viewvc/accumulo/tags/1.4.1/src/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java?view=markup
Getting jcc to recognize MyEntry (listed below) is the actual problem I'm still hoping to solve.
private static class MyEntry implements Entry<Key,Value> {
98
99 private Key key;
100 private Value value;
101
102 MyEntry(Key key, Value value) {
103 this.key = key;
104 this.value = value;
105 }
106
107 @Override
108 public Key getKey() {
109 return key;
110 }
111
112 @Override
113 public Value getValue() {
114 return value;
115 }
116
117 @Override
118 public Value setValue(Value value) {
119 throw new UnsupportedOperationException();
120 }
121
122 }
If this class is contained within a specified --jar argument in the jcc invocation, can I then add a --rename command such that I can refer to the "private" and "static" MyEntry class.
Thanks again for your kind consideration.
Craig
> JCC Nested Java Object Access from Python
> -----------------------------------------
>
> Key: PYLUCENE-21
> URL: https://issues.apache.org/jira/browse/PYLUCENE-21
> Project: PyLucene
> Issue Type: Question
> Environment: generic
> Reporter: Craig Rickle
> Priority: Minor
>
> Is it possible to access a nested object from python using jcc?
> package home;
> public class App
> {
> public class Embedded {
> public void hello2() {
> System.out.println("hello from App.Embedded method");
> }
> }
>
> public void hello() {
> System.out.println("hello from App method");
> }
> public static void main( String[] args )
> {
> System.out.println( "Hello World!" );
> }
> }
> Once processed by jcc,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello();"
> hello from App method
> is ok, but,
> $ python -c "import jcchello;from jcchello import initVM,CLASSPATH,App;initVM(classpath=CLASSPATH);a = App();a.hello2();"
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> AttributeError: 'App' object has no attribute 'hello2'
> does not resolve. We might say, ok, makes sense, lets try to --rename home.App\$Embedded=AppEmbedded, then, import an AppEmbedded object, but this approach has not worked either in the numerous forms that I have tried.
> For completeness, a jar listing follows:
> $ jar tf jcc-hello/target/jcc-hello-1.0-SNAPSHOT.jar
> META-INF/
> META-INF/MANIFEST.MF
> home/
> home/App$Embedded.class
> home/App.class
> META-INF/maven/
> META-INF/maven/home/
> META-INF/maven/home/jcc-hello/
> META-INF/maven/home/jcc-hello/pom.xml
> META-INF/maven/home/jcc-hello/pom.properties
> In reality, hello2() will effectively be a result set iterator written by an external group back to the python caller. Current thinking is to segment this portion of code as a new java method and apply jcc for subsequent integration. This would avoid the need to access the nested logic from python, but, would require blocking up the resulting data. Would appreciate any thoughts on this.
> Thanks in advance,
> Craig
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira