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