001package org.apache.commons.jcs3.auxiliary.lateral;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.Serializable;
023
024import org.apache.commons.jcs3.engine.behavior.ICacheElement;
025
026/**
027 * This class wraps command to other laterals. It is essentially a
028 * JCS-TCP-Lateral packet. The headers specify the action the receiver should
029 * take.
030 */
031public class LateralElementDescriptor<K, V>
032    implements Serializable
033{
034    /** Don't change */
035    private static final long serialVersionUID = 5268222498076063575L;
036
037    /** The Cache Element that we are distributing. */
038    public ICacheElement<K, V> ce;
039
040    /**
041     * The id of the source of the request. This is used to prevent infinite
042     * loops.
043     */
044    public long requesterId;
045
046    /** The operation has been requested by the client. */
047    public LateralCommand command = LateralCommand.UPDATE;
048
049    /**
050     * The hash code value for this element.
051     */
052    public int valHashCode = -1;
053
054    /** Constructor for the LateralElementDescriptor object
055     * @deprecated
056     */
057    @Deprecated // Not used
058    public LateralElementDescriptor()
059    {
060    }
061
062    /**
063     * Constructor for the LateralElementDescriptor object
064     * <p>
065     * @param ce ICacheElement&lt;K, V&gt; payload
066     */
067    public LateralElementDescriptor( final ICacheElement<K, V> ce )
068    {
069        this.ce = ce;
070    }
071
072    /**
073     * Constructor for the LateralElementDescriptor object
074     * <p>
075     * @param ce ICacheElement&lt;K, V&gt; payload
076     * @param command operation requested by the client
077     * @since 3.1
078     */
079    public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command)
080    {
081        this(ce);
082        this.command = command;
083    }
084
085    /**
086     * Constructor for the LateralElementDescriptor object
087     * <p>
088     * @param ce ICacheElement&lt;K, V&gt; payload
089     * @param command operation requested by the client
090     * @param requesterId id of the source of the request
091     * @since 3.1
092     */
093    public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command, long requesterId)
094    {
095        this(ce, command);
096        this.requesterId = requesterId;
097    }
098
099    /**
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}