17
17
use exonum:: {
18
18
blockchain:: Blockchain ,
19
19
crypto:: { Hash , PublicKey } ,
20
- exonum_merkledb:: Snapshot ,
21
- messages:: BinaryValue ,
20
+ exonum_merkledb:: { BinaryValue , Snapshot } ,
22
21
runtime:: {
23
- ArtifactId , CallInfo , Caller , ExecutionContext , ExecutionError , ExecutionFail , InstanceId ,
24
- InstanceSpec , InstanceStatus , Mailbox , Runtime , RuntimeIdentifier , SnapshotExt ,
25
- WellKnownRuntime ,
22
+ ArtifactId , CallInfo , Caller , ExecutionContext , ExecutionError , InstanceId , InstanceSpec ,
23
+ InstanceStatus , Mailbox , Runtime , RuntimeIdentifier , SnapshotExt , WellKnownRuntime ,
26
24
} ,
27
25
} ;
28
26
use futures:: { Future , IntoFuture } ;
@@ -66,17 +64,6 @@ impl JavaRuntimeProxy {
66
64
}
67
65
}
68
66
69
- fn parse_artifact ( & self , artifact : & ArtifactId ) -> Result < JavaArtifactId , ExecutionError > {
70
- if artifact. runtime_id != JAVA_RUNTIME_ID {
71
- Err ( Error :: IllegalArgument . with_description ( format ! (
72
- "Invalid runtime ID ({}), {} expected" ,
73
- artifact. runtime_id, JAVA_RUNTIME_ID
74
- ) ) )
75
- } else {
76
- Ok ( JavaArtifactId ( artifact. name . to_string ( ) ) )
77
- }
78
- }
79
-
80
67
/// If the current node is a validator, returns its ID, otherwise returns `-1`.
81
68
fn validator_id ( snapshot : & dyn Snapshot , pub_key : & PublicKey ) -> i32 {
82
69
snapshot
@@ -106,16 +93,13 @@ impl Runtime for JavaRuntimeProxy {
106
93
107
94
fn deploy_artifact (
108
95
& mut self ,
109
- artifact : ArtifactId ,
96
+ artifact_id : ArtifactId ,
110
97
deploy_spec : Vec < u8 > ,
111
98
) -> Box < dyn Future < Item = ( ) , Error = ExecutionError > > {
112
- let id = match self . parse_artifact ( & artifact) {
113
- Ok ( id) => id. to_string ( ) ,
114
- Err ( err) => return Box :: new ( Err ( err) . into_future ( ) ) ,
115
- } ;
99
+ let serialized_artifact_id: Vec < u8 > = artifact_id. to_bytes ( ) ;
116
100
117
101
let result = jni_call_default ( & self . exec , |env| {
118
- let artifact_id = JObject :: from ( env. new_string ( id ) ?) ;
102
+ let artifact_id = JObject :: from ( env. byte_array_from_slice ( & serialized_artifact_id ) ?) ;
119
103
let spec = JObject :: from ( env. byte_array_from_slice ( & deploy_spec) ?) ;
120
104
121
105
env. call_method_unchecked (
@@ -130,16 +114,11 @@ impl Runtime for JavaRuntimeProxy {
130
114
Box :: new ( result. map ( |_| ( ) ) . into_future ( ) )
131
115
}
132
116
133
- fn is_artifact_deployed ( & self , id : & ArtifactId ) -> bool {
134
- let artifact = match self . parse_artifact ( id) {
135
- Ok ( id) => id. to_string ( ) ,
136
- Err ( _) => {
137
- return false ;
138
- }
139
- } ;
117
+ fn is_artifact_deployed ( & self , artifact_id : & ArtifactId ) -> bool {
118
+ let serialized_artifact_id: Vec < u8 > = artifact_id. to_bytes ( ) ;
140
119
141
120
unwrap_jni ( self . exec . with_attached ( |env| {
142
- let artifact_id = JObject :: from ( env. new_string ( artifact ) ?) ;
121
+ let artifact_id = JObject :: from ( env. byte_array_from_slice ( & serialized_artifact_id ) ?) ;
143
122
144
123
panic_on_exception (
145
124
env,
@@ -187,21 +166,24 @@ impl Runtime for JavaRuntimeProxy {
187
166
_snapshot : & dyn Snapshot ,
188
167
instance_spec : & InstanceSpec ,
189
168
status : InstanceStatus ,
190
- ) -> Result < ( ) , ExecutionError > {
169
+ ) {
191
170
let serialized_instance_spec: Vec < u8 > = instance_spec. to_bytes ( ) ;
192
- jni_call_default ( & self . exec , |env| {
171
+ unwrap_jni ( self . exec . with_attached ( |env| {
193
172
let instance_spec =
194
173
JObject :: from ( env. byte_array_from_slice ( & serialized_instance_spec) ?) ;
195
174
let instance_status = status as i32 ;
196
175
197
- env. call_method_unchecked (
198
- self . runtime_adapter . as_obj ( ) ,
199
- runtime_adapter:: update_service_status_id ( ) ,
200
- JavaType :: Primitive ( Primitive :: Void ) ,
201
- & [ JValue :: from ( instance_spec) , JValue :: from ( instance_status) ] ,
202
- )
203
- . and_then ( JValue :: v)
204
- } )
176
+ panic_on_exception (
177
+ env,
178
+ env. call_method_unchecked (
179
+ self . runtime_adapter . as_obj ( ) ,
180
+ runtime_adapter:: update_service_status_id ( ) ,
181
+ JavaType :: Primitive ( Primitive :: Void ) ,
182
+ & [ JValue :: from ( instance_spec) , JValue :: from ( instance_status) ] ,
183
+ ) ,
184
+ ) ;
185
+ Ok ( ( ) )
186
+ } ) ) ;
205
187
}
206
188
207
189
fn execute (
@@ -336,13 +318,3 @@ impl fmt::Debug for JavaRuntimeProxy {
336
318
impl WellKnownRuntime for JavaRuntimeProxy {
337
319
const ID : u32 = JAVA_RUNTIME_ID ;
338
320
}
339
-
340
- /// Artifact identification properties within `JavaRuntimeProxy`
341
- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
342
- pub struct JavaArtifactId ( String ) ;
343
-
344
- impl fmt:: Display for JavaArtifactId {
345
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
346
- write ! ( f, "{}" , self . 0 )
347
- }
348
- }
0 commit comments