|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.ignite.internal.managers.communication; |
| 19 | + |
| 20 | +import org.apache.ignite.configuration.DeploymentMode; |
| 21 | +import org.apache.ignite.internal.MessageProcessor; |
| 22 | +import org.apache.ignite.internal.Order; |
| 23 | +import org.apache.ignite.plugin.extensions.communication.Message; |
| 24 | +import org.jetbrains.annotations.Nullable; |
| 25 | + |
| 26 | +import static org.apache.ignite.configuration.DeploymentMode.CONTINUOUS; |
| 27 | +import static org.apache.ignite.configuration.DeploymentMode.ISOLATED; |
| 28 | +import static org.apache.ignite.configuration.DeploymentMode.PRIVATE; |
| 29 | +import static org.apache.ignite.configuration.DeploymentMode.SHARED; |
| 30 | + |
| 31 | +/** |
| 32 | + * Message wrapper for {@link DeploymentMode}. See {@link MessageProcessor} for details. |
| 33 | + */ |
| 34 | +public class DeploymentModeMessage implements Message { |
| 35 | + /** Type code. */ |
| 36 | + public static final short TYPE_CODE = 515; |
| 37 | + |
| 38 | + /** Deployment mode. */ |
| 39 | + private DeploymentMode val; |
| 40 | + |
| 41 | + /** Code. */ |
| 42 | + @Order(0) |
| 43 | + private byte code = -1; |
| 44 | + |
| 45 | + /** |
| 46 | + * Constructor. |
| 47 | + */ |
| 48 | + public DeploymentModeMessage() { |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Constructor. |
| 53 | + */ |
| 54 | + public DeploymentModeMessage(DeploymentMode depMode) { |
| 55 | + val = depMode; |
| 56 | + code = encode(depMode); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return Code. |
| 61 | + */ |
| 62 | + public byte code() { |
| 63 | + return code; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @param code New code. |
| 68 | + */ |
| 69 | + public void code(byte code) { |
| 70 | + this.code = code; |
| 71 | + val = decode(code); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @return Deployment mode. |
| 76 | + */ |
| 77 | + public DeploymentMode value() { |
| 78 | + return val; |
| 79 | + } |
| 80 | + |
| 81 | + /** @param depMode Deployment mode to encode. */ |
| 82 | + private static byte encode(@Nullable DeploymentMode depMode) { |
| 83 | + if (depMode == null) |
| 84 | + return -1; |
| 85 | + |
| 86 | + switch (depMode) { |
| 87 | + case PRIVATE: return 0; |
| 88 | + case ISOLATED: return 1; |
| 89 | + case SHARED: return 2; |
| 90 | + case CONTINUOUS: return 3; |
| 91 | + } |
| 92 | + |
| 93 | + throw new IllegalArgumentException("Unknown deployment mode: " + depMode); |
| 94 | + } |
| 95 | + |
| 96 | + /** @param code Deployment mode code to decode back to a deployment mode value. */ |
| 97 | + @Nullable private static DeploymentMode decode(byte code) { |
| 98 | + switch (code) { |
| 99 | + case -1: return null; |
| 100 | + case 0: return PRIVATE; |
| 101 | + case 1: return ISOLATED; |
| 102 | + case 2: return SHARED; |
| 103 | + case 3: return CONTINUOUS; |
| 104 | + } |
| 105 | + |
| 106 | + throw new IllegalArgumentException("Unknown deployment mode code: " + code); |
| 107 | + } |
| 108 | + |
| 109 | + /** {@inheritDoc} */ |
| 110 | + @Override public short directType() { |
| 111 | + return TYPE_CODE; |
| 112 | + } |
| 113 | +} |
0 commit comments