org.vertx.java.core.AsyncResult Java Examples
The following examples show how to use
org.vertx.java.core.AsyncResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaModuleDeployWithStatsdDisabledConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); config.putBoolean("statsd.enabled", false); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithStatsdDisabledConfigIT.super.start(); } }); }
Example #2
Source File: WebSocketBusTest.java From realtime-channel with Apache License 2.0 | 6 votes |
@Override public void start() { initialize(); VertxPlatform.register(vertx); // Deploy the module - the System property `vertx.modulename` will contain the name of the // module so you don't have to hardecode it in your tests container.deployModule(System.getProperty("vertx.modulename"), new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("deploymentID should not be null", asyncResult.result()); bus = new ReconnectBus("ws://localhost:1986/channel/websocket", null); startTests(); } }); }
Example #3
Source File: VertxBusTest.java From realtime-channel with Apache License 2.0 | 6 votes |
@Override public void start() { initialize(); // Deploy the module - the System property `vertx.modulename` will contain the name of the // module so you don't have to hardecode it in your tests container.deployModule(System.getProperty("vertx.modulename"), new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("deploymentID should not be null", asyncResult.result()); bus = new VertxBus(vertx.eventBus()); startTests(); } }); }
Example #4
Source File: ChannelBridge.java From realtime-channel with Apache License 2.0 | 6 votes |
public void bridge(final CountingCompletionHandler<Void> countDownLatch) { HttpServer server = vertx.createHttpServer(); SockJSServer sjsServer = vertx.createSockJSServer(server).setHook(hook); JsonObject empty = new JsonObject(); JsonArray all = new JsonArray().add(empty); JsonArray inboundPermitted = config.getArray("inbound_permitted", all); JsonArray outboundPermitted = config.getArray("outbound_permitted", all); sjsServer.bridge(config.getObject("sjs_config", new JsonObject() .putString("prefix", "/channel")), inboundPermitted, outboundPermitted, config.getObject( "bridge_config", empty)); countDownLatch.incRequired(); server.listen(config.getInteger("port", 1986), config.getString("host", "0.0.0.0"), new AsyncResultHandler<HttpServer>() { @Override public void handle(AsyncResult<HttpServer> ar) { if (!ar.succeeded()) { countDownLatch.failed(ar.cause()); } else { countDownLatch.complete(); } } }); }
Example #5
Source File: VertxBus.java From realtime-channel with Apache License 2.0 | 6 votes |
@Override public void close() { if (hook == null || hook.handlePreClose()) { state = State.CLOSING; localBus.close(); eb.close(new org.vertx.java.core.Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> ar) { if (ar.succeeded()) { state = State.CLOSED; if (hook != null) { hook.handlePostClose(); } } else { log.log(Level.SEVERE, "Failed to close EventBus", ar.cause()); } } }); } }
Example #6
Source File: ChannelVerticle.java From realtime-channel with Apache License 2.0 | 6 votes |
@Override public void start(final Future<Void> startedResult) { super.start(); final CountingCompletionHandler<Void> countDownLatch = new CountingCompletionHandler<Void>((VertxInternal) vertx); countDownLatch.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> ar) { if (ar.failed()) { startedResult.setFailure(ar.cause()); } else if (ar.succeeded()) { startedResult.setResult(null); } } }); new ChannelBridge(vertx, config).setHook(new BridgeHook(vertx)).bridge(countDownLatch); }
Example #7
Source File: StringSerializerIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.logger().info("modulename: " +System.getProperty("vertx.modulename")); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); StringSerializerIT.super.start(); } }); }
Example #8
Source File: KafkaModuleDeployWithIncorrectConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { VertxAssert.initialize(vertx); JsonObject config = new JsonObject(); // Do not put required config param when deploying the module - config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.failed()); assertEquals("address must be specified in config for busmod", asyncResult.cause().getMessage()); testComplete(); } }); }
Example #9
Source File: KafkaMessageProcessorIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { before(); JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaMessageProcessorIT.super.start(); } }); }
Example #10
Source File: ProfilerServer.java From statsd-jvm-profiler with MIT License | 6 votes |
/** * Start an embedded HTTP server * * @param activeProfilers The active profilers * @param port The port on which to bind the server */ public static void startServer(final Map<String, ScheduledFuture<?>> runningProfilers, final Map<String, Profiler> activeProfilers, final int port, final AtomicReference<Boolean> isRunning, final List<String> errors) { final HttpServer server = VERTX.createHttpServer(); server.requestHandler(RequestHandler.getMatcher(runningProfilers, activeProfilers, isRunning, errors)); server.listen(port, new Handler<AsyncResult<HttpServer>>() { @Override public void handle(AsyncResult<HttpServer> event) { if (event.failed()) { server.close(); startServer(runningProfilers, activeProfilers, port + 1, isRunning, errors); } else if (event.succeeded()) { LOGGER.info("Profiler server started on port " + port); } } }); }
Example #11
Source File: KafkaModuleDeployWithCorrectConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithCorrectConfigIT.super.start(); } }); }
Example #12
Source File: ByteArraySerializerIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.BYTE_SERIALIZER.getValue()); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); ByteArraySerializerIT.super.start(); } }); }
Example #13
Source File: KafkaModuleDeployWithStatsdEnabledConfigIT.java From mod-kafka with Apache License 2.0 | 6 votes |
@Override public void start() { JsonObject config = new JsonObject(); config.putString("address", ADDRESS); config.putString("metadata.broker.list", KafkaProperties.DEFAULT_BROKER_LIST); config.putString("kafka-topic", KafkaProperties.DEFAULT_TOPIC); config.putNumber("request.required.acks", KafkaProperties.DEFAULT_REQUEST_ACKS); config.putString("serializer.class", MessageSerializerType.STRING_SERIALIZER.getValue()); config.putBoolean("statsd.enabled", true); config.putString("statsd.host", "localhost"); config.putNumber("statsd.port", 8125); config.putString("statsd.prefix", "testapp.prefix"); container.deployModule(System.getProperty("vertx.modulename"), config, new AsyncResultHandler<String>() { @Override public void handle(AsyncResult<String> asyncResult) { assertTrue(asyncResult.succeeded()); assertNotNull("DeploymentID should not be null", asyncResult.result()); KafkaModuleDeployWithStatsdEnabledConfigIT.super.start(); } }); }
Example #14
Source File: AsyncResultHandler.java From mod-lang-php with MIT License | 6 votes |
public void handle(AsyncResult<T> result) { Env env = getEnvironment(); if (hasModifier()) { AsyncResult<?> wrapped = (AsyncResult<?>) getModifier().modify(result); if (wrapped.succeeded()) { getCallable().call(env, env.wrapJava(wrapped.result()), env.wrapJava(null)); } else { getCallable().call(env, env.wrapJava(null), env.wrapJava(wrapped.cause())); } } else { if (result.succeeded()) { getCallable().call(env, env.wrapJava(result.result()), env.wrapJava(null)); } else { getCallable().call(env, env.wrapJava(null), env.wrapJava(result.cause())); } } }
Example #15
Source File: EventBus.java From mod-lang-php with MIT License | 5 votes |
/** * Sends a point-to-point message on the bus with a timeout. * * @param address * The address to which to send the message. * @param message * A mixed value message to send. * @param handler * An optional handler to be invoked in response to the message. * @return The called object. */ public EventBus sendWithTimeout(final Env env, StringValue address, Value message, Value timeout, final Value handler) { PhpTypes.assertCallable(env, handler, "Handler argument to Vertx\\EventBus::sendWithTimeout() must be callable."); org.vertx.java.core.Handler<AsyncResult<org.vertx.java.core.eventbus.Message<Object>>> sendHandler = new org.vertx.java.core.Handler<AsyncResult<org.vertx.java.core.eventbus.Message<Object>>>() { @Override public void handle(AsyncResult<org.vertx.java.core.eventbus.Message<Object>> result) { if (result.failed()) { handler.call(env, env.wrapJava(null), env.wrapJava(new ReplyException((org.vertx.java.core.eventbus.ReplyException) result.cause()))); } else { handler.call(env, env.wrapJava(new Message<Object>(result.result())), env.wrapJava(null)); } } }; if (message.isBoolean()) { eventBus.sendWithTimeout(address.toString(), message.toBoolean(), timeout.toLong(), sendHandler); } else if (message.isString()) { eventBus.sendWithTimeout(address.toString(), message.toString(), timeout.toLong(), sendHandler); } else if (message.isNumeric()) { eventBus.sendWithTimeout(address.toString(), message.toInt(), timeout.toLong(), sendHandler); } else if (message.isObject()) { eventBus.sendWithTimeout(address.toString(), (org.vertx.java.core.buffer.Buffer) message.toJavaObject(env, org.vertx.java.core.buffer.Buffer.class), timeout.toLong(), sendHandler); } else if (message.isArray()) { eventBus.sendWithTimeout(address.toString(), PhpTypes.arrayToJson(env, message), timeout.toLong(), sendHandler); } return this; }
Example #16
Source File: EventBus.java From mod-lang-php with MIT License | 5 votes |
/** * Registers a new event handler. * * @param address * The address at which to register the handler. * @param handler * The handler to register. This can be any PHP callable. * @param resultHandler * An optional handler to be invoke when the handler registration has * been propagated across the cluster. It will be invoked with a * single argument that represents an error if one occurs, else null. * @return The called object. */ public StringValue registerHandler(Env env, StringValue address, Value handler, @Optional Value resultHandler) { PhpTypes.assertCallable(env, handler, "Handler argument to Vertx\\EventBus::registerHandler() must be callable."); AddressPair<String, org.vertx.java.core.Handler<org.vertx.java.core.eventbus.Message<Object>>> addressPair = createAddressPair(env, address, handler); if (PhpTypes.isCallable(env, resultHandler)) { org.vertx.java.core.Handler<AsyncResult<Void>> resultEventHandler = HandlerFactory.createAsyncVoidHandler(env, handler); eventBus.registerHandler(addressPair.getAddress(), addressPair.getHandler(), resultEventHandler); } else { eventBus.registerHandler(addressPair.getAddress(), addressPair.getHandler()); } return env.createString(handlers.register(addressPair).toString()); }
Example #17
Source File: AsyncResultWrapper.java From mod-lang-php with MIT License | 5 votes |
@Override public AsyncResult<E> modify(final AsyncResult<T> result) { return new AsyncResult<E>() { @Override public Throwable cause() { return result.cause(); } @Override public boolean failed() { return result.failed(); } @Override public E result() { if (result.succeeded()) { return wrap(result.result()); } return null; } @Override public boolean succeeded() { return result.succeeded(); } }; }
Example #18
Source File: MainVerticle.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
/** It starts vertx and deploys this project module */ public static void main(String[] args) throws InterruptedException, IOException { PlatformManager pm = PlatformLocator.factory.createPlatformManager(5558,"localhost"); pm.deployModule("com.chuidiang.examples~vertx~1.0.0", null, 1, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> arg0) { System.out.println("module deploying result "+arg0.result()); } }); }
Example #19
Source File: HandlerFactory.java From mod-lang-php with MIT License | 4 votes |
/** * Creates a generic asynchronous handler. */ public static <T> org.vertx.java.core.Handler<AsyncResult<T>> createAsyncGenericHandler(Env env, Value handler) { PhpTypes.assertCallable(env, handler); return new AsyncResultHandler<T>(env, PhpTypes.toCallable(handler)); }
Example #20
Source File: BridgeHook.java From realtime-channel with Apache License 2.0 | 4 votes |
@Override public boolean handleAuthorise(JsonObject message, String sessionID, Handler<AsyncResult<Boolean>> handler) { return false; }