本文整理匯總了Java中org.vertx.java.core.eventbus.Message.body方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.body方法的具體用法?Java Message.body怎麽用?Java Message.body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.vertx.java.core.eventbus.Message
的用法示例。
在下文中一共展示了Message.body方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handle
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
* Handle the event bus reply.
*
* @param event The event
*/
@Override
public void handle(final AsyncResult<Message<Object>> event) {
EventBusBridgeResponse response = new EventBusBridgeResponse();
response.setSuccessful(event.succeeded());
response.setAddress(address);
if (event.succeeded()) {
Message<Object> result = event.result();
Object responseMessage = result.body();
response.setResponseMessage(EventBusMessageTypeConverter.convertOutgoingMessage(result.body()));
response.setEventBusMessageType(EventBusMessageType.lookupByClass(responseMessage.getClass()));
} else {
Throwable cause = event.cause();
if (cause != null) {
if (cause instanceof ReplyException) {
ReplyException replyException = (ReplyException) cause;
response.setCause(replyException.failureType().name());
} else {
response.setCause(cause.getMessage());
}
}
}
postResponse(response);
}
示例2: processRequest
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
public void processRequest(Message<JsonObject> msg) {
JsonObject request = msg.body();
// MANDATORY: action to perform
String action = helper.getMandatoryString(request, MSG_PROPERTY_ACTION, msg);
if (action == null) return;
// OPTIONAL: headers to use for the operation
JsonObject headers = helper.getOptionalObject(request, MSG_PROPERTY_HEADERS);
// OPTIONAL: timeout for the action (defaults to 10sec)
int timeout = helper.getOptionalInt(request, MSG_PROPERTY_TIMEOUT, DEFAULT_REQUEST_TIMEOUT);
// OPTIONAL: database on which the action should be performed (will default to the database specified in the config or _system if none was specified)
String dbName = helper.getOptionalString(request, MSG_PROPERTY_DATABASE, persistor.SETTING_DBNAME);
performAction(msg, action, headers, timeout, dbName);
}
示例3: prepare
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
* From a retrieved message prepare the given arguments to prepared statements and cache them
*
* @param message
*/
@SuppressWarnings("unchecked")
private void prepare(Message<JsonObject> message) {
JsonObject prepareMessage = message.body();
try {
if(prepareMessage.containsField("statement")) {
getPreparedStatementCache().add(prepareMessage.getString("statement"));
} else {
// Note: If more statements than cache size are entered, the
// ladder will replace the earlier
getPreparedStatementCache().addAll(prepareMessage.getArray("statements").toList());
}
} catch(Exception e) {
// An error happened
sendError(message, "[Cassandra Persistor] Could not prepare query/ies from " + prepareMessage + "!", e);
return;
}
//
sendOK(message);
}
示例4: unlock
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void unlock(Message<JsonObject> message) throws InterruptedException, ExecutionException {
JsonObject json = message.body();
String key = getMandatoryString("key", message);
Long cas = json.getLong("cas");
if (key == null || cas == null) {
sendError(message, "key and cas must be specified");
return;
}
OperationFuture<Boolean> unlockFuture = client.asyncUnlock(key, cas);
boolean response = unlockFuture.get();
if (response) {
JsonObject reply = new JsonObject();
reply.putString("key", unlockFuture.getKey());
sendOK(message, reply);
}
else {
sendError(message, unlockFuture.getStatus().getMessage());
}
}
示例5: touch
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void touch(Message<JsonObject> message) throws InterruptedException, ExecutionException {
JsonObject json = message.body();
String key = getMandatoryString("key", message);
int expiration = json.getInteger("expiration", 0);
if (key == null) {
sendError(message, "key must be specified");
return;
}
OperationFuture<Boolean> touchFuture = client.touch(key, expiration);
boolean response = touchFuture.get();
if (response) {
JsonObject reply = new JsonObject();
reply.putString("key", touchFuture.getKey());
sendOK(message, reply);
}
else {
sendError(message, touchFuture.getStatus().getMessage());
}
}
示例6: saveVertex
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void saveVertex(Message<JsonObject> message) {
try {
JsonObject mBody = message.body();
String id = mBody.getString("id");
JsonObject props = mBody.getObject("properties");
og = factory.getTx();
Vertex v = og.getVertex(id);
props.getFieldNames().forEach(
(fieldName) ->
v.setProperty(fieldName, props.getValue(fieldName))
);
og.commit();
JsonObject reply = new JsonObject(getVertexAsMap(v, true));
sendOK(message, reply);
} catch (Exception e) {
logger.error(e);
sendError(message, e.toString());
og.rollback();
}
}
示例7: addVertex
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void addVertex(Message<JsonObject> message) {
try {
JsonObject mBody = message.body();
String clazz = mBody.getString("class");
String cluster = mBody.getString("cluster", null);
JsonObject props = mBody.getObject("properties");
og = factory.getTx();
Vertex newVertex = og.addVertex(clazz, cluster);
props.getFieldNames().forEach(
(fieldName) ->
newVertex.setProperty(fieldName, props.getValue(fieldName))
);
og.commit();
JsonObject reply = new JsonObject(getVertexAsMap(newVertex, true));
sendOK(message, reply);
} catch (Exception e) {
logger.error(e);
sendError(message, e.toString());
og.rollback();
}
}
示例8: handleLocalMessage
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
protected void handleLocalMessage(final Message events) {
JsonArray jsonEvents = (JsonArray) events.body();
for (int i = 0; i < jsonEvents.size(); i++) {
JsonObject event = jsonEvents.get(i);
String eventId = event.getString(EVENT_FIELD_ID, "");
String title = event.getString(EVENT_FIELD_TITLE, "");
String message = event.getString(EVENT_FIELD_MESSAGE, "");
logger().trace("Processing notification: {}", eventId);
// Event priority
String priority = event.getString(EVENT_FIELD_PRIORITY,
EVENT_PRIORITY_NORMAL);
// Destinations
JsonArray destinations = event.getArray(EVENT_FIELD_DESTINATIONS,
new JsonArray());
// Bombs away...
send(eventId,
destinations,
title,
message,
priority);
}
}
示例9: handle
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
public void handle(final Message<JsonObject> message) {
Result result = new Result(message.body());
if (!result.isReturnCode(RET_DEPLOYMENT_ID)) {
throw new IllegalStateException(result.getReason());
} else {
m_filter.setDeploymentId(result.getReason());
}
}
示例10: processCommand
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
protected void processCommand(final Message message) {
Object msgBody = message.body();
if (msgBody instanceof JsonObject) {
JsonObject json = (JsonObject) msgBody;
logger().debug("Received command: {}", json);
AbstractCommand cmd = buildCommand(json);
cmd.execute(message);
}
}
示例11: handle
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
@Override
public void handle(final Message<JsonObject> message) {
Commands.Result result = new Commands.Result(message.body());
if (!result.isReturnCode(RET_DEPLOYMENT_ID)) {
handleFailure(result);
} else {
String deploymentId = result.getReason();
handleSuccess(deploymentId);
}
}
示例12: sendMessageToKinesis
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
protected void sendMessageToKinesis(final Message<JsonObject> event) throws KinesisException {
if (kinesisAsyncClient == null) {
throw new KinesisException("AmazonKinesisAsyncClient is not initialized");
}
if (!isValid(event.body().getString(PAYLOAD))) {
logger.error("Invalid message provided.");
return;
}
JsonObject object = event.body();
logger.debug(" --- Got event " + event.toString());
logger.debug(" --- Got body + " + object.toString());
byte[] payload = object.getBinary(PAYLOAD);
if (payload == null) {
logger.debug(" --- Payload is null, trying to get the payload as String");
payload = object.getString(PAYLOAD).getBytes();
}
logger.debug("Binary payload size: " + payload.length);
String msgPartitionKey = object.getString(PARTITION_KEY);
String requestPartitionKey = msgPartitionKey != null ? msgPartitionKey : partitionKey;
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setStreamName(streamName);
putRecordRequest.setPartitionKey(requestPartitionKey);
logger.debug("Writing to streamName " + streamName + " using partitionkey " + requestPartitionKey);
putRecordRequest.setData(ByteBuffer.wrap(payload));
retryCounter = 0;
this.sendUsingAsyncClient(putRecordRequest, event);
}
示例13: serviceUnRegisterHandler
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
private void serviceUnRegisterHandler(Message<JsonObject> message) {
final JsonObject info = message.body();
JSONTool.getObjectListFromArray(info.getArray("operations")).forEach(operation -> {
final String url = operation.getString("url");
if (registeredRoutes.contains(url)) {
routeMatcher.removeAll(url);
registeredRoutes.remove(url);
}
});
}
示例14: validResult
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
public static Either<String, JsonObject> validResult(Message<JsonObject> res) {
if ("ok".equals(res.body().getString("status"))) {
JsonObject r = res.body().getObject("result");
if (r == null) {
r = res.body();
r.removeField("status");
}
return new Either.Right<>(r);
} else {
return new Either.Left<>(res.body().getString("message", ""));
}
}
示例15: handle
import org.vertx.java.core.eventbus.Message; //導入方法依賴的package包/類
/**
*
*/
@Override
public void handle(Message<JsonArray> message) {
//
JsonArray actions = message.body();
BatchRequestHandler<?> batchRequestHandler = new BatchRequestHandler<>(message, actions.size());
//
for(int i = 0; i < actions.size(); i++) {
eb.sendWithTimeout(getPersistorAddress(), (JsonObject) actions.get(i), getTimeout(), batchRequestHandler);
}
}