| 1 | package org.apache.commons.jcs3.auxiliary.lateral; |
| 2 | |
| 3 | /* |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | * or more contributor license agreements. See the NOTICE file |
| 6 | * distributed with this work for additional information |
| 7 | * regarding copyright ownership. The ASF licenses this file |
| 8 | * to you under the Apache License, Version 2.0 (the |
| 9 | * "License"); you may not use this file except in compliance |
| 10 | * with the License. You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, |
| 15 | * software distributed under the License is distributed on an |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | * KIND, either express or implied. See the License for the |
| 18 | * specific language governing permissions and limitations |
| 19 | * under the License. |
| 20 | */ |
| 21 | |
| 22 | import java.io.Serializable; |
| 23 | |
| 24 | import org.apache.commons.jcs3.engine.behavior.ICacheElement; |
| 25 | |
| 26 | /** |
| 27 | * This class wraps command to other laterals. It is essentially a |
| 28 | * JCS-TCP-Lateral packet. The headers specify the action the receiver should |
| 29 | * take. |
| 30 | */ |
| 31 | public class LateralElementDescriptor<K, V> |
| 32 | implements Serializable |
| 33 | { |
| 34 | /** Don't change */ |
| 35 | private static final long serialVersionUID = 5268222498076063575L; |
| 36 | |
| 37 | /** The Cache Element that we are distributing. */ |
| 38 | public ICacheElement<K, V> ce; |
| 39 | |
| 40 | /** |
| 41 | * The id of the source of the request. This is used to prevent infinite |
| 42 | * loops. |
| 43 | */ |
| 44 | public long requesterId; |
| 45 | |
| 46 | /** The operation has been requested by the client. */ |
| 47 | public LateralCommand command = LateralCommand.UPDATE; |
| 48 | |
| 49 | /** |
| 50 | * The hash code value for this element. |
| 51 | */ |
| 52 | public int valHashCode = -1; |
| 53 | |
| 54 | /** Constructor for the LateralElementDescriptor object |
| 55 | * @deprecated |
| 56 | */ |
| 57 | @Deprecated // Not used |
| 58 | public LateralElementDescriptor() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Constructor for the LateralElementDescriptor object |
| 64 | * <p> |
| 65 | * @param ce ICacheElement<K, V> payload |
| 66 | */ |
| 67 | public LateralElementDescriptor( final ICacheElement<K, V> ce ) |
| 68 | { |
| 69 | this.ce = ce; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Constructor for the LateralElementDescriptor object |
| 74 | * <p> |
| 75 | * @param ce ICacheElement<K, V> payload |
| 76 | * @param command operation requested by the client |
| 77 | * @since 3.1 |
| 78 | */ |
| 79 | public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command) |
| 80 | { |
| 81 | this(ce); |
| 82 | this.command = command; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Constructor for the LateralElementDescriptor object |
| 87 | * <p> |
| 88 | * @param ce ICacheElement<K, V> payload |
| 89 | * @param command operation requested by the client |
| 90 | * @param requesterId id of the source of the request |
| 91 | * @since 3.1 |
| 92 | */ |
| 93 | public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command, long requesterId) |
| 94 | { |
| 95 | this(ce, command); |
| 96 | this.requesterId = requesterId; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Return payload |
| 101 | * |
| 102 | * @return the ce |
| 103 | * @since 3.1 |
| 104 | */ |
| 105 | public ICacheElement<K, V> getPayload() |
| 106 | { |
| 107 | return ce; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Return id of the source of the request |
| 112 | * |
| 113 | * @return the requesterId |
| 114 | * @since 3.1 |
| 115 | */ |
| 116 | public long getRequesterId() |
| 117 | { |
| 118 | return requesterId; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Return operation requested by the client |
| 123 | * |
| 124 | * @return the command |
| 125 | * @since 3.1 |
| 126 | */ |
| 127 | public LateralCommand getCommand() |
| 128 | { |
| 129 | return command; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @return the valHashCode |
| 134 | * @since 3.1 |
| 135 | */ |
| 136 | public int getValHashCode() |
| 137 | { |
| 138 | return valHashCode; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @return String, all the important values that can be configured |
| 143 | */ |
| 144 | @Override |
| 145 | public String toString() |
| 146 | { |
| 147 | final StringBuilder buf = new StringBuilder(); |
| 148 | buf.append( "\n LateralElementDescriptor " ); |
| 149 | buf.append( "\n command = [" + this.command + "]" ); |
| 150 | buf.append( "\n valHashCode = [" + this.valHashCode + "]" ); |
| 151 | buf.append( "\n ICacheElement = [" + this.ce + "]" ); |
| 152 | return buf.toString(); |
| 153 | } |
| 154 | } |