本文整理匯總了Java中org.vertx.java.core.Handler類的典型用法代碼示例。如果您正苦於以下問題:Java Handler類的具體用法?Java Handler怎麽用?Java Handler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Handler類屬於org.vertx.java.core包,在下文中一共展示了Handler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateDownloadLogs
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
public void updateDownloadLogs(final String id, final UserInfos user, final Handler<JsonObject> handler) {
final QueryBuilder query = QueryBuilder.start("_id").is(id);
final JsonObject logElem = new JsonObject().putString("userDisplayName", user.getUsername()).putObject("downloadDate", MongoDb.now());
final MongoUpdateBuilder modifier = new MongoUpdateBuilder();
modifier.addToSet("downloadLogs", logElem);
mongo.update(ShareBigFiles.SHARE_BIG_FILE_COLLECTION, MongoQueryBuilder.build(query),
modifier.build(), new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> event) {
if ("ok".equals(event.body().getString("status"))) {
handler.handle(new JsonObject().putString("status", "ok"));
} else {
handler.handle(new JsonObject().putString("status", "error")
.putString("message", event.body().getString("message")));
}
}
});
}
示例2: start
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
public void start(String host, int port) {
Handler<HttpServerRequest> handler = new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest request) {
if (request.absoluteURI().getPath().equals("/kill")) {
request.response().end("Exiting after 5s ...");
killWorker();
return;
} else if (request.absoluteURI().getPath().equals("/ping")) {
request.response().end("PONG");
return;
}
request.response().end("ScheduledJobNode is running");
}
};
registerWorkerHttpHandler(host, port, handler);
}
示例3: main
import org.vertx.java.core.Handler; //導入依賴的package包/類
public static void main(String[] args) {
// Configure the client.
String adCode3rd = "/?advideo/3.0/78.109/5798044/0//cc=2;vidAS=pre_roll;vidRT=VAST;vidRTV=2.0.1";
HttpClient httpClient = VertxFactory.newVertx().createHttpClient();
httpClient.setHost("adserver.adtech.de");
httpClient.get(adCode3rd, new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse httpClientResponse) {
httpClientResponse.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
System.out.println("Response (" + buffer.length() + "): ");
System.out.println(buffer.getString(0, buffer.length()));
}
});
}
});
Utils.sleep(10000);
}
示例4: init
import org.vertx.java.core.Handler; //導入依賴的package包/類
private void init() {
this.next.readStream().dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
if( encryptedReadBuffer == null ) {
encryptedReadBuffer = buffer;
} else {
encryptedReadBuffer.appendBuffer(buffer);
}
encryptedReadBufferUnderflow = false;
pumpReads();
}
});
this.next.readStream().endHandler(new Handler<Void>() {
@Override
public void handle(Void x) {
encryptedReadEOF = true;
}
});
this.next.readStream().exceptionHandler(new Handler<Throwable>() {
@Override
public void handle(Throwable error) {
onFailure(error);
}
});
}
示例5: getInfo
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
public void getInfo(final String fileId, final AsyncResultHandler<FileInfos> handler) {
final JsonObject query = new JsonObject().putString(mapping.getString("file", "file"), fileId);
mongo.findOne(collection, query, keys, new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> event) {
if ("ok".equals(event.body().getString("status"))) {
JsonObject res = event.body().getObject("result");
if (res != null) {
final FileInfos fi = new FileInfos();
fi.setApplication(application);
fi.setId(fileId);
fi.setName(res.getString(mapping.getString("title", "title")));
fi.setOwner(res.getObject("owner", new JsonObject()).getString("userId"));
handler.handle(new DefaultAsyncResult<>(fi));
} else {
handler.handle(new DefaultAsyncResult<>((FileInfos) null));
}
} else {
handler.handle(new DefaultAsyncResult<FileInfos>(
new StorageException(event.body().getString("message"))));
}
}
});
}
示例6: getResidualRepositorySize
import org.vertx.java.core.Handler; //導入依賴的package包/類
private void getResidualRepositorySize(final Handler<Long> handler) {
storage.stats(new AsyncResultHandler<BucketStats>() {
@Override
public void handle(AsyncResult<BucketStats> event) {
Long residualRepositorySize = 0L;
if (event.succeeded()) {
final Long sizeUsed = event.result().getStorageSize();
final Long residualRepository = ShareBigFilesController.this.maxRepositoryQuota - sizeUsed;
residualRepositorySize = (residualRepository < 0) ? 0L : residualRepository;
} else {
log.error("Can't get the repository stats : ", event.cause());
}
handler.handle(residualRepositorySize);
}
});
}
示例7: authorize
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
public void authorize(final HttpServerRequest request, final Binding binding, final UserInfos user, final Handler<Boolean> handler) {
RequestUtils.bodyToJson(request, Server.getPathPrefix(Config.getInstance().getConfig()) + "deletes", new Handler<JsonObject>() {
public void handle(JsonObject data) {
final List<String> ids = data.getArray("ids").toList();
if (ids != null && !ids.isEmpty()) {
List<DBObject> groups = new ArrayList<>();
String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-");
groups.add(QueryBuilder.start("userId").is(user.getUserId())
.put(sharedMethod).is(true).get());
for (String gpId: user.getGroupsIds()) {
groups.add(QueryBuilder.start("groupId").is(gpId)
.put(sharedMethod).is(true).get());
}
QueryBuilder query = QueryBuilder.start("_id").in(new HashSet<String>(ids)).or(
QueryBuilder.start("owner.userId").is(user.getUserId()).get(),
QueryBuilder.start("shared").elemMatch(
new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()
);
MongoAppFilter.executeCountQuery(request, conf.getCollection(), MongoQueryBuilder.build(query), ids.size(), handler);
} else {
handler.handle(false);
}
}
});
}
示例8: createBooking
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Post("/resource/:id/booking")
@ApiDoc("Create booking of a given resource")
@SecuredAction(value = "rbs.contrib", type= ActionType.RESOURCE)
@ResourceFilter(TypeAndResourceAppendPolicy.class)
public void createBooking(final HttpServerRequest request) {
UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() {
@Override
public void handle(final UserInfos user) {
if (user != null) {
RequestUtils.bodyToJson(request, pathPrefix + "createBooking",
getBookingHandler(user, request, true));
} else {
log.debug("User not found in session.");
unauthorized(request);
}
}
});
}
示例9: initVerticle
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
protected void initVerticle() {
Commands.call(
eventBus(),
LOCAL_ADDRESS,
Commands.cmdDeployVerticle(
TestVerticle1.class.getName(),
new JsonObject(),
1,
false,
false),
new Handler<Message<JsonObject>>() {
@Override
public void handle(Message<JsonObject> message) {
Result result = new Result(message.body());
if (result.getReturnCode() != RET_DEPLOYMENT_ID) {
throw new IllegalStateException(result.getReason());
} else {
undeployVerticle(result.getReason()); // Deployment ID is in reason
}
}
});
}
示例10: getDelaysAndTypeProperties
import org.vertx.java.core.Handler; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void getDelaysAndTypeProperties(long resourceId, Handler<Either<String, JsonObject>> handler) {
StringBuilder query = new StringBuilder("SELECT r.min_delay, r.max_delay, t.owner, t.school_id,");
// Subquery to return managers
query.append(" (SELECT json_agg(DISTINCT ts.member_id) FROM rbs.resource_type_shares AS ts")
.append(" WHERE ts.resource_id = t.id")
.append(" AND ts.action = 'net-atos-entng-rbs-controllers-ResourceTypeController|shareJsonSubmit') AS managers");
query.append(" FROM rbs.resource AS r")
.append(" INNER JOIN rbs.resource_type AS t ON r.type_id = t.id")
.append(" WHERE r.id = ?");
JsonArray values = new JsonArray().add(resourceId);
Sql.getInstance().prepared(query.toString(), values, validUniqueResultHandler(handler));
}
示例11: updateBooking
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Put("/resource/:id/booking/:bookingId")
@ApiDoc("Update booking")
@SecuredAction(value = "rbs.contrib", type= ActionType.RESOURCE)
@ResourceFilter(TypeAndResourceAppendPolicy.class)
public void updateBooking(final HttpServerRequest request){
UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() {
@Override
public void handle(final UserInfos user) {
if (user != null) {
RequestUtils.bodyToJson(request, pathPrefix + "updateBooking",
getBookingHandler(user, request, false));
} else {
log.debug("User not found in session.");
unauthorized(request);
}
}
});
}
示例12: startLocalHttpServer
import org.vertx.java.core.Handler; //導入依賴的package包/類
private void startLocalHttpServer(final URI address) {
String host = address.getHost();
int port = address.getPort();
m_logger.info("Listening on {}:{}", host, port);
HttpServer server = vertx.createHttpServer();
server.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(final HttpServerRequest request) {
m_logger.debug("{} received request from {}",
request.localAddress(),
request.remoteAddress());
request.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(final Buffer body) {
m_logger.info("{} client data: {}",
request.localAddress(),
body.toString(StandardCharsets.UTF_8.name()));
}
});
request.response().setStatusCode(200).end();
}
}).listen(port, host);
}
示例13: createPeriodicBooking
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Post("/resource/:id/booking/periodic")
@ApiDoc("Create periodic booking of a given resource")
@SecuredAction(value = "rbs.contrib", type= ActionType.RESOURCE)
@ResourceFilter(TypeAndResourceAppendPolicy.class)
public void createPeriodicBooking(final HttpServerRequest request) {
UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() {
@Override
public void handle(final UserInfos user) {
if (user != null) {
RequestUtils.bodyToJson(request, pathPrefix + "createPeriodicBooking",
getPeriodicBookingHandler(user, request, true));
} else {
log.debug("User not found in session.");
unauthorized(request);
}
}
});
}
示例14: deleteSession
import org.vertx.java.core.Handler; //導入依賴的package包/類
/**
* Delete a user session on a collaborative editor
* @param request HTTP request
*/
public void deleteSession(final HttpServerRequest request) {
UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() {
@Override
public void handle(final UserInfos user) {
String sessionID = CookieHelper.get("sessionID", request);
if (sessionID != null) {
client.deleteSession(sessionID, new Handler<JsonObject>() {
@Override
public void handle(JsonObject event) {
if ("ok".equals(event.getField("status"))) {
request.response().putHeader("Set-Cookie", "sessionID=deleted;max-age=-1;path=/;domain=" + domain).setStatusCode(200).end();
} else {
//TODO check if render error because there is a redmine ticket about error log on session doesn't exist !!!!!
Renders.renderError(request, event);
}
}
});
} else {
request.response().setStatusCode(200).end();
}
}
});
}
示例15: retrieve
import org.vertx.java.core.Handler; //導入依賴的package包/類
@Override
public void retrieve(String id, Handler<Either<String, JsonObject>> handler) {
String query;
JsonArray values = new JsonArray();
if (id != null) {
query = "SELECT t.id as _id, t.title, t.icon, t.mode, t.created, t.modified, t.owner, u.username" +
", json_agg(row_to_json(row(ts.member_id, ts.action)::actualites.share_tuple)) as shared" +
", array_to_json(array_agg(group_id)) as groups" +
" FROM actualites.thread AS t" +
" LEFT JOIN actualites.users AS u ON t.owner = u.id" +
" LEFT JOIN actualites.thread_shares AS ts ON t.id = ts.resource_id" +
" LEFT JOIN actualites.members AS m ON (ts.member_id = m.id AND m.group_id IS NOT NULL)" +
" WHERE t.id = ? " +
" GROUP BY t.id, u.username" +
" ORDER BY t.modified DESC";
values.add(Sql.parseId(id));
Sql.getInstance().prepared(query.toString(), values, SqlResult.parseSharedUnique(handler));
}
}