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


Java AbstractMessage类代码示例

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


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

示例1: decodeJson

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public static WsPacket decodeJson(String stringResult) {
	try {

		JSONObject jsObj = JSONObject.fromObject(stringResult);
		String wsOpCode = jsObj.getString(WSOPCODE);
		if (wsOpCode == null) {
			if (WSManager.log != null) {
				WSManager.log.warn("数据为:" + stringResult + ",无wsOpCode");
			}
			return null;
		}
		if (!WSManager.wsOpCodeMap.containsKey(wsOpCode)) {
			if (WSManager.log != null) {
				WSManager.log.warn("wsOpCode为:" + wsOpCode + "无对应解析,请及时解决");
			}
			return null;
		}
		Class<?> className = WSManager.wsOpCodeMap.get(wsOpCode);

		Method buildM = className.getDeclaredMethod("newBuilder");
		AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
		Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
		WsPacket wsPacket = new WsPacket(wsOpCode, data);
		return wsPacket;
	} catch (Exception e) {
		if (WSManager.log != null) {
			WSManager.log.error("json转换成protobuf异常", e);
		}
		return null;
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:32,代码来源:WSCodeUtil.java

示例2: decode

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // int占4个字节
    int messageId = in.readInt();
    // 消息体的长度(假设长度为20)
    byte[] bytes = new byte[in.readableBytes()];
    in.readBytes(bytes);
    // 4+20 =24
    AbstractMessage message = msgPool.getMessage(messageId);
    if (message == null) {
        LOGGER.error("未注册的消息id{}", messageId);
        return;
    }

    out.add(message.getParserForType().parseFrom(bytes));
}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:17,代码来源:MessageDecoder.java

示例3: encode

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, AbstractMessage msg, ByteBuf out) throws Exception {
    int messageId = msgPool.getMessageId(msg);
    if (messageId == 0) {
        LOGGER.error("编码到未知的消息{}", messageId);
    }
    byte[] bytes = msg.toByteArray();
    int length = Integer.BYTES + bytes.length;
    boolean writeAble = out.isWritable(length);
    if (!writeAble) {
        LOGGER.error("消息过大,编码失败 {} -> {}", messageId, length);
        return;
    }
    // int->4
    out.writeInt(messageId);
    // ->20(假设)
    out.writeBytes(bytes);

}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:20,代码来源:MessageEncoder.java

示例4: requireAllFieldsExcept

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
private static void requireAllFieldsExcept(AbstractMessage message, int... fieldNumbersNotRequired) {
    Collection<Descriptors.FieldDescriptor> required = new ArrayList<>(message.getDescriptorForType().getFields());
    Collection<Descriptors.FieldDescriptor> actual = message.getAllFields().keySet();
    required.removeAll(actual);
    if(fieldNumbersNotRequired != null) {
        for(int fieldNumber : fieldNumbersNotRequired) {
            required.remove(message.getDescriptorForType().findFieldByNumber(fieldNumber));
        }
    }
    if(!required.isEmpty()) {
        Collection<String> names = new ArrayList<>(required.size());
        for(Descriptors.FieldDescriptor desc : required) {
            names.add(desc.getName());
        }
        throw new ProtobufReadException(message.getDescriptorForType().getFullName(),
                                        "Missing required fields: " + names.toString());
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:19,代码来源:ProtobufReader.java

示例5: parseDelimitedFrom

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public static <T extends /*@NonNull*/ AbstractMessage> List<T> parseDelimitedFrom(
        @Nullable ByteBuffer byteBuf, Parser<T> parser) throws IOException {
    if (byteBuf == null) {
        return ImmutableList.of();
    }
    SizeLimitBypassingParser<T> sizeLimitBypassingParser =
            new SizeLimitBypassingParser<>(parser);
    List<T> messages = Lists.newArrayList();
    try (InputStream input = new ByteBufferInputStream(byteBuf)) {
        T message;
        while ((message = sizeLimitBypassingParser.parseDelimitedFrom(input)) != null) {
            messages.add(message);
        }
    }
    return messages;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:17,代码来源:Messages.java

示例6: send

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@Override
public void send(final MessageController messageController, final AbstractMessage message) {
	final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
	try {
		final Map<String, Collection<String>> headers = buildHeaders(messageController);
		final AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(url);
		requestBuilder.setHeaders(headers);
		requestBuilder.setBody(messagePayload(messageController, message));
		final Future<Response> f = requestBuilder.execute();
		final Response r = f.get();
		final String responseBody = r.getResponseBody();
		if (!"OK".equals(responseBody)) {
			LOGGER.warn("Non-OK response received for HTTP transport client request.");
		}
	} catch (final IOException | ExecutionException | InterruptedException e) {
		LOGGER.error("Could not execute HTTP request.", e);
	}
}
 
开发者ID:ngerakines,项目名称:elasticservices,代码行数:19,代码来源:HttpTransportClient.java

示例7: send

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@Override
public void send(final MessageController messageController, final AbstractMessage message) {
	sendCount.increment();
	final ServiceProto.ContentType contentType = getContentType(messageController);
	if (contentType == null) {
		sendFailureCount.increment();
		throw new RuntimeException("Could not get content type of message.");
	}
	try {
		final byte[] messageBytes = rawMessageBytes(contentType, message);
		final AMQP.BasicProperties basicProperties = buildBasicProperties(messageController, contentType);
		channel.basicPublish(
				transportRef.getExchange(),
				"fanout".equals(transportRef.getType()) ? "" : transportRef.getRoutingKey(),
				basicProperties,
				messageBytes);
	} catch (final Exception e) {
		sendFailureCount.increment();
		LOGGER.error("Exception caught publishing message:", e);
	}
}
 
开发者ID:ngerakines,项目名称:elasticservices,代码行数:22,代码来源:RabbitMqTransportClient.java

示例8: sendAndReceive

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@Override
public Future<Message> sendAndReceive(
		final ServiceProto.ServiceRef destination,
		final AbstractMessage message,
		final Class messageClass,
		final Optional<Expiration> expirationOptional) {
	final SettableFuture<Message> resultsFuture = SettableFuture.create();
	final byte[] messageId = MessageUtils.randomMessageId(24);
	final MessageController controller =
			new DefaultMessageController(
					serviceRef,
					destination,
					ContentTypes.fromClass(messageClass),
					Optional.of(messageId),
					Optional.<byte[]> absent(),
					expirationOptional.isPresent() ? Optional.of(expirationOptional.get().getExpiration()) : Optional
							.<DateTime> absent());
	resultsFutures.putIfAbsent(Arrays.hashCode(messageId), new Pair<>(resultsFuture, DateTime.now()));
	serviceRegistry.sendMessage(controller, message);
	return resultsFuture;
}
 
开发者ID:ngerakines,项目名称:elasticservices,代码行数:22,代码来源:DefaultResponseManager.java

示例9: build

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public NettyRpcProto.RpcRequest build() {
    NettyRpcProto.RpcRequest result = buildPartial();
    if (!result.isInitialized()) {
        throw AbstractMessage.Builder.newUninitializedMessageException(result);
    }
    return result;
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:8,代码来源:NettyRpcProto.java

示例10: decodeJson

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
/**
 * 将字符串转换成HttpPacket
 * 
 * @param stringResult
 *            字符串
 * @param isServer
 *            是不是服务器一般传true
 * @param httpPacket
 *            消息包
 * @return
 */
public static boolean decodeJson(String stringResult, boolean isServer, HttpPacket httpPacket) {
	try {
		// 转换成json获取hOpCode,如果没有看看头消息有没有
		JSONObject jsObj = JSONObject.fromObject(stringResult);
		String hOpCode;
		if (jsObj.containsKey(AllowParam.HOPCODE)) {
			hOpCode = jsObj.getString(AllowParam.HOPCODE);
		} else if (httpPacket.hSession.headParam.hOpCode != null && !httpPacket.hSession.headParam.hOpCode.equals("")) {
			hOpCode = httpPacket.hSession.headParam.hOpCode;
		} else {
			return false;
		}
		// 是否设定相应解析
		if (!HttpManager.hOpCodeMap.containsKey(hOpCode)) {
			if (HttpConfig.log != null) {
				HttpConfig.log.warn("hOpCode为:" + hOpCode + "无对应解析,请及时解决");
			}
			return false;
		}
		// 解析
		Class<?>[] classNames = HttpManager.hOpCodeMap.get(hOpCode);
		Class<?> className;
		if (isServer) {
			className = classNames[0];
		} else {
			className = classNames[1];
		}
		Method buildM = className.getDeclaredMethod("newBuilder");
		AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
		Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
		if (data == null) {
			return false;
		}
		// 设置hOpCode和消息体
		httpPacket.sethOpCode(hOpCode);
		httpPacket.setData(data);
		return true;
	} catch (Exception e) {
		if (HttpConfig.log != null) {
			HttpConfig.log.error("json转换成protobuf异常", e);
		}
		return false;
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:56,代码来源:CodeUtils.java

示例11: consume

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void consume(AbstractMessage msg, Channel channel) {

    //将消息分发到指定的队列中,该队列有可能在同一个进程,也有可能不在同一个进程

    int queueId = 1;

    IProcessor processor = processors.get(queueId);
    if (processor == null) {
        log.error("找不到可用的消息处理器[{}]", queueId);
        return;
    }

    Session session = AttributeUtil.get(channel, SessionKey.SESSION);

    if (session == null) {
        return;
    }

    AbstractHandler handler = msgPool.getHandler(msg.getClass().getName());
    handler.setMessage(msg);
    handler.setParam(session);
    log.debug("收到消息:" + msg);

    processor.process(handler);

}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:29,代码来源:MessageRouter.java

示例12: build

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public Row build() {
  Row result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
 
开发者ID:mravi,项目名称:hbase-connect-kafka,代码行数:8,代码来源:HRowProtos.java

示例13: build

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public HColumn build() {
  HColumn result = buildPartial();
  if (!result.isInitialized()) {
    throw AbstractMessage.Builder.newUninitializedMessageException(result);
  }
  return result;
}
 
开发者ID:mravi,项目名称:hbase-connect-kafka,代码行数:8,代码来源:HColumnProtos.java

示例14: consume

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void consume(AbstractMessage msg, Channel channel) {

    //将消息分发到指定的队列中,该队列有可能在同一个进程,也有可能不在同一个进程

    int queueId = 1;

    IProcessor processor = processors.get(queueId);
    if (processor == null) {
        LOGGER.error("找不到可用的消息处理器[{}]", queueId);
        return;
    }

    Session session = AttributeUtil.get(channel, SessionKey.SESSION);

    if (session == null) {
        return;
    }

    AbstractHandler handler = msgPool.getHandler(msg.getClass().getName());
    handler.setMessage(msg);
    handler.setParam(session);
    LOGGER.debug("收到消息:" + msg);

    processor.process(handler);

}
 
开发者ID:beimi,项目名称:ChessGameServer,代码行数:29,代码来源:MessageRouter.java

示例15: sendMsg

import com.google.protobuf.AbstractMessage; //导入依赖的package包/类
public static void sendMsg(AbstractMessage msg, long id) {
    Session session = SessionManager.getInstance().getSession(id);
    if (session == null) {
        return;
    }
    session.sendMessage(msg);
}
 
开发者ID:beimi,项目名称:ChessGameServer,代码行数:8,代码来源:MessageUtil.java


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