FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PyJavaZ/pyjavaz/wrappers.py at main · PyJavaZ/PyJavaZ · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PyJavaZ
/
PyJavaZ
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
1
Code
Issues
4
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PyJavaZ
/
pyjavaz
/
wrappers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (97 loc) · 3.79 KB
Breadcrumbs
PyJavaZ
/
pyjavaz
/
wrappers.py
Copy path
File metadata and controls
108 lines (97 loc) · 3.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
These classes wrap the ZMQ backend for ease of access
"""
from
pyjavaz
.
bridge
import
_JavaObjectShadow
,
Bridge
,
_DataSocket
import
zmq
DEFAULT_BRIDGE_PORT
=
Bridge
.
DEFAULT_PORT
DEFAULT_BRIDGE_TIMEOUT
=
Bridge
.
DEFAULT_TIMEOUT
class
PullSocket
(
_DataSocket
):
"""
Create and connect to a pull socket on the given port
"""
def
__init__
(
self
,
port
=
Bridge
.
DEFAULT_PORT
,
debug
=
False
,
ip_address
=
"127.0.0.1"
):
_DataSocket
.
__init__
(
self
,
context
=
zmq
.
Context
.
instance
(),
port
=
port
,
type
=
zmq
.
PULL
,
debug
=
debug
,
ip_address
=
ip_address
)
class
PushSocket
(
_DataSocket
):
"""
Create and connect to a pull socket on the given port
"""
def
__init__
(
self
,
port
=
Bridge
.
DEFAULT_PORT
,
debug
=
False
,
ip_address
=
"127.0.0.1"
):
_DataSocket
.
__init__
(
self
,
context
=
zmq
.
Context
.
instance
(),
port
=
port
,
type
=
zmq
.
PUSH
,
debug
=
debug
,
ip_address
=
ip_address
)
class
JavaObject
(
_JavaObjectShadow
):
"""
Instance of a an object on the Java side. Returns a Python "Shadow" of the object, which behaves
just like the object on the Java side (i.e. same methods, fields). Methods of the object can be inferred at
runtime using iPython autocomplete
"""
def
__new__
(
cls
,
classpath
,
args
:
list
=
None
,
port
=
Bridge
.
DEFAULT_PORT
,
timeout
=
Bridge
.
DEFAULT_TIMEOUT
,
new_socket
=
False
,
convert_camel_case
=
True
,
debug
=
False
,
):
"""
classpath: str
Full classpath of the java object
args: list
list of constructor arguments
port: int
The port of the Bridge used to create the object
new_socket: bool
If True, will create new java object on a new port so that blocking calls will not interfere
with the bridges main port
convert_camel_case : bool
If True, methods for Java objects that are passed across the bridge
will have their names converted from camel case to underscores. i.e. class.methodName()
becomes class.method_name()
debug:
print debug messages
"""
bridge
=
Bridge
.
create_or_get_existing_bridge
(
port
=
port
,
timeout
=
timeout
,
convert_camel_case
=
convert_camel_case
,
debug
=
debug
)
return
bridge
.
_construct_java_object
(
classpath
,
new_socket
=
new_socket
,
args
=
args
)
class
JavaClass
(
_JavaObjectShadow
):
"""
Get an an object corresponding to a java class, for example to be used
when calling static methods on the class directly
"""
def
__new__
(
cls
,
classpath
,
port
=
Bridge
.
DEFAULT_PORT
,
timeout
=
Bridge
.
DEFAULT_TIMEOUT
,
new_socket
=
False
,
convert_camel_case
=
True
,
debug
=
False
,
):
"""
classpath: str
Full classpath of the java calss
port: int
The port of the Bridge used to create the object
new_socket: bool
If True, will create new java object on a new port so that blocking calls will not interfere
with the bridges main port
convert_camel_case : bool
If True, methods for Java objects that are passed across the bridge
will have their names converted from camel case to underscores. i.e. class.methodName()
becomes class.method_name()
debug:
print debug messages
"""
bridge
=
Bridge
.
create_or_get_existing_bridge
(
port
=
port
,
timeout
=
timeout
,
convert_camel_case
=
convert_camel_case
,
debug
=
debug
)
return
bridge
.
_get_java_class
(
classpath
,
new_socket
=
new_socket
)
Back
|
FazBrowse Home
|
New Git URL