📄 freespacemanager.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Core License version 1 published by ozone-db.org.//// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.//// $Id: FreeSpaceManager.java,v 1.1.2.1 2004/04/10 10:06:51 per_nyfelt Exp $package org.ozoneDB.core.storage.gammaStore;import java.util.Collection;import java.util.HashSet;import java.util.LinkedList;import java.util.Properties;import java.util.SortedSet;import java.util.TreeSet;import org.ozoneDB.core.ConfigurationException;import org.ozoneDB.core.storage.PropertyConfigurable;import org.ozoneDB.core.storage.PropertyInfo;public final class FreeSpaceManager implements PropertyConfigurable { public static final PropertyInfo MAXFREESPACESIZEDIFFERENCE = new PropertyInfo( ".maxFreeSpaceSizeDifference", "int", "8", "Maximum difference in size (bytes) when searching for free space.", new String[] { "0", "5", "28" } ); public static final PropertyInfo MAXSIZE = new PropertyInfo( ".maxSize", "int", "1000", "If the number of free space entries becomes higher than this value, " + "TODO: what exactly?", new String[] { "100", "1000" } ); private TreeSet freeSpaces; private int maxSizeDifference; private int maxSize; private String prefix; public FreeSpaceManager() { } /** * As prescribed by the <code>PropertyConfigurable</code> interface. */ public FreeSpaceManager(Properties properties, String prefix) { this.prefix = prefix; try { setMaxFreeSpaceSizeDifference(Integer.parseInt(properties.getProperty(prefix + MAXFREESPACESIZEDIFFERENCE.getKey(), MAXFREESPACESIZEDIFFERENCE.getDefaultValue()))); setMaxSize(Integer.parseInt(properties.getProperty(prefix + MAXSIZE.getKey(), MAXSIZE.getDefaultValue()))); } catch (NumberFormatException e) { throw new ConfigurationException("invalid value", e); } } /** * Returns a block of free space in a cluster when there is free space that * is equal or grater than the specified size and smaller or equal to the * specified size plus <code>getMaxSizeDifference()</code>. The returned * <code>FreeSpace</code> is no longer regarded as 'free'. If no apropriate * free space is found, then a <code>null</code> value is returned. * * @return a free block of space, or <code>null</code> if there is none */ public synchronized FreeSpace findFreeSpace(int size) { FreeSpace searchKey = new FreeSpace(0, 0, size); SortedSet found = freeSpaces.tailSet(searchKey); FreeSpace result = (FreeSpace) found.first(); if (result.getSize() <= size + maxSizeDifference) { found.remove(result); size--; } else { result = null; } return result; } /** * Registers a block of free space. */ public synchronized void registerFreespace(FreeSpace freeSpace) { freeSpaces.add(freeSpace); } public synchronized void registerFreespace(int clusterId, int position, int size) { registerFreespace(new FreeSpace(clusterId, position, size)); } public int getMaxFreeSpaceSizeDifference() { return maxSizeDifference; } public void setMaxFreeSpaceSizeDifference(int maxSizeDifference) { this.maxSizeDifference = maxSizeDifference; } public int getMaxSize() { return maxSize; } public void setMaxSize(int maxSize) { this.maxSize = maxSize; } public Collection getPropertyInfos() { Collection result = new LinkedList(); result.add(MAXFREESPACESIZEDIFFERENCE); result.add(MAXSIZE); return result; } public String getPrefix() { return prefix; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -