public void registerCodec(MessageCodec codec) { Objects.requireNonNull(codec, "codec"); Objects.requireNonNull(codec.name(), "code.name()"); checkSystemCodec(codec); if (userCodecMap.containsKey(codec.name())) { throw new IllegalStateException("Already a codec registered with name " + codec.name()); } userCodecMap.put(codec.name(), codec); }
public void unregisterDefaultCodec(Class clazz) { Objects.requireNonNull(clazz); MessageCodec codec = defaultCodecMap.remove(clazz); if (codec != null) { userCodecMap.remove(codec.name()); } }
public <T> void registerDefaultCodec(Class<T> clazz, MessageCodec<T, ?> codec) { Objects.requireNonNull(clazz); Objects.requireNonNull(codec, "codec"); Objects.requireNonNull(codec.name(), "code.name()"); checkSystemCodec(codec); if (defaultCodecMap.containsKey(clazz)) { throw new IllegalStateException("Already a default codec registered for class " + clazz); } if (userCodecMap.containsKey(codec.name())) { throw new IllegalStateException("Already a codec registered with name " + codec.name()); } defaultCodecMap.put(clazz, codec); userCodecMap.put(codec.name(), codec); }
@Test public void testUnregisterDecoder() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); vertx.eventBus().unregisterCodec(codec.name()); try { vertx.eventBus().send(ADDRESS1, new MyPOJO("foo"), new DeliveryOptions().setCodecName(codec.name())); fail("Should throw exception"); } catch (IllegalArgumentException e) { // OK } }
public Buffer encodeToWire() { int length = 1024; // TODO make this configurable Buffer buffer = Buffer.buffer(length); buffer.appendInt(0); buffer.appendByte(WIRE_PROTOCOL_VERSION); byte systemCodecID = messageCodec.systemCodecID(); buffer.appendByte(systemCodecID); if (systemCodecID == -1) { // User codec writeString(buffer, messageCodec.name()); } buffer.appendByte(send ? (byte)0 : (byte)1); writeString(buffer, address); if (replyAddress != null) { writeString(buffer, replyAddress); } else { buffer.appendInt(0); } buffer.appendInt(sender.port); writeString(buffer, sender.host); encodeHeaders(buffer); writeBody(buffer); buffer.setInt(0, buffer.length() - 4); return buffer; }
@Test public void testDecoderSendAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplySymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder2(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendSymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder2(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testSend(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
public void registerCodec(MessageCodec codec) { Objects.requireNonNull(codec, "codec"); Objects.requireNonNull(codec.name(), "code.name()"); checkSystemCodec(codec); if (userCodecMap.containsKey(codec.name())) { throw new IllegalStateException("Already a codec registered with name " + codec.name()); } userCodecMap.put(codec.name(), codec); }
@Test public void testDecoderReplySymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendSymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testSend(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testUnregisterDecoder() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); vertx.eventBus().unregisterCodec(codec.name()); try { vertx.eventBus().send(ADDRESS1, new MyPOJO("foo"), new DeliveryOptions().setCodecName(codec.name())); fail("Should throw exception"); } catch (IllegalArgumentException e) { // OK } }
@Test public void testDecoderReplyAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendAsymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder1(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testSend(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderSendSymmetric() throws Exception { MessageCodec codec = new MyPOJOEncoder2(); vertx.eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testSend(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplyAsymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder1(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); testReply(new MyPOJO(str), str, null, new DeliveryOptions().setCodecName(codec.name())); }
@Test public void testDecoderReplySymmetric() throws Exception { startNodes(2); MessageCodec codec = new MyPOJOEncoder2(); vertices[0].eventBus().registerCodec(codec); vertices[1].eventBus().registerCodec(codec); String str = TestUtils.randomAlphaString(100); MyPOJO pojo = new MyPOJO(str); testReply(pojo, pojo, null, new DeliveryOptions().setCodecName(codec.name())); }