View Javadoc

1   /**
2    *  Copyright 2003-2006 Greg Luck
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.distribution;
18  
19  import net.sf.ehcache.Element;
20  
21  import java.io.Serializable;
22  
23  /**
24   * An Event Message, in respect of a particular cache.
25   * <p/>
26   * The message is Serializable, so that it can be sent across the network.
27   * @author Greg Luck
28   * @version $Id: EventMessage.java 52 2006-04-24 14:50:03Z gregluck $
29   * @noinspection SerializableHasSerializationMethods
30   */
31  public final class EventMessage implements Serializable {
32  
33  
34      /**
35       * A put or update event.
36       */
37      public static final int PUT = 0;
38  
39      /**
40       * A remove or invalidate event.
41       */
42      public static final int REMOVE = 1;
43  
44      private static final long serialVersionUID = -5760542938372164184L;
45      
46      /**
47       * The event component.
48       */
49      private final int event;
50      /**
51       * The element component.
52       */
53      private final Element element;
54      /**
55       * The key component.
56       */
57      private final Serializable key;
58  
59  
60  
61      /**
62       * Full constructor.
63       * @param event
64       * @param key
65       * @param element
66       */
67      public EventMessage(int event, Serializable key, Element element) {
68          this.event = event;
69          this.key = key;
70          this.element = element;
71      }
72  
73      /**
74       * Gets the event.
75       * @return either {@link #PUT} or {@link #REMOVE}
76       */
77      public final int getEvent() {
78          return event;
79      }
80  
81      /**
82       * @return the element component of the message. null if a {@link #REMOVE} event
83       */
84      public final Element getElement() {
85          return element;
86      }
87  
88      /**
89       * @return the key component of the message. null if a {@link #PUT} event
90       */
91      public final Serializable getSerializableKey() {
92          return key;
93      }
94  }
95