/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.dimm.vsm.fsengine;

import de.dimm.vsm.records.DedupHashBlock;
import de.dimm.vsm.records.StoragePool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Administrator
 */
public class JavaHashCache extends HashCache
{
    HashMap<String,Long> hashMap;

    public JavaHashCache( StoragePool pool)
    {
        super(pool);
        hashMap = new HashMap<String, Long>();
    }


    @Override
    public void fill( String hash, long id )
    {
        hashMap.put(hash, id);
    }
    
    

    @Override
    public long getDhbIdx( String hash )
    {
        Long l = hashMap.get(hash);
        if (l != null)
            return l.longValue();
        
        return -1;
    }
    @Override
    public void addDhb( String hash, long idx )
    {
        hashMap.put(hash, idx);
    }

    @Override
    public long size()
    {
        return hashMap.size();
    }

    @Override
    public void removeDhb( DedupHashBlock dhb )
    {
        hashMap.remove(dhb.getHashvalue());
    }

    
    @Override
    public List<String> getUrlUnsafeHashes()
    {
        ArrayList<String> ret = new ArrayList<String>();
        Set<String> set = hashMap.keySet();

        for (Iterator<String> it = set.iterator(); it.hasNext();)
        {
            String hash = it.next();
            boolean found = false;

            char lastCh = hash.charAt( hash.length() - 1 );

            // DETECT PADDED HASHES
            if (lastCh == '=')
                found = true;

            if (!found)
            {
                for (int i = 0; i < hash.length(); i++)
                {
                    char ch = hash.charAt(i);
                    if (ch == '/' || ch == '+')
                    {
                        found = true;
                        break;
                    }
                }
            }
            if (found)
            {
                ret.add(hash);
            }
        }
        return ret;
    }

    @Override
    public boolean shutdown()
    {
        hashMap.clear();
        return true;
    }

}

@@ -253,23 +253,24 @@
 va.util.
-HashMap
+Iterator
 ;%0Aimport
@@ -276,32 +276,50 @@
 t java.util.
-Iterator
+List;%0Aimport java.util.Map
 ;%0Aimport jav
@@ -317,35 +317,34 @@
 mport java.util.
-Lis
+Se
 t;%0Aimport java.u
@@ -347,19 +347,44 @@
 va.util.
-Set
+concurrent.ConcurrentHashMap
 ;%0A%0A/**%0A 
@@ -465,20 +465,16 @@
 e%0A%7B%0A    
-Hash
 Map%3CStri
@@ -589,28 +589,26 @@
 new 
-HashMap%3CString, Long
+ConcurrentHashMap%3C
 %3E();
@@ -728,17 +728,16 @@
   %0A    %0A
-%0A
     @Ove

Use ConcurrentHashMap