Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.core.stateful;
   19   
   20   public interface Cache<K, V> {
   21       /**
   22        * Gets the listener for cache events.
   23        */
   24       CacheListener<V> getListener();
   25   
   26       /**
   27        * Sets the listener for cache events.  This should be called by the
   28        * container before using the cache.
   29        */
   30       void setListener(CacheListener<V> listener);
   31   
   32       /**
   33        * Add a new entry to the cache.  The entry is marked checked-out and can
   34        * not be accessed again until checked-in.
   35        *
   36        * @IllegalStateException if an value is already associated with the key
   37        */
   38       void add(K key, V value);
   39   
   40       /**
   41        * Marks the entry checked-out, so this entry can not be accessed until
   42        * checked-in.
   43        *
   44        * @throws IllegalStateException if the entry is already checked out.
   45        * @throws Exception if an entry is loaded and the afterLoad method threw an
   46        * exception
   47        */
   48       V checkOut(K key) throws Exception;
   49   
   50       /**
   51        * Marks the entry available, so it can be accessed again.
   52        *
   53        * @throws IllegalStateException if the entry is not checked out.
   54        */
   55       void checkIn(K key);
   56   
   57       /**
   58        * Removes the entry from the cache.
   59        */
   60       V remove(K key);
   61   
   62       /**
   63        * Removes all of th entries that match the specified filter.
   64        */
   65       void removeAll(CacheFilter<V> filter);
   66   
   67       /**
   68        * Callback listener for cache events.
   69        */
   70       public interface CacheListener<V> {
   71           /**
   72            * Called after an entry is loaded from a store.
   73            *
   74            * @throws Exception if there is a problem with the instance
   75            */
   76           void afterLoad(V value) throws Exception;
   77   
   78           /**
   79            * Called before an entry is written to a store.
   80            *
   81            * @throws Exception if there is a problem with the instance
   82            */
   83           void beforeStore(V value) throws Exception;
   84   
   85           /**
   86            * Called when an instance has been removed from the cache due to a
   87            * time-out.
   88            */
   89           void timedOut(V value);
   90       }
   91   
   92       /**
   93        * CacheFileter is used to select values to remove during a removeAll
   94        * invocation.
   95        */
   96       public interface CacheFilter<V> {
   97           /**
   98            * True if the filter matches the value.
   99            */
  100           boolean matches(V v);
  101       }
  102   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]