当前位置: 首页>>代码示例>>Java>>正文


Java Handler类代码示例

本文整理汇总了Java中io.vertx.core.Handler的典型用法代码示例。如果您正苦于以下问题:Java Handler类的具体用法?Java Handler怎么用?Java Handler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Handler类属于io.vertx.core包,在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: modify

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public FdfsClient modify(ReadStream<Buffer> stream, long size, FdfsFileId fileId, long offset,
		Handler<AsyncResult<Void>> handler) {
	getTracker().setHandler(tracker -> {
		if (tracker.succeeded()) {
			tracker.result().getStoreStorage(fileId.group(), storage -> {
				if (storage.succeeded()) {
					storage.result().modify(stream, size, fileId, offset, modify -> {
						handler.handle(modify);
					});
				} else {
					handler.handle(Future.failedFuture(storage.cause()));
				}
			});
		} else {
			handler.handle(Future.failedFuture(tracker.cause()));
		}
	});

	return this;
}
 
开发者ID:gengteng,项目名称:vertx-fastdfs-client,代码行数:22,代码来源:FdfsClientImpl.java

示例2: getBooks

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public BookDatabaseService getBooks(Book book, Handler<AsyncResult<JsonArray>> resultHandler) {
  DynamicQuery dynamicQuery = generateDynamicQuery(SQL_FIND_ALL_BOOKS, book);
  String preparedQuery = dynamicQuery.getPreparedQuery();
  Tuple params = dynamicQuery.getParams();

  pgConnectionPool.rxPreparedQuery(preparedQuery, params)
    .map(PgResult::getDelegate)
    .subscribe(
      pgResult -> {
        JsonArray jsonArray = transformPgResultToJson(pgResult);
        resultHandler.handle(Future.succeededFuture(jsonArray));
      },
      throwable -> {
        LOGGER.error("Failed to get the filtered books by the following conditions"
          + params.toString(), throwable);
        resultHandler.handle(Future.failedFuture(throwable));
      });
  return this;
}
 
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:21,代码来源:BookDatabaseServiceImpl.java

示例3: pageUpdateHandler

import io.vertx.core.Handler; //导入依赖的package包/类
private void pageUpdateHandler(RoutingContext context) {
  String title = context.request().getParam("title");

  Handler<AsyncResult<Void>> handler = reply -> {
    if (reply.succeeded()) {
      context.response().setStatusCode(303);
      context.response().putHeader("Location", "/wiki/" + title);
      context.response().end();
    } else {
      context.fail(reply.cause());
    }
  };

  String markdown = context.request().getParam("markdown");
  if ("yes".equals(context.request().getParam("newPage"))) {
    dbService.createPage(title, markdown, handler);
  } else {
    dbService.savePage(Integer.valueOf(context.request().getParam("id")), markdown, handler);
  }
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:21,代码来源:HttpServerVerticle.java

示例4: handler

import io.vertx.core.Handler; //导入依赖的package包/类
private Handler<Message<JsonObject>> handler(ServiceHandler serviceHandler) {
	return msg -> {
		vertx.executeBlocking(ar -> {
			try {
				ar.complete(serviceHandler.invokeService(msg.body()));
			} catch (Exception e) {
				ar.fail(e);
			}
		}, res -> {
			if (res.succeeded()) {
				msg.reply(res.result());
			} else {
				int failureCode = 500;
				String message = res.cause().getMessage();
				msg.fail(failureCode, message);
			}
		});
	};
}
 
开发者ID:simonemasoni,项目名称:vertx_spring,代码行数:20,代码来源:ServiceVerticle.java

示例5: processMethods

import io.vertx.core.Handler; //导入依赖的package包/类
/**
 * 分发请求并处理
 * 下面具体的方法如方法名所示,与DAO层方法命名一致,在此不表
 *
 * @author Leibniz.Hu
 */
@Override
protected <T> void processMethods(Handler<T> replyMsg, JsonArray params, EventBusNamespace method) {
    switch (method) {
        case COMMAND_INSERT_ORDER:
            insertOrder(replyMsg, params);
            break;
        case COMMAND_GET_ORDER_BY_ALIPAY_ORDER_ID:
            getOrderByAlipayOrderId(replyMsg, params);
            break;
        case COMMAND_GET_ORDER_BY_WECHAT_ORDER_ID:
            getOrderByWechatOrderId(replyMsg, params);
            break;
        case COMMAND_UPDATE_PAID_ORDER:
            updateAfterPaid(replyMsg, params);
            break;
        default:
            log.error("未能处理的请求方法:{}", method);
    }
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:26,代码来源:OrderDBVerticle.java

示例6: fetchAllPages

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
  dbClient.query(sqlQueries.get(SqlQuery.ALL_PAGES), res -> {
    if (res.succeeded()) {
      JsonArray pages = new JsonArray(res.result()
        .getResults()
        .stream()
        .map(json -> json.getString(0))
        .sorted()
        .collect(Collectors.toList()));
      resultHandler.handle(Future.succeededFuture(pages));
    } else {
      LOGGER.error("Database query error", res.cause());
      resultHandler.handle(Future.failedFuture(res.cause()));
    }
  });
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:19,代码来源:WikiDatabaseServiceImpl.java

示例7: fetchPage

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public WikiDatabaseService fetchPage(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
  dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), new JsonArray().add(name), fetch -> {
    if (fetch.succeeded()) {
      JsonObject response = new JsonObject();
      ResultSet resultSet = fetch.result();
      if (resultSet.getNumRows() == 0) {
        response.put("found", false);
      } else {
        response.put("found", true);
        JsonArray row = resultSet.getResults().get(0);
        response.put("id", row.getInteger(0));
        response.put("rawContent", row.getString(1));
      }
      resultHandler.handle(Future.succeededFuture(response));
    } else {
      LOGGER.error("Database query error", fetch.cause());
      resultHandler.handle(Future.failedFuture(fetch.cause()));
    }
  });
  return this;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:23,代码来源:WikiDatabaseServiceImpl.java

示例8: connect_success

import io.vertx.core.Handler; //导入依赖的package包/类
@Test
public void connect_success(@Mocked NetSocketImpl netSocket) {
  FutureFactoryImpl futureFactory = new FutureFactoryImpl();
  new MockUp<NetClientWrapper>(netClientWrapper) {
    @Mock
    void connect(boolean ssl, int port, String host, Handler<AsyncResult<NetSocket>> connectHandler) {
      connectHandler.handle(futureFactory.succeededFuture(netSocket));
    }
  };

  tcpClientConnection.connect();

  Assert.assertSame(netSocket, tcpClientConnection.getNetSocket());
  Assert.assertEquals(Status.WORKING, Deencapsulation.getField(tcpClientConnection, "status"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:16,代码来源:TestTcpClientConnection.java

示例9: WikiDatabaseServiceImpl

import io.vertx.core.Handler; //导入依赖的package包/类
WikiDatabaseServiceImpl(io.vertx.ext.jdbc.JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
  this.dbClient = new JDBCClient(dbClient);
  this.sqlQueries = sqlQueries;

  getConnection()
    .flatMap(conn -> conn.rxExecute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE)))
    .map(v -> this)
    .subscribe(RxHelper.toSubscriber(readyHandler));
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:10,代码来源:WikiDatabaseServiceImpl.java

示例10: countAsync

import io.vertx.core.Handler; //导入依赖的package包/类
/**
 * Count all records of the underlying table asynchronously.
 * @param resultHandler the resultHandler which succeeds when the blocking method of this type succeeds or fails
 *                      with an <code>DataAccessException</code> if the blocking method of this type throws an exception
 * @see #count()
 */
default void countAsync(Handler<AsyncResult<Long>> resultHandler){
    VertxDAOHelper.countAsync(this, (query,mapper)->{
        client().fetchOne(query,mapper, h -> {
            if (h.succeeded()) {
                resultHandler.handle(Future.succeededFuture((Long) h.result().get()));
            } else {
                resultHandler.handle(Future.failedFuture(h.cause()));
            }
        });
        return null;
    });
}
 
开发者ID:jklingsporn,项目名称:vertx-jooq-async,代码行数:19,代码来源:VertxDAO.java

示例11: ofSucceededVoid

import io.vertx.core.Handler; //导入依赖的package包/类
public static <A, B> Handler<AsyncResult<A>> ofSucceededVoid(Handler<AsyncResult<B>> handler, VoidConsumer alwaysDo, Consumer<A> consumer)
{
    return e -> {
        if (alwaysDo != null) {
            alwaysDo.accept();
        }

        if (e.failed()) {
            handler.handle(failedFuture(e.cause()));
            return;
        }
        consumer.accept(e.result());
    };
}
 
开发者ID:DavidQuan,项目名称:vertx-ssdb,代码行数:15,代码来源:F.java

示例12: connect

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
public BinlogClientImpl connect(Handler<AsyncResult<Void>> startHandler) {
  if (connected) {
    throw new IllegalStateException("Client already connected.");
  }
  connected = true;
  vertx.<Void>executeBlocking((f) -> {
    try {
      client.connect(connectTimeout);
      Runtime.getRuntime().addShutdownHook(shutdownHook);
      f.complete();
    } catch (Exception e) {
      f.fail(e);
    }
  }, true, (ar) -> {
    if (ar.succeeded()) {
      if (logger.isDebugEnabled()) {
        logger.debug("Binlog listener " +
          "[" + host + ":" + port + "]" +
          " started ");
      }
    } else {
      connected = false;
      if (exceptionHandler != null) {
        exceptionHandler.handle(ar.cause());
      }
    }
    startHandler.handle(ar);
  });
  return this;
}
 
开发者ID:guoyu511,项目名称:vertx-mysql-binlog-client,代码行数:32,代码来源:BinlogClientImpl.java

示例13: compareBodyHandler

import io.vertx.core.Handler; //导入依赖的package包/类
private Handler<HttpClientResponse> compareBodyHandler(String message, TestContext context, Async f) {
	return r -> {
		context.assertEquals(200, r.statusCode(), "Failed to call consumes test '" + message + "'");
		r.exceptionHandler(context::fail).bodyHandler(body -> {
			context.assertEquals(message, body.toString());
			f.complete();
		});
	};
}
 
开发者ID:GreenfieldTech,项目名称:irked,代码行数:10,代码来源:TestMountController.java

示例14: request

import io.vertx.core.Handler; //导入依赖的package包/类
private @NotNull HttpClientRequest request(@NotNull Handler<Buffer> handler, @NotNull Async latch) {
  return vertx.createHttpClient()
      .get(PORT, "localhost", "/metrics")
      .handler(response -> {
        context.assertEquals(HttpResponseStatus.OK.code(), response.statusCode());
        response.bodyHandler(body -> {
          handler.handle(body);
          latch.complete();
        });
      });
}
 
开发者ID:nolequen,项目名称:vertx-prometheus-metrics,代码行数:12,代码来源:PrometheusMetricsTestCase.java

示例15: fetchAllPages

import io.vertx.core.Handler; //导入依赖的package包/类
@Override
// tag::rx-data-flow[]
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
  dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES))
    .flatMapObservable(res -> {  // <1>
      List<JsonArray> results = res.getResults();
      return Observable.from(results); // <2>
    })
    .map(json -> json.getString(0)) // <3>
    .sorted() // <4>
    .collect(JsonArray::new, JsonArray::add) // <5>
    .subscribe(RxHelper.toSubscriber(resultHandler));
  return this;
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:15,代码来源:WikiDatabaseServiceImpl.java


注:本文中的io.vertx.core.Handler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。