-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace generated classes usages by the ProxyHelper.
Update the documentation to mention the two ways,
- Loading branch information
1 parent
daf7196
commit f41e5e6
Showing
6 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...service-provider/src/main/groovy/io/vertx/groovy/examples/service/ProcessorService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2014 Red Hat, Inc. | ||
* | ||
* Red Hat licenses this file to you under the Apache License, version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.vertx.groovy.examples.service; | ||
import groovy.transform.CompileStatic | ||
import io.vertx.lang.groovy.InternalHelper | ||
import io.vertx.groovy.core.Vertx | ||
import io.vertx.core.json.JsonObject | ||
import io.vertx.core.AsyncResult | ||
import io.vertx.core.Handler | ||
/** | ||
* The service interface. | ||
*/ | ||
@CompileStatic | ||
public class ProcessorService { | ||
final def io.vertx.examples.service.ProcessorService delegate; | ||
public ProcessorService(io.vertx.examples.service.ProcessorService delegate) { | ||
this.delegate = delegate; | ||
} | ||
public Object getDelegate() { | ||
return delegate; | ||
} | ||
public static ProcessorService create(Vertx vertx) { | ||
def ret= InternalHelper.safeCreate(io.vertx.examples.service.ProcessorService.create((io.vertx.core.Vertx)vertx.getDelegate()), io.vertx.examples.service.ProcessorService.class, io.vertx.groovy.examples.service.ProcessorService.class); | ||
return ret; | ||
} | ||
public static ProcessorService createProxy(Vertx vertx, String address) { | ||
def ret= InternalHelper.safeCreate(io.vertx.examples.service.ProcessorService.createProxy((io.vertx.core.Vertx)vertx.getDelegate(), address), io.vertx.examples.service.ProcessorService.class, io.vertx.groovy.examples.service.ProcessorService.class); | ||
return ret; | ||
} | ||
public void process(Map<String, Object> document, Handler<AsyncResult<Map<String, Object>>> resultHandler) { | ||
this.delegate.process(document != null ? new io.vertx.core.json.JsonObject(document) : null, new Handler<AsyncResult<io.vertx.core.json.JsonObject>>() { | ||
public void handle(AsyncResult<io.vertx.core.json.JsonObject> event) { | ||
AsyncResult<Map<String, Object>> f | ||
if (event.succeeded()) { | ||
f = InternalHelper.<Map<String, Object>>result((Map<String, Object>)InternalHelper.wrapObject(event.result())) | ||
} else { | ||
f = InternalHelper.<Map<String, Object>>failure(event.cause()) | ||
} | ||
resultHandler.handle(f) | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...amples/service-provider/src/main/resources/vertx-processor-sample-js/processor_service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2014 Red Hat, Inc. | ||
* | ||
* Red Hat licenses this file to you under the Apache License, version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** @module vertx-processor-sample-js/processor_service */ | ||
var utils = require('vertx-js/util/utils'); | ||
|
||
var io = Packages.io; | ||
var JsonObject = io.vertx.core.json.JsonObject; | ||
var JProcessorService = io.vertx.examples.service.ProcessorService; | ||
|
||
/** | ||
The service interface. | ||
@class | ||
*/ | ||
var ProcessorService = function(j_val) { | ||
|
||
var j_processorService = j_val; | ||
var that = this; | ||
|
||
/** | ||
@public | ||
@param document {Object} | ||
@param resultHandler {function} | ||
*/ | ||
this.process = function(document, resultHandler) { | ||
var __args = arguments; | ||
if (__args.length === 2 && typeof __args[0] === 'object' && typeof __args[1] === 'function') { | ||
j_processorService["process(io.vertx.core.json.JsonObject,io.vertx.core.Handler)"](utils.convParamJsonObject(document), function(ar) { | ||
if (ar.succeeded()) { | ||
resultHandler(utils.convReturnJson(ar.result()), null); | ||
} else { | ||
resultHandler(null, ar.cause()); | ||
} | ||
}); | ||
} else utils.invalidArgs(); | ||
}; | ||
|
||
// A reference to the underlying Java delegate | ||
// NOTE! This is an internal API and must not be used in user code. | ||
// If you rely on this property your code is likely to break if we change it / remove it without warning. | ||
this._jdel = j_processorService; | ||
}; | ||
|
||
/** | ||
@memberof module:vertx-processor-sample-js/processor_service | ||
@param vertx {Vertx} | ||
@return {ProcessorService} | ||
*/ | ||
ProcessorService.create = function(vertx) { | ||
var __args = arguments; | ||
if (__args.length === 1 && typeof __args[0] === 'object' && __args[0]._jdel) { | ||
return utils.convReturnVertxGen(JProcessorService["create(io.vertx.core.Vertx)"](vertx._jdel), ProcessorService); | ||
} else utils.invalidArgs(); | ||
}; | ||
|
||
/** | ||
@memberof module:vertx-processor-sample-js/processor_service | ||
@param vertx {Vertx} | ||
@param address {string} | ||
@return {ProcessorService} | ||
*/ | ||
ProcessorService.createProxy = function(vertx, address) { | ||
var __args = arguments; | ||
if (__args.length === 2 && typeof __args[0] === 'object' && __args[0]._jdel && typeof __args[1] === 'string') { | ||
return utils.convReturnVertxGen(JProcessorService["createProxy(io.vertx.core.Vertx,java.lang.String)"](vertx._jdel, address), ProcessorService); | ||
} else utils.invalidArgs(); | ||
}; | ||
|
||
// We export the Constructor function | ||
module.exports = ProcessorService; |
43 changes: 43 additions & 0 deletions
43
...-examples/service-provider/src/main/resources/vertx-processor-sample/processor_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'vertx/util/utils.rb' | ||
# Generated from io.vertx.examples.service.ProcessorService | ||
module VertxProcessorSample | ||
# The service interface. | ||
class ProcessorService | ||
# @private | ||
# @param j_del [::VertxProcessorSample::ProcessorService] the java delegate | ||
def initialize(j_del) | ||
@j_del = j_del | ||
end | ||
# @private | ||
# @return [::VertxProcessorSample::ProcessorService] the underlying java delegate | ||
def j_del | ||
@j_del | ||
end | ||
# @param [::Vertx::Vertx] vertx | ||
# @return [::VertxProcessorSample::ProcessorService] | ||
def self.create(vertx=nil) | ||
if vertx.class.method_defined?(:j_del) && !block_given? | ||
return ::Vertx::Util::Utils.safe_create(Java::IoVertxExamplesService::ProcessorService.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxProcessorSample::ProcessorService) | ||
end | ||
raise ArgumentError, "Invalid arguments when calling create(vertx)" | ||
end | ||
# @param [::Vertx::Vertx] vertx | ||
# @param [String] address | ||
# @return [::VertxProcessorSample::ProcessorService] | ||
def self.create_proxy(vertx=nil,address=nil) | ||
if vertx.class.method_defined?(:j_del) && address.class == String && !block_given? | ||
return ::Vertx::Util::Utils.safe_create(Java::IoVertxExamplesService::ProcessorService.java_method(:createProxy, [Java::IoVertxCore::Vertx.java_class,Java::java.lang.String.java_class]).call(vertx.j_del,address),::VertxProcessorSample::ProcessorService) | ||
end | ||
raise ArgumentError, "Invalid arguments when calling create_proxy(vertx,address)" | ||
end | ||
# @param [Hash{String => Object}] document | ||
# @yield | ||
# @return [void] | ||
def process(document=nil) | ||
if document.class == Hash && block_given? | ||
return @j_del.java_method(:process, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(document),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.encode) : nil : nil) })) | ||
end | ||
raise ArgumentError, "Invalid arguments when calling process(document)" | ||
end | ||
end | ||
end |