• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 5682

Show
Ignore:
Timestamp:
10/13/08 14:03:05 (7 weeks ago)
Author:
jburel
Message:

Modified caching strategy

Location:
trunk
Files:
13 modified

  • SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java (modified) (3 diffs)
  • SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java (modified) (1 diff)
  • SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java (modified) (2 diffs)
  • SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java (modified) (2 diffs)
  • SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java (modified) (3 diffs)
  • SRC/org/openmicroscopy/shoola/env/cache/CacheService.java (modified) (3 diffs)
  • SRC/org/openmicroscopy/shoola/env/cache/CacheServiceFactory.java (modified) (1 diff)
  • SRC/org/openmicroscopy/shoola/env/cache/CacheServiceImpl.java (modified) (5 diffs)
  • SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java (modified) (6 diffs)
  • SRC/org/openmicroscopy/shoola/env/rnd/PixelsServicesFactory.java (modified) (13 diffs)
  • SRC/org/openmicroscopy/shoola/env/rnd/RenderingControlProxy.java (modified) (7 diffs)
  • SRC/org/openmicroscopy/shoola/env/rnd/data/DataSink.java (modified) (7 diffs)
  • TEST/org/openmicroscopy/shoola/env/cache/NullCacheService.java (modified) (1 diff)

Legend:

Unmodified
Added
Removed
  • trunk/SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java

    r5509 r5682  
    3636import org.openmicroscopy.shoola.env.rnd.RndProxyDef; 
    3737 
     38import pojos.DataObject; 
    3839import pojos.ImageData; 
    3940 
    … …  
    6970    private long                selectedUserID; 
    7071     
     72    /** The parent of the image or <code>null</code> if no context specified. */ 
     73    private DataObject  parent; 
     74     
     75    /**  
     76     * The grandparent of the image or <code>null</code> if no  
     77     * context specified.  
     78     */ 
     79    private DataObject  grandParent; 
     80     
    7181    /** 
    7282     * Creates a new instance. 
    … …  
    8393        selectedUserID = -1; 
    8494    } 
     95     
     96    /** 
     97     * Sets the context of the node. 
     98     *  
     99     * @param parent            The parent of the image or <code>null</code>  
     100     *                                          if no context specified. 
     101     * @param grandParent   The grandparent of the image or <code>null</code>  
     102     *                                          if no context specified. 
     103     */ 
     104    public void setContext(DataObject parent, DataObject grandParent) 
     105    { 
     106        this.parent = parent; 
     107        this.grandParent = grandParent; 
     108    } 
     109     
     110    /** 
     111     * Returns the parent of the image or <code>null</code>  
     112     * if no context specified. 
     113     *  
     114     * @return See above. 
     115     */ 
     116    public DataObject getParent() { return parent; } 
     117     
     118    /** 
     119     * Returns the grandparent of the image or <code>null</code>  
     120     * if no context specified. 
     121     *  
     122     * @return See above. 
     123     */ 
     124    public DataObject getGrandParent() { return grandParent; } 
    85125     
    86126    /** 
  • trunk/SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java

    r5509 r5682  
    108108        ImViewer view = ImViewerFactory.getImageViewer(evt.getImage(), 
    109109                                        evt.getRequesterBounds()); 
    110         if (view != null)  
     110        if (view != null) { 
    111111                view.activate(evt.getSettings(), evt.getSelectedUserID()); 
     112                view.setContext(evt.getParent(), evt.getGrandParent()); 
     113        } 
    112114    } 
    113115     
  • trunk/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java

    r5641 r5682  
    4646import org.openmicroscopy.shoola.env.rnd.RndProxyDef; 
    4747import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; 
     48 
     49import pojos.DataObject; 
    4850import pojos.ExperimenterData; 
    4951import pojos.ImageData; 
    … …  
    901903        public void setProjectedRenderingSettings(Boolean result, ImageData image); 
    902904         
     905        /** 
     906     * Sets the context of the node. 
     907     *  
     908     * @param parent            The parent of the image or <code>null</code>  
     909     *                                          if no context specified. 
     910     * @param grandParent   The grandparent of the image or <code>null</code>  
     911     *                                          if no context specified. 
     912     */ 
     913    public void setContext(DataObject parent, DataObject grandParent); 
     914         
    903915} 
  • trunk/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java

    r5630 r5682  
    8282import org.openmicroscopy.shoola.util.ui.UIUtilities; 
    8383import org.openmicroscopy.shoola.util.ui.component.AbstractComponent; 
     84 
     85import pojos.DataObject; 
    8486import pojos.ExperimenterData; 
    8587import pojos.ImageData; 
    … …  
    25862588        } 
    25872589 
     2590        /** 
     2591         * Sets the context of the node. 
     2592         *  
     2593         * @param parent                The parent of the image or <code>null</code>  
     2594         *                                              if no context specified. 
     2595         * @param grandParent   The grandparent of the image or <code>null</code>  
     2596         *                                              if no context specified. 
     2597         */ 
     2598        public void setContext(DataObject parent, DataObject grandParent) 
     2599        { 
     2600                if (model.getState() == DISCARDED) return; 
     2601                model.setContext(parent, grandParent); 
     2602        } 
     2603     
    25882604} 
  • trunk/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java

    r5657 r5682  
    6969import org.openmicroscopy.shoola.env.rnd.RndProxyDef; 
    7070import org.openmicroscopy.shoola.util.image.geom.Factory; 
     71 
     72import pojos.DataObject; 
    7173import pojos.ExperimenterData; 
    7274import pojos.ImageData; 
    … …  
    228230        private boolean                                         initMagnificationFactor; 
    229231         
     232    /** The parent of the image or <code>null</code> if no context specified. */ 
     233    private DataObject                                  parent; 
     234     
     235    /**  
     236     * The grandparent of the image or <code>null</code> if no  
     237     * context specified.  
     238     */ 
     239    private DataObject                                  grandParent; 
     240     
    230241        /** Computes the values of the {@link #sizeX} and {@link #sizeY} fields. */ 
    231242        private void computeSizes() 
    … …  
    14311442        } 
    14321443         
     1444        /** 
     1445         * Sets the context of the node. 
     1446         *  
     1447         * @param parent                The parent of the image or <code>null</code>  
     1448         *                                              if no context specified. 
     1449         * @param grandParent   The grandparent of the image or <code>null</code>  
     1450         *                                              if no context specified. 
     1451         */ 
     1452        void setContext(DataObject parent, DataObject grandParent) 
     1453        { 
     1454                this.parent = parent; 
     1455                this.grandParent = grandParent; 
     1456        } 
     1457         
     1458        /** 
     1459     * Returns the parent of the image or <code>null</code>  
     1460     * if no context specified. 
     1461     *  
     1462     * @return See above. 
     1463     */ 
     1464    DataObject getParent() { return parent; } 
     1465     
     1466    /** 
     1467     * Returns the grandparent of the image or <code>null</code>  
     1468     * if no context specified. 
     1469     *  
     1470     * @return See above. 
     1471     */ 
     1472    DataObject getGrandParent() { return grandParent; } 
     1473     
     1474     
    14331475} 
  • trunk/SRC/org/openmicroscopy/shoola/env/cache/CacheService.java

    r5574 r5682  
    5252         
    5353        /** Indicates to cache data in memory only. */ 
    54         public static final int IN_MEMORY_ONLY = 2; 
     54        public static final int IN_MEMORY = 2; 
     55         
     56        /** The default size of a cache. */ 
     57        public static final int CACHE_SIZE = 10; 
    5558         
    5659        /** 
    … …  
    6265         */ 
    6366        public int createCache(); 
     67         
     68        /** 
     69         * Creates a cache of a given type. 
     70         *  
     71         * @param type The type of cache to create. 
     72         * @param size The size of the cache. 
     73         * @return See above. 
     74         * @throws CacheServiceException        Thrown if an error occured while  
     75         *                                                                      creating the cache. 
     76         */ 
     77        public int createCache(int type, int size); 
    6478         
    6579        /** 
    … …  
    109123        public void clearCache(int cacheID); 
    110124         
     125        /** 
     126         * Resets the size (number of items in memory) of the cache,  
     127         * when a new cache is created or deleted. 
     128         *  
     129         * @param cacheID       The id of the cache. 
     130         * @param size          The size of the cache. 
     131         */ 
     132        public void setCacheSize(int cacheID, int size); 
     133         
    111134} 
  • trunk/SRC/org/openmicroscopy/shoola/env/cache/CacheServiceFactory.java

    r5574 r5682  
    111111                        public int createCache() { return -1; } 
    112112                        public int createCache(int type) { return -1; } 
     113                        public int createCache(int type, int size) { return -1; } 
    113114                        public Object getElement(int cacheID, Object key) { return null; } 
    114115                        public void removeCache(int cacheID) {} 
    115116                        public void clearCache(int cacheID) {} 
     117                        public void setCacheSize(int cacheID, int size) {} 
    116118                }; 
    117119        } 
  • trunk/SRC/org/openmicroscopy/shoola/env/cache/CacheServiceImpl.java

    r5574 r5682  
    5151        implements CacheService 
    5252{ 
    53  
     53         
    5454        /** Reference to the manager. */ 
    5555        private CacheManager manager; 
    … …  
    8787        /**  
    8888         * Implemented as specified by {@link CacheService}. 
    89          * @see CacheService#createCache(int) 
     89         * @see CacheService#createCache(int, int) 
    9090         */ 
    91         public int createCache(int type)  
     91        public int createCache(int type, int size)  
    9292        { 
    9393                Cache cache; 
     94                if (size < 0) size = 0; 
    9495                switch (type) { 
    9596                        case PERSISTENCE_ON_DISK: 
     97                                //TODO: implement. 
    9698                                return -1; 
    97                         case IN_MEMORY_ONLY: 
     99                        case IN_MEMORY: 
    98100                                cacheID++; 
    99                                 cache = new Cache(""+cacheID, 10000, false, false, 300, 600); 
     101                                //name, maximum number of elements, overflow to disk, eternal 
     102                                //time to Idle, time to live 
     103                                cache = new Cache(""+cacheID, size, true, false, 300, 600); 
    100104                                manager.addCache(cache); 
    101105                                break; 
    … …  
    108112                } 
    109113                return cacheID; 
     114                 
     115        } 
     116         
     117        /**  
     118         * Implemented as specified by {@link CacheService}. 
     119         * @see CacheService#createCache(int) 
     120         */ 
     121        public int createCache(int type)  
     122        { 
     123                return createCache(type, CACHE_SIZE); 
    110124        } 
    111125 
    … …  
    128142                Cache cache = manager.getCache(""+cacheID); 
    129143                if (cache == null) return; 
     144                if (cache.getSize() >=  
     145                        cache.getCacheConfiguration().getMaxElementsInMemory()) 
     146                        cache.flush(); 
    130147                cache.put(new Element(key, element)); 
    131148        } 
    … …  
    155172        } 
    156173 
     174        /**  
     175         * Implemented as specified by {@link CacheService}. 
     176         * @see CacheService#setCacheSize(int, int) 
     177         */ 
     178        public void setCacheSize(int cacheID, int size) 
     179        { 
     180                Cache cache = manager.getCache(""+cacheID); 
     181                if (cache == null) return; 
     182                cache.flush(); 
     183                cache.getCacheConfiguration().setMaxElementsInMemory(size); 
     184                 
     185        } 
     186         
    157187} 
  • trunk/SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java

    r5672 r5682  
    4848 
    4949//Application-internal dependencies 
    50 import org.openmicroscopy.shoola.env.LookupNames; 
    5150import org.openmicroscopy.shoola.env.data.util.PojoMapper; 
    5251import org.openmicroscopy.shoola.env.data.util.SearchDataContext; 
    5352import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; 
    5453import ome.system.UpgradeCheck; 
     54import omero.AuthenticationException; 
     55import omero.DataAccessException; 
     56import omero.ExpiredCredentialException; 
    5557import omero.InternalException; 
    5658import omero.RInt; 
    … …  
    5961import omero.RTime; 
    6062import omero.RType; 
     63import omero.SecurityViolation; 
    6164import omero.ServerError; 
     65import omero.SessionException; 
    6266import omero.client; 
    6367import omero.api.IAdminPrx; 
    … …  
    223227        private float                                   compression; 
    224228         
    225         //Blitz stuff 
    226         /** Tell us to configure ice. */ 
    227         private Properties                              iceConfig; 
    228  
    229229        /** The port to connect. */ 
    230230        private int                                             port; 
    … …  
    255255        { 
    256256                Throwable cause = t.getCause(); 
    257                 if (cause instanceof ServerError) { 
    258                          
    259                          
    260                         String s = "Cannot access data for security reasons \n";  
     257                if (cause instanceof DataAccessException) { 
     258                        String s = "Cannot access data. \n";  
    261259                        throw new DSAccessException(s+message, t); 
    262                 } 
     260                } else if (cause instanceof SecurityViolation) { 
     261                        String s = "For security reasons, cannot access data. \n";  
     262                        throw new DSAccessException(s+message, t); 
     263                } else if (cause instanceof SessionException) { 
     264                        String s = "Session is not valid. \n";  
     265                        throw new DSOutOfServiceException(s+message, t); 
     266                } else if (cause instanceof AuthenticationException) { 
     267                        String s = "Cannot initialize the session. \n";  
     268                        throw new DSOutOfServiceException(s+message, t); 
     269                } else if (cause instanceof ExpiredCredentialException) { 
     270                        String s = "Cannot initialize the session. \n";  
     271                        throw new DSOutOfServiceException(s+message, t); 
     272                } 
     273                throw new DSAccessException("Cannot access data. \n"+message, t); 
    263274        } 
    264275         
    … …  
    839850                return false; 
    840851        } 
    841          
     852 
    842853        /** 
    843854         * Creates a new instance. 
    844855         *  
    845          * @param iceConfig     The Ice configuration. 
    846          * @param dsFactory     A reference to the factory. Used whenever a broken  
    847          *                                              link is detected to get the Login Service and try  
    848          *                      reestablishing a valid link to <i>OMEDS</i>. 
    849          *                      Mustn't be <code>null</code>. 
    850          */ 
    851         OMEROGateway(Properties iceConfig, DataServicesFactory dsFactory) 
    852         { 
    853                 if (dsFactory == null)  
    854                         throw new IllegalArgumentException("No Data service factory."); 
    855                 this.dsFactory = dsFactory; 
    856                 this.iceConfig = iceConfig; 
    857                 thumbRetrieval = 0; 
    858         } 
    859  
    860         /** 
    861          * Creates a new instance. 
    862          *  
    863          * @param iceConfig     The Ice configuration. 
     856         * @param port                  The port used to connect. 
    864857         * @param dsFactory     A reference to the factory. Used whenever a broken  
    865858         *                                              link is detected to get the Login Service and try  
    … …  
    10271020                try { 
    10281021                        compression = compressionLevel; 
    1029                          
    1030                         //Put value of hostname 
    1031                         /* 
    1032                         Set keys = iceConfig.keySet(); 
    1033                         Iterator i = keys.iterator(); 
    1034                         String key, value; 
    1035                         while (i.hasNext()) { 
    1036                                 key = (String) i.next(); 
    1037                                 value = iceConfig.getProperty(key); 
    1038                                 value = value.replaceAll(LookupNames.ICE_HOSTNAME, hostName); 
    1039                                 iceConfig.put(key, value); 
    1040                         } 
    1041                         blitzClient = new client(iceConfig); 
    1042                         */ 
    10431022                        this.hostName = hostName; 
    10441023                        if (port > 0) blitzClient = new client(hostName, port); 
  • trunk/SRC/org/openmicroscopy/shoola/env/rnd/PixelsServicesFactory.java

    r5674 r5682  
    2727//Java imports 
    2828import java.awt.image.BufferedImage; 
     29import java.lang.management.ManagementFactory; 
     30import java.lang.management.MemoryUsage; 
    2931import java.util.Collection; 
    3032import java.util.HashMap; 
    … …  
    4850import org.openmicroscopy.shoola.env.data.DSOutOfServiceException; 
    4951import org.openmicroscopy.shoola.env.rnd.data.DataSink; 
    50 import org.openmicroscopy.shoola.env.rnd.roi.ROIAnalyser; 
    51  
    5252import pojos.PixelsData; 
    5353 
    … …  
    7373{ 
    7474 
     75        /** The percentage of memory used for caching. */ 
     76        private static final double             RATIO = 0.10; 
     77         
     78        /** Values used to determine the size of a cache. */ 
     79        private static final int                FACTOR = 1024*1024; 
     80         
    7581        /** The sole instance. */ 
    7682        private static PixelsServicesFactory    singleton; 
    … …  
    7985        private static Registry                 registry; 
    8086 
     87        /** The maximum amount of memory in bytes used for caching. */ 
     88        private static int                                              maxSize; 
     89         
    8190        /** 
    8291         * Converts the {@link RenderingDef} into a {@link RndProxyDef}. 
    … …  
    149158                        registry = c.getRegistry(); 
    150159                        singleton = new PixelsServicesFactory(); 
     160                        //Retrieve the maximum heap size. 
     161                        MemoryUsage usage =  
     162                                ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); 
     163                        String message = "Heap memory usage: max "+usage.getMax(); 
     164                        registry.getLogger().info(singleton, message); 
     165                        //percentage of memory used for caching. 
     166                        maxSize = (int) (RATIO*usage.getMax())/FACTOR;  
    151167                } 
    152168                return singleton; 
    … …  
    234250                singleton.rndSvcProxies.get(new Long(pixelsID)); 
    235251                if (proxy != null) { 
    236                         proxy.shutDown(); 
    237252                        proxy.resetRenderingEngine(re, convert(def)); 
    238253                } 
    … …  
    259274                        proxy.shutDown(); 
    260275                        singleton.rndSvcProxies.remove(new Long(pixelsID)); 
     276                        getCacheSize(); 
    261277                } 
    262278        } 
    … …  
    312328                                singleton.pixelsSource.isSame(pixels.getId())) 
    313329                        return singleton.pixelsSource; 
    314                 singleton.pixelsSource = DataSink.makeNew(pixels, registry); 
     330                int size = getCacheSize(); 
     331                boolean cacheInMemory = true; 
     332                if (size <= 0) cacheInMemory = false; 
     333                singleton.pixelsSource = DataSink.makeNew(pixels, registry,  
     334                                                                                                cacheInMemory); 
    315335                return singleton.pixelsSource; 
    316336        } 
    … …  
    329349                        throw new IllegalArgumentException("Not allow to access method."); 
    330350                if (singleton.pixelsSource != null &&  
    331                                 singleton.pixelsSource.isSame(pixelsID)) 
    332                         singleton.pixelsSource.eraseCache(); 
     351                                singleton.pixelsSource.isSame(pixelsID)) { 
     352                        int size = getCacheSize(); 
     353                        boolean cacheInMemory = true; 
     354                        if (size <= 0) cacheInMemory = false; 
     355                        singleton.pixelsSource.clearCache(); 
     356                        singleton.pixelsSource.setCacheInMemory(cacheInMemory); 
     357                } 
    333358        } 
    334359         
    … …  
    342367         * @param pDef      The plane to render. 
    343368         * @return See above. 
     369         *  
     370     * @throws RenderingServiceException        If an error occured while setting  
     371     *                                                                          the value. 
     372     * @throws DSOutOfServiceException          If the connection is broken. 
    344373         */ 
    345374        public static BufferedImage render(Registry context, Long pixelsID,  
    346375                        PlaneDef pDef) 
     376                throws RenderingServiceException, DSOutOfServiceException 
    347377        { 
    348378                if (!(context.equals(registry))) 
    … …  
    353383                        throw new RuntimeException("No rendering service " + 
    354384                &nbs