I get some data from cassandra's jmx. one element is defined like this. https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java#L358
The returned type in Java is int[];
import xml.etree.ElementTree as xml
text = requests.get('http://:8081/mbean?objectname=org.apache.cassandra.db:type=xxx,keyspace=x,columnfamily=x&template=identity').text
x = xml.fromstring(text)
>>> for i in x:
... if i.get('name') == 'SSTableCountPerLevel':
... p=i
>>> p.items()
[('description', 'Attribute exposed for management'), ('aggregation', 'array'), ('value', '[I@48a6ea00'), ('isnull', 'false'), ('strinit', 'false'), ('type', '[I'), ('availability', 'RO'), ('name', 'SSTableCountPerLevel')]
>>> p.get('value')
'[I@48a6ea00'
So How can I convert this [I@48a6ea00 to a list of int in python?
@update 1:
Seems JPY is here for this purpose, but since the lack of document, I will try this and give a update soon.
>>> import jpyutil
>>> jpyutil.init_jvm(jvm_maxmem='512M')
>>> import jpy
>>> b = jpy.array('int', [1,2,3])
>>> b.toString()
'[I@3f2a09d5'
>>> b
[I(objectRef=0x7fa66340dfe8)
>>> b[0]
1L
>>> b[2]
3L
>>> dir(b)
['__class__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__jinit__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'toString', 'wait']
But I still can't convert string to Python List, which is I want.
@ conclusion:
Decode Java int array in python code should be possible if the python knows the content of java int array, but in the above case, [I@48a6ea00 is not the content of java int array, it is a memory reference to the java int array, so it is impossible.
I got this string via MX4J, I will check MX4J document to see how MX4j handle array.
@ update 2:
After checked the MX4J doucment, it is clearly stated with
Obviously it has some limitations, like not being able to manipulate data which cannot be obtained from Strings
At last, I used JYTHON, it resolves my issue perfectly.