View Javadoc
1   package org.apache.commons.jcs.auxiliary.remote;
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.IOException;
23  import java.util.LinkedList;
24  import java.util.List;
25  
26  import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
27  import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType;
28  import org.apache.commons.jcs.engine.behavior.ICacheElement;
29  
30  /**
31   * For testing.
32   * <p>
33   * @author Aaron Smuts
34   */
35  public class MockRemoteCacheListener<K, V>
36      implements IRemoteCacheListener<K, V>
37  {
38      /** Setup the listener id that this will return. */
39      private long listenerId;
40  
41      /** Setup the listener ip that this will return. */
42      public String localAddress;
43  
44      /** Number of times handlePut was called. */
45      public int putCount;
46  
47      /** List of ICacheElements passed to handlePut. */
48      public List<ICacheElement<K, V>> putItems = new LinkedList<ICacheElement<K,V>>();
49  
50      /** List of Serializable objects passed to handleRemove. */
51      public List<K> removedKeys = new LinkedList<K>();
52  
53      /** Number of times handleRemote was called. */
54      public int removeCount;
55  
56      /** The type of remote listener */
57      public RemoteType remoteType = RemoteType.LOCAL;
58  
59      /**
60       * @throws IOException
61       */
62      @Override
63      public void dispose()
64          throws IOException
65      {
66          // TODO Auto-generated method stub
67      }
68  
69      /**
70       * returns the listener id, which can be setup.
71       * @return listenerId
72       * @throws IOException
73       */
74      @Override
75      public long getListenerId()
76          throws IOException
77      {
78          return listenerId;
79      }
80  
81      /**
82       * @return localAddress
83       * @throws IOException
84       */
85      @Override
86      public String getLocalHostAddress()
87          throws IOException
88      {
89          return localAddress;
90      }
91  
92      /**
93       * Return the setup remoteType.
94       * @return remoteType
95       * @throws IOException
96       */
97      @Override
98      public RemoteType getRemoteType()
99          throws IOException
100     {
101         return remoteType;
102     }
103 
104     /**
105      * Allows you to setup the listener id.
106      * <p>
107      * @param id
108      * @throws IOException
109      */
110     @Override
111     public void setListenerId( long id )
112         throws IOException
113     {
114         listenerId = id;
115     }
116 
117     /**
118      * @param cacheName
119      * @throws IOException
120      */
121     @Override
122     public void handleDispose( String cacheName )
123         throws IOException
124     {
125         // TODO Auto-generated method stub
126 
127     }
128 
129     /**
130      * This increments the put count and adds the item to the putItem list.
131      * <p>
132      * @param item
133      * @throws IOException
134      */
135     @Override
136     public void handlePut( ICacheElement<K, V> item )
137         throws IOException
138     {
139         putCount++;
140         this.putItems.add( item );
141     }
142 
143     /**
144      * Increments the remove count and adds the key to the removedKeys list.
145      * <p>
146      * @param cacheName
147      * @param key
148      * @throws IOException
149      */
150     @Override
151     public void handleRemove( String cacheName, K key )
152         throws IOException
153     {
154         removeCount++;
155         removedKeys.add( key );
156     }
157 
158     /**
159      * @param cacheName
160      * @throws IOException
161      */
162     @Override
163     public void handleRemoveAll( String cacheName )
164         throws IOException
165     {
166         // TODO Auto-generated method stub
167     }
168 }