|
1 | 1 | /*
|
2 |
| - * Copyright 2015-2016 the original author or authors. |
| 2 | + * Copyright 2015-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.integration.codec.kryo;
|
18 | 18 |
|
19 | 19 | import java.util.Arrays;
|
| 20 | +import java.util.HashMap; |
20 | 21 | import java.util.List;
|
| 22 | +import java.util.UUID; |
21 | 23 |
|
| 24 | +import org.springframework.integration.message.AdviceMessage; |
| 25 | +import org.springframework.integration.support.MutableMessage; |
22 | 26 | import org.springframework.integration.support.MutableMessageHeaders;
|
23 | 27 | import org.springframework.messaging.MessageHeaders;
|
| 28 | +import org.springframework.messaging.support.ErrorMessage; |
| 29 | +import org.springframework.messaging.support.GenericMessage; |
24 | 30 |
|
| 31 | +import com.esotericsoftware.kryo.Kryo; |
25 | 32 | import com.esotericsoftware.kryo.Registration;
|
26 | 33 |
|
27 | 34 | /**
|
28 | 35 | * Registers common MessageHeader types and Serializers.
|
| 36 | + * |
29 | 37 | * @author David Turanski
|
30 | 38 | * @author Gary Russell
|
| 39 | + * @author Artem Bilan |
| 40 | + * |
31 | 41 | * @since 4.2
|
32 | 42 | */
|
33 | 43 | public class MessageKryoRegistrar extends AbstractKryoRegistrar {
|
34 | 44 |
|
35 |
| - private volatile int messageHeadersRegistrationId = RegistrationIds.DEFAULT_MESSAGEHEADERS_ID; |
| 45 | + private int genericMessageRegistrationId = RegistrationIds.DEFAULT_GENERIC_MESSAGE_ID; |
| 46 | + |
| 47 | + private int errorMessageRegistrationId = RegistrationIds.DEFAULT_ERROR_MESSAGE_ID; |
| 48 | + |
| 49 | + private int adviceMessageRegistrationId = RegistrationIds.DEFAULT_ADVICE_MESSAGE_ID; |
| 50 | + |
| 51 | + private int mutableMessageRegistrationId = RegistrationIds.DEFAULT_MUTABLE_MESSAGE_ID; |
36 | 52 |
|
37 |
| - private volatile int mutableMessageHeadersRegistrationId = RegistrationIds.DEFAULT_MUTABLE_MESSAGEHEADERS_ID; |
| 53 | + private int messageHeadersRegistrationId = RegistrationIds.DEFAULT_MESSAGEHEADERS_ID; |
| 54 | + |
| 55 | + private int mutableMessageHeadersRegistrationId = RegistrationIds.DEFAULT_MUTABLE_MESSAGEHEADERS_ID; |
| 56 | + |
| 57 | + private int hashMapRegistrationId = RegistrationIds.DEFAULT_HASH_MAP_ID; |
| 58 | + |
| 59 | + private int uuidRegistrationId = RegistrationIds.DEFAULT_UUID_ID; |
38 | 60 |
|
39 | 61 | /**
|
40 |
| - * Set the registration id for {@code MessageHeaders}. |
| 62 | + * Set the registration id for {@link MessageHeaders}. |
41 | 63 | * @param messageHeadersRegistrationId the id, default 41.
|
42 | 64 | */
|
43 | 65 | public void setMessageHeadersRegistrationId(int messageHeadersRegistrationId) {
|
44 | 66 | this.messageHeadersRegistrationId = messageHeadersRegistrationId;
|
45 | 67 | }
|
46 | 68 |
|
47 | 69 | /**
|
48 |
| - * Set the registration id for {@code MutableMessageHeaders}. |
| 70 | + * Set the registration id for {@link MutableMessageHeaders}. |
49 | 71 | * @param mutableMessageHeadersRegistrationId the id, default 42.
|
50 | 72 | */
|
51 | 73 | public void setMutableMessageHeadersRegistrationId(int mutableMessageHeadersRegistrationId) {
|
52 | 74 | this.mutableMessageHeadersRegistrationId = mutableMessageHeadersRegistrationId;
|
53 | 75 | }
|
54 | 76 |
|
| 77 | + /** |
| 78 | + * Set the registration id for {@link GenericMessage}. |
| 79 | + * @param genericMessageRegistrationId the id, default 43. |
| 80 | + * @since 4.3.23 |
| 81 | + */ |
| 82 | + public void setGenericMessageRegistrationId(int genericMessageRegistrationId) { |
| 83 | + this.genericMessageRegistrationId = genericMessageRegistrationId; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Set the registration id for {@link ErrorMessage}. |
| 88 | + * @param errorMessageRegistrationId the id, default 44. |
| 89 | + * @since 4.3.23 |
| 90 | + */ |
| 91 | + public void setErrorMessageRegistrationId(int errorMessageRegistrationId) { |
| 92 | + this.errorMessageRegistrationId = errorMessageRegistrationId; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Set the registration id for {@link AdviceMessage}. |
| 97 | + * @param adviceMessageRegistrationId the id, default 45. |
| 98 | + * @since 4.3.23 |
| 99 | + */ |
| 100 | + public void setAdviceMessageRegistrationId(int adviceMessageRegistrationId) { |
| 101 | + this.adviceMessageRegistrationId = adviceMessageRegistrationId; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Set the registration id for {@link MutableMessage}. |
| 106 | + * @param mutableMessageRegistrationId the id, default 46. |
| 107 | + * @since 4.3.23 |
| 108 | + */ |
| 109 | + public void setMutableMessageRegistrationId(int mutableMessageRegistrationId) { |
| 110 | + this.mutableMessageRegistrationId = mutableMessageRegistrationId; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Set the registration id for {@link HashMap}. |
| 115 | + * @param hashMapRegistrationId the id, default 47. |
| 116 | + * @since 4.3.23 |
| 117 | + */ |
| 118 | + public void setHashMapRegistrationId(int hashMapRegistrationId) { |
| 119 | + this.hashMapRegistrationId = hashMapRegistrationId; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Set the registration id for {@link UUID}. |
| 124 | + * @param uuidRegistrationId the id, default 48. |
| 125 | + * @since 4.3.23 |
| 126 | + */ |
| 127 | + public void setUuidRegistrationId(int uuidRegistrationId) { |
| 128 | + this.uuidRegistrationId = uuidRegistrationId; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public void registerTypes(Kryo kryo) { |
| 133 | + super.registerTypes(kryo); |
| 134 | + kryo.register(GenericMessage.class, this.genericMessageRegistrationId); |
| 135 | + kryo.register(ErrorMessage.class, this.errorMessageRegistrationId); |
| 136 | + kryo.register(AdviceMessage.class, this.adviceMessageRegistrationId); |
| 137 | + kryo.register(MutableMessage.class, this.mutableMessageRegistrationId); |
| 138 | + kryo.register(HashMap.class, this.hashMapRegistrationId); |
| 139 | + kryo.register(UUID.class, this.uuidRegistrationId); |
| 140 | + } |
55 | 141 |
|
56 | 142 | @Override
|
57 | 143 | public List<Registration> getRegistrations() {
|
|
0 commit comments