Problem with using classes from different modules

2013-07-01 Thread Johan Jonkers

Hello,

I have been playing around with JCC to see if it would provide in the 
needs we have here at work to interface Java with Python. I have 
encountered one issue in which I hope someone on this mailinglist might 
be able to help me with. If this is not the right place to ask then I 
apologize in advance.


This issue I am having is that I would like to create two packages 
compiled with JCC in which classes from one package are used by classes 
in the other pacakge. I would like to use those classes in Python but am 
having problems doing so that I don't understand yet.


In package 1 is the class shown below:

package nl.seecr.freestyle;

public class Sum {
private int _sum;

public Sum() {
_sum = 0;
}

public void add(int value) {
_sum += value;
}

public int value() {
return _sum;
}
}

The second package holds a class what uses the Sum Class:

package org.cq2.freestyle;

import nl.seecr.freestyle.Sum;

public class SumWrapper {

private Sum total;

public SumWrapper() {
this(new Sum());
System.out.println("Empty constructor");
}

public SumWrapper(Sum sum) {
total = sum;
}

public void add(int value) {
total.add(value);
}

public int value() {
return total.value();
}

public Sum asSum() {
Sum sum = new Sum();
sum.add(value());
return sum;
}

public void printValue() {
System.out.println(value());
}
}

I can compile these classes into .class files and put them in jars and 
have those compiled with JCC:

python -m jcc \
--root ${ROOT} \
--use_full_names \
--shared \
--arch x86_64 \
--jar cq2.jar \
--classpath ./seecr.jar \
--python cq2 \
--build \
--install

export PYTHON_PATH=${ROOT}/usr/local/lib/python2.7/dist-packages
python -m jcc \
--root ${ROOT} \
--use_full_names \
--import cq2 \
--shared \
--arch x86_64 \
--jar seecr.jar \
--python seecr \
--build \
--install

In my understanding the "--import cq2" argument should prevent jcc from 
creating a wrapper for the Sum class in the seecr package itself but use 
the one in the cq2 package.


This all compiles without errors but when I run the following python 
program:


import seecr
seecr.initVM()

import cq2
cq2.initVM()

from nl.seecr.freestyle import Sum
from org.cq2.freestyle import SumWrapper

sum = Sum()
sum.add(5)
print "Sum value", sum.value()

wrapper = SumWrapper(sum)
print wrapper.value()

The 1st print shows the value 5 as expected. The 2nd print however shows 
0 and I had not expected that. If I run the same program in Java and use 
the jars I created earlier, the 2nd print shows 5 (as expected). The 
"Empty constructor" message is also shown when running this python 
program and I had not expected that to happen.


The "asSum" method in the SumWrapper class is not available in the 
Python version of the class. I do not understand yet why that is.


I haven't been able to find many examples or documentation on the 
options for compiling with JCC. I am hoping that someone here on the 
mailinglist can point me in the right direction. Any help would be 
really appreciated.



Johan



Re: [VOTE] Release PyLucene 4.3.1-1

2013-07-01 Thread Michael McCandless
On Sun, Jun 30, 2013 at 10:41 PM, Andi Vajda  wrote:

> And I have now reproduced the problem by forcing '/usr/bin/javac' to be the
> one installed by Oracle's JDK 1.7, even though the original /usr/bin/javac
> reported version 1.7.25. Sheesh, this is user hostile.
>
> Using Oracle's javac to compile Lucene causes the problem to reproduce.

Phew, I'm glad you're able to reproduce, and it's spooky that
compiling Lucene w/ Java7 causes what should be an AtomicReader to
become an IndexReader...

Mike McCandless

http://blog.mikemccandless.com


[jira] [Created] (LUCENE-5086) RamUsageEstimator causes AWT classes to be loaded by calling ManagementFactory#getPlatformMBeanServer (fwd)

2013-07-01 Thread Andi Vajda


We're not alone :-) !

Andi..

-- Forwarded message --
Date: Mon, 1 Jul 2013 17:14:20 + (UTC)
From: "Shay Banon (JIRA)" 
Reply-To: d...@lucene.apache.org
To: d...@lucene.apache.org
Subject: [jira] [Created] (LUCENE-5086) RamUsageEstimator causes AWT classes to
be loaded by calling ManagementFactory#getPlatformMBeanServer

Shay Banon created LUCENE-5086:
--

 Summary: RamUsageEstimator causes AWT classes to be loaded by 
calling ManagementFactory#getPlatformMBeanServer
 Key: LUCENE-5086
 URL: https://issues.apache.org/jira/browse/LUCENE-5086
 Project: Lucene - Core
  Issue Type: Bug
Reporter: Shay Banon


Yea, that type of day and that type of title :).

Since the last update of Java 6 on OS X, I started to see an annoying icon pop 
up at the doc whenever running elasticsearch. By default, all of our scripts 
add headless AWT flag so people will probably not encounter it, but, it was 
strange that I saw it when before I didn't.

I started to dig around, and saw that when RamUsageEstimator was being loaded, 
it was causing AWT classes to be loaded. Further investigation showed that 
actually for some reason, calling ManagementFactory#getPlatformMBeanServer now 
with the new Java version causes AWT classes to be loaded (at least on the mac, 
haven't tested on other platforms yet).

There are several ways to try and solve it, for example, by identifying the bug 
in the JVM itself, but I think that there should be a fix for it in Lucene 
itself, specifically since there is no need to call #getPlatformMBeanServer to 
get the hotspot diagnostics one (its a heavy call...).

Here is a simple call that will allow to get the hotspot mxbean without using 
the #getPlatformMBeanServer method, and not causing it to be loaded and loading 
all those nasty AWT classes:

[code]
Object getHotSpotMXBean() {
Object hotSpotBean = null;
try {
// Java 6
Class sunMF = Class.forName("sun.management.ManagementFactory");
return sunMF.getMethod("getDiagnosticMXBean").invoke(null);
} catch (Throwable t) {
// ignore
}
// potentially Java 7
try {
return ManagementFactory.class.getMethod("getPlatformMXBean", 
Class.class).invoke(null, Class.forName("com.sun.management.HotSpotDiagnosticMXBean"));
} catch (Throwable t) {
// ignore
}
return null;
}
[/code]

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



Re: Problem with using classes from different modules

2013-07-01 Thread Andi Vajda


On Mon, 1 Jul 2013, Johan Jonkers wrote:


Hello,

I have been playing around with JCC to see if it would provide in the needs 
we have here at work to interface Java with Python. I have encountered one 
issue in which I hope someone on this mailinglist might be able to help me 
with. If this is not the right place to ask then I apologize in advance.


This issue I am having is that I would like to create two packages compiled 
with JCC in which classes from one package are used by classes in the other 
pacakge. I would like to use those classes in Python but am having problems 
doing so that I don't understand yet.


In package 1 is the class shown below:

package nl.seecr.freestyle;

public class Sum {
   private int _sum;

   public Sum() {
   _sum = 0;
   }

   public void add(int value) {
   _sum += value;
   }

   public int value() {
   return _sum;
   }
}

The second package holds a class what uses the Sum Class:

package org.cq2.freestyle;

import nl.seecr.freestyle.Sum;

public class SumWrapper {

   private Sum total;

   public SumWrapper() {
   this(new Sum());
   System.out.println("Empty constructor");
   }

   public SumWrapper(Sum sum) {
   total = sum;
   }

   public void add(int value) {
   total.add(value);
   }

   public int value() {
   return total.value();
   }

   public Sum asSum() {
   Sum sum = new Sum();
   sum.add(value());
   return sum;
   }

   public void printValue() {
   System.out.println(value());
   }
}

I can compile these classes into .class files and put them in jars and have 
those compiled with JCC:

python -m jcc \
   --root ${ROOT} \
   --use_full_names \
   --shared \
   --arch x86_64 \
   --jar cq2.jar \
   --classpath ./seecr.jar \
   --python cq2 \
   --build \
   --install

export PYTHON_PATH=${ROOT}/usr/local/lib/python2.7/dist-packages
python -m jcc \
   --root ${ROOT} \
   --use_full_names \
   --import cq2 \
   --shared \
   --arch x86_64 \
   --jar seecr.jar \
   --python seecr \
   --build \
   --install

In my understanding the "--import cq2" argument should prevent jcc from 
creating a wrapper for the Sum class in the seecr package itself but use the 
one in the cq2 package.


This all compiles without errors but when I run the following python program:

import seecr
seecr.initVM()

import cq2
cq2.initVM()

from nl.seecr.freestyle import Sum
from org.cq2.freestyle import SumWrapper

sum = Sum()
sum.add(5)
print "Sum value", sum.value()

wrapper = SumWrapper(sum)
print wrapper.value()

The 1st print shows the value 5 as expected. The 2nd print however shows 0 
and I had not expected that. If I run the same program in Java and use the 
jars I created earlier, the 2nd print shows 5 (as expected). The "Empty 
constructor" message is also shown when running this python program and I had 
not expected that to happen.


The "asSum" method in the SumWrapper class is not available in the Python 
version of the class. I do not understand yet why that is.


I haven't been able to find many examples or documentation on the options for 
compiling with JCC. I am hoping that someone here on the mailinglist can 
point me in the right direction. Any help would be really appreciated.


I haven't had time yet to reproduce the problem but you may want to try to 
add an explicit request to wrap the Sum class - by just listing it on the 
second jcc call command line. No wrapper will be generated for it, because 
of the --import statement, but methods in the second jar with Sum in their 
signature should then get wrapped.


 python -m jcc \
--root ${ROOT} \
--use_full_names \
--import cq2 \
--shared \
--arch x86_64 \
--jar seecr.jar \
--python seecr \
--build \
--install \
nl.seecr.freestyle.Sum

Andi..