Formatting cleanup. Ignore some generated files.

0.6.6-post-fixes
Jeff Ames 2009-06-09 18:07:35 +00:00
parent 135ff63c3d
commit a7fcacf8f3
11 changed files with 264 additions and 263 deletions

View File

@ -81,7 +81,7 @@ namespace OpenSim.Framework
/// 30 minutes. /// 30 minutes.
/// </para> /// </para>
/// </remarks> /// </remarks>
public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes( 30.0 ); public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes(30.0);
/// <summary> /// <summary>
/// Minimal allowed expiration time. /// Minimal allowed expiration time.
@ -91,7 +91,7 @@ namespace OpenSim.Framework
/// 5 minutes. /// 5 minutes.
/// </para> /// </para>
/// </remarks> /// </remarks>
public static readonly TimeSpan MinExpirationTime = TimeSpan.FromSeconds( 10.0 ); public static readonly TimeSpan MinExpirationTime = TimeSpan.FromSeconds(10.0);
/// <summary> /// <summary>
/// Comparer used to compare element keys. /// Comparer used to compare element keys.
@ -171,7 +171,7 @@ namespace OpenSim.Framework
/// Initializes a new instance of the <see cref="CnmMemoryCache{TKey,TValue}"/> class. /// Initializes a new instance of the <see cref="CnmMemoryCache{TKey,TValue}"/> class.
/// </summary> /// </summary>
public CnmMemoryCache() public CnmMemoryCache()
: this( DefaultMaxSize ) : this(DefaultMaxSize)
{ {
} }
@ -181,8 +181,8 @@ namespace OpenSim.Framework
/// <param name="maximalSize"> /// <param name="maximalSize">
/// Maximal cache size. /// Maximal cache size.
/// </param> /// </param>
public CnmMemoryCache( long maximalSize ) public CnmMemoryCache(long maximalSize)
: this( maximalSize, DefaultMaxCount ) : this(maximalSize, DefaultMaxCount)
{ {
} }
@ -195,8 +195,8 @@ namespace OpenSim.Framework
/// <param name="maximalCount"> /// <param name="maximalCount">
/// Maximal element count. /// Maximal element count.
/// </param> /// </param>
public CnmMemoryCache( long maximalSize, int maximalCount ) public CnmMemoryCache(long maximalSize, int maximalCount)
: this( maximalSize, maximalCount, DefaultExpirationTime ) : this(maximalSize, maximalCount, DefaultExpirationTime)
{ {
} }
@ -212,8 +212,8 @@ namespace OpenSim.Framework
/// <param name="expirationTime"> /// <param name="expirationTime">
/// Elements expiration time. /// Elements expiration time.
/// </param> /// </param>
public CnmMemoryCache( long maximalSize, int maximalCount, TimeSpan expirationTime ) public CnmMemoryCache(long maximalSize, int maximalCount, TimeSpan expirationTime)
: this( maximalSize, maximalCount, expirationTime, EqualityComparer<TKey>.Default ) : this(maximalSize, maximalCount, expirationTime, EqualityComparer<TKey>.Default)
{ {
} }
@ -235,21 +235,21 @@ namespace OpenSim.Framework
/// <exception cref="ArgumentNullException"> /// <exception cref="ArgumentNullException">
/// <see cref="comparer"/>is <see langword="null"/> reference. /// <see cref="comparer"/>is <see langword="null"/> reference.
/// </exception> /// </exception>
public CnmMemoryCache( long maximalSize, public CnmMemoryCache(long maximalSize,
int maximalCount, int maximalCount,
TimeSpan expirationTime, TimeSpan expirationTime,
IEqualityComparer<TKey> comparer ) IEqualityComparer<TKey> comparer)
{ {
if( comparer == null ) if (comparer == null)
throw new ArgumentNullException( "comparer" ); throw new ArgumentNullException("comparer");
if( expirationTime < MinExpirationTime ) if (expirationTime < MinExpirationTime)
expirationTime = MinExpirationTime; expirationTime = MinExpirationTime;
if( maximalCount < 8 ) if (maximalCount < 8)
maximalCount = 8; maximalCount = 8;
if( maximalSize < 8 ) if (maximalSize < 8)
maximalSize = 8; maximalSize = 8;
if( maximalCount > maximalSize ) if (maximalCount > maximalSize)
maximalCount = (int) maximalSize; maximalCount = (int) maximalSize;
Comparer = comparer; Comparer = comparer;
@ -275,14 +275,14 @@ namespace OpenSim.Framework
/// <param name="size"> /// <param name="size">
/// The element's size. /// The element's size.
/// </param> /// </param>
protected virtual void AddToNewGeneration( int bucketIndex, TKey key, TValue value, long size ) protected virtual void AddToNewGeneration(int bucketIndex, TKey key, TValue value, long size)
{ {
// Add to newest generation // Add to newest generation
if( !m_newGeneration.Set( bucketIndex, key, value, size ) ) if (!m_newGeneration.Set(bucketIndex, key, value, size))
{ {
// Failed to add new generation // Failed to add new generation
RecycleGenerations(); RecycleGenerations();
m_newGeneration.Set( bucketIndex, key, value, size ); m_newGeneration.Set(bucketIndex, key, value, size);
} }
m_version++; m_version++;
@ -314,9 +314,9 @@ namespace OpenSim.Framework
/// For example: key's hash is 72, bucket count is 5, element's bucket index is 72 % 5 = 2. /// For example: key's hash is 72, bucket count is 5, element's bucket index is 72 % 5 = 2.
/// </para> /// </para>
/// </remarks> /// </remarks>
protected virtual int GetBucketIndex( TKey key ) protected virtual int GetBucketIndex(TKey key)
{ {
return (Comparer.GetHashCode( key ) & 0x7FFFFFFF) % m_generationBucketCount; return (Comparer.GetHashCode(key) & 0x7FFFFFFF) % m_generationBucketCount;
} }
/// <summary> /// <summary>
@ -325,7 +325,7 @@ namespace OpenSim.Framework
/// <param name="generation"> /// <param name="generation">
/// The generation that is purged. /// The generation that is purged.
/// </param> /// </param>
protected virtual void PurgeGeneration( IGeneration generation ) protected virtual void PurgeGeneration(IGeneration generation)
{ {
generation.Clear(); generation.Clear();
m_version++; m_version++;
@ -339,7 +339,7 @@ namespace OpenSim.Framework
// Do this only one in every m_operationsBetweenTimeChecks // Do this only one in every m_operationsBetweenTimeChecks
// Fetching time is using several millisecons - it is better not to do all time. // Fetching time is using several millisecons - it is better not to do all time.
m_operationsBetweenTimeChecks--; m_operationsBetweenTimeChecks--;
if( m_operationsBetweenTimeChecks <= 0 ) if (m_operationsBetweenTimeChecks <= 0)
PurgeExpired(); PurgeExpired();
} }
@ -355,10 +355,10 @@ namespace OpenSim.Framework
m_generationElementCount = MaxCount / 2; m_generationElementCount = MaxCount / 2;
// Buckets need to be prime number to get better spread of hash values // Buckets need to be prime number to get better spread of hash values
m_generationBucketCount = PrimeNumberHelper.GetPrime( m_generationElementCount ); m_generationBucketCount = PrimeNumberHelper.GetPrime(m_generationElementCount);
m_newGeneration = new HashGeneration( this ); m_newGeneration = new HashGeneration(this);
m_oldGeneration = new HashGeneration( this ); m_oldGeneration = new HashGeneration(this);
m_oldGeneration.MakeOld(); m_oldGeneration.MakeOld();
} }
@ -399,7 +399,7 @@ namespace OpenSim.Framework
/// <param name="cache"> /// <param name="cache">
/// The cache. /// The cache.
/// </param> /// </param>
public Enumerator( CnmMemoryCache<TKey, TValue> cache ) public Enumerator(CnmMemoryCache<TKey, TValue> cache)
{ {
m_generationEnumerators[ 0 ] = cache.m_newGeneration.GetEnumerator(); m_generationEnumerators[ 0 ] = cache.m_newGeneration.GetEnumerator();
m_generationEnumerators[ 1 ] = cache.m_oldGeneration.GetEnumerator(); m_generationEnumerators[ 1 ] = cache.m_oldGeneration.GetEnumerator();
@ -420,7 +420,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
if( m_currentEnumerator == -1 || m_currentEnumerator >= m_generationEnumerators.Length ) if (m_currentEnumerator == -1 || m_currentEnumerator >= m_generationEnumerators.Length)
throw new InvalidOperationException(); throw new InvalidOperationException();
return m_generationEnumerators[ m_currentEnumerator ].Current; return m_generationEnumerators[ m_currentEnumerator ].Current;
@ -461,12 +461,12 @@ namespace OpenSim.Framework
/// <filterpriority>2</filterpriority> /// <filterpriority>2</filterpriority>
public bool MoveNext() public bool MoveNext()
{ {
if( m_currentEnumerator == -1 ) if (m_currentEnumerator == -1)
m_currentEnumerator = 0; m_currentEnumerator = 0;
while( m_currentEnumerator < m_generationEnumerators.Length ) while (m_currentEnumerator < m_generationEnumerators.Length)
{ {
if( m_generationEnumerators[ m_currentEnumerator ].MoveNext() ) if (m_generationEnumerators[ m_currentEnumerator ].MoveNext())
return true; return true;
m_currentEnumerator++; m_currentEnumerator++;
@ -484,7 +484,7 @@ namespace OpenSim.Framework
/// <filterpriority>2</filterpriority> /// <filterpriority>2</filterpriority>
public void Reset() public void Reset()
{ {
foreach( IEnumerator<KeyValuePair<TKey, TValue>> enumerator in m_generationEnumerators ) foreach (IEnumerator<KeyValuePair<TKey, TValue>> enumerator in m_generationEnumerators)
{ {
enumerator.Reset(); enumerator.Reset();
} }
@ -582,7 +582,7 @@ namespace OpenSim.Framework
/// <param name="cache"> /// <param name="cache">
/// The cache. /// The cache.
/// </param> /// </param>
public HashGeneration( CnmMemoryCache<TKey, TValue> cache ) public HashGeneration(CnmMemoryCache<TKey, TValue> cache)
{ {
m_cache = cache; m_cache = cache;
m_elements = new Element[m_cache.m_generationElementCount]; m_elements = new Element[m_cache.m_generationElementCount];
@ -608,16 +608,16 @@ namespace OpenSim.Framework
/// <returns> /// <returns>
/// Element's index, if found from the generation; -1 otherwise (if element is not found the generation). /// Element's index, if found from the generation; -1 otherwise (if element is not found the generation).
/// </returns> /// </returns>
private int FindElementIndex( int bucketIndex, TKey key, bool moveToFront, out int previousIndex ) private int FindElementIndex(int bucketIndex, TKey key, bool moveToFront, out int previousIndex)
{ {
previousIndex = -1; previousIndex = -1;
int elementIndex = m_buckets[ bucketIndex ]; int elementIndex = m_buckets[ bucketIndex ];
while( elementIndex >= 0 ) while (elementIndex >= 0)
{ {
if( m_cache.Comparer.Equals( key, m_elements[ elementIndex ].Key ) ) if (m_cache.Comparer.Equals(key, m_elements[ elementIndex ].Key))
{ {
// Found match // Found match
if( moveToFront && previousIndex >= 0 ) if (moveToFront && previousIndex >= 0)
{ {
// Move entry to front // Move entry to front
m_elements[ previousIndex ].Next = m_elements[ elementIndex ].Next; m_elements[ previousIndex ].Next = m_elements[ elementIndex ].Next;
@ -648,9 +648,9 @@ namespace OpenSim.Framework
/// <param name="previousIndex"> /// <param name="previousIndex">
/// The element's previous index. /// The element's previous index.
/// </param> /// </param>
private void RemoveElement( int bucketIndex, int entryIndex, int previousIndex ) private void RemoveElement(int bucketIndex, int entryIndex, int previousIndex)
{ {
if( previousIndex >= 0 ) if (previousIndex >= 0)
m_elements[ previousIndex ].Next = m_elements[ entryIndex ].Next; m_elements[ previousIndex ].Next = m_elements[ entryIndex ].Next;
else else
m_buckets[ bucketIndex ] = m_elements[ entryIndex ].Next; m_buckets[ bucketIndex ] = m_elements[ entryIndex ].Next;
@ -755,7 +755,7 @@ namespace OpenSim.Framework
/// <param name="generation"> /// <param name="generation">
/// The generation. /// The generation.
/// </param> /// </param>
public Enumerator( HashGeneration generation ) public Enumerator(HashGeneration generation)
{ {
m_generation = generation; m_generation = generation;
m_version = m_generation.m_cache.m_version; m_version = m_generation.m_cache.m_version;
@ -776,7 +776,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
if( m_currentIndex == 0 || m_currentIndex >= m_generation.Count ) if (m_currentIndex == 0 || m_currentIndex >= m_generation.Count)
throw new InvalidOperationException(); throw new InvalidOperationException();
return m_current; return m_current;
@ -816,19 +816,19 @@ namespace OpenSim.Framework
/// </exception> /// </exception>
public bool MoveNext() public bool MoveNext()
{ {
if( m_version != m_generation.m_cache.m_version ) if (m_version != m_generation.m_cache.m_version)
throw new InvalidOperationException(); throw new InvalidOperationException();
while( m_currentIndex < m_generation.Count ) while (m_currentIndex < m_generation.Count)
{ {
if( m_generation.m_elements[ m_currentIndex ].IsFree ) if (m_generation.m_elements[ m_currentIndex ].IsFree)
{ {
m_currentIndex++; m_currentIndex++;
continue; continue;
} }
m_current = new KeyValuePair<TKey, TValue>( m_generation.m_elements[ m_currentIndex ].Key, m_current = new KeyValuePair<TKey, TValue>(m_generation.m_elements[ m_currentIndex ].Key,
m_generation.m_elements[ m_currentIndex ].Value ); m_generation.m_elements[ m_currentIndex ].Value);
m_currentIndex++; m_currentIndex++;
return true; return true;
} }
@ -846,7 +846,7 @@ namespace OpenSim.Framework
/// <filterpriority>2</filterpriority> /// <filterpriority>2</filterpriority>
public void Reset() public void Reset()
{ {
if( m_version != m_generation.m_cache.m_version ) if (m_version != m_generation.m_cache.m_version)
throw new InvalidOperationException(); throw new InvalidOperationException();
m_currentIndex = 0; m_currentIndex = 0;
@ -907,12 +907,12 @@ namespace OpenSim.Framework
/// <seealso cref="IGeneration.MakeOld"/> /// <seealso cref="IGeneration.MakeOld"/>
public void Clear() public void Clear()
{ {
for( int i = m_buckets.Length - 1 ; i >= 0 ; i-- ) for (int i = m_buckets.Length - 1 ; i >= 0 ; i--)
{ {
m_buckets[ i ] = -1; m_buckets[ i ] = -1;
} }
Array.Clear( m_elements, 0, m_elements.Length ); Array.Clear(m_elements, 0, m_elements.Length);
Size = 0; Size = 0;
m_firstFreeElement = -1; m_firstFreeElement = -1;
m_freeCount = 0; m_freeCount = 0;
@ -934,10 +934,10 @@ namespace OpenSim.Framework
/// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>; /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>;
/// otherwise <see langword="false"/>. /// otherwise <see langword="false"/>.
/// </returns> /// </returns>
public bool Contains( int bucketIndex, TKey key ) public bool Contains(int bucketIndex, TKey key)
{ {
int previousIndex; int previousIndex;
if( FindElementIndex( bucketIndex, key, true, out previousIndex ) == -1 ) if (FindElementIndex(bucketIndex, key, true, out previousIndex) == -1)
return false; return false;
AccessedSinceLastTimeCheck = true; AccessedSinceLastTimeCheck = true;
@ -953,7 +953,7 @@ namespace OpenSim.Framework
/// <filterpriority>1</filterpriority> /// <filterpriority>1</filterpriority>
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{ {
return new Enumerator( this ); return new Enumerator(this);
} }
/// <summary> /// <summary>
@ -980,13 +980,13 @@ namespace OpenSim.Framework
/// <returns> /// <returns>
/// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>. /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>.
/// </returns> /// </returns>
public bool Remove( int bucketIndex, TKey key ) public bool Remove(int bucketIndex, TKey key)
{ {
int previousIndex; int previousIndex;
int entryIndex = FindElementIndex( bucketIndex, key, false, out previousIndex ); int entryIndex = FindElementIndex(bucketIndex, key, false, out previousIndex);
if( entryIndex != -1 ) if (entryIndex != -1)
{ {
RemoveElement( bucketIndex, entryIndex, previousIndex ); RemoveElement(bucketIndex, entryIndex, previousIndex);
AccessedSinceLastTimeCheck = true; AccessedSinceLastTimeCheck = true;
return true; return true;
} }
@ -1020,18 +1020,18 @@ namespace OpenSim.Framework
/// size must fit generation's limits, before element is added to generation. /// size must fit generation's limits, before element is added to generation.
/// </para> /// </para>
/// </remarks> /// </remarks>
public bool Set( int bucketIndex, TKey key, TValue value, long size ) public bool Set(int bucketIndex, TKey key, TValue value, long size)
{ {
Debug.Assert( m_newGeneration, "It is possible to insert new elements only to newest generation." ); Debug.Assert(m_newGeneration, "It is possible to insert new elements only to newest generation.");
Debug.Assert( size > 0, "New element size should be more than 0." ); Debug.Assert(size > 0, "New element size should be more than 0.");
int previousIndex; int previousIndex;
int elementIndex = FindElementIndex( bucketIndex, key, true, out previousIndex ); int elementIndex = FindElementIndex(bucketIndex, key, true, out previousIndex);
if( elementIndex == -1 ) if (elementIndex == -1)
{ {
// New key // New key
if( Size + size > m_cache.m_generationMaxSize || if (Size + size > m_cache.m_generationMaxSize ||
(m_nextUnusedElement == m_cache.m_generationElementCount && m_freeCount == 0) ) (m_nextUnusedElement == m_cache.m_generationElementCount && m_freeCount == 0))
{ {
// Generation is full // Generation is full
return false; return false;
@ -1041,7 +1041,7 @@ namespace OpenSim.Framework
Size += size; Size += size;
// Get first free entry and update free entry list // Get first free entry and update free entry list
if( m_firstFreeElement != -1 ) if (m_firstFreeElement != -1)
{ {
// There was entry that was removed // There was entry that was removed
elementIndex = m_firstFreeElement; elementIndex = m_firstFreeElement;
@ -1055,7 +1055,7 @@ namespace OpenSim.Framework
m_nextUnusedElement++; m_nextUnusedElement++;
} }
Debug.Assert( m_elements[ elementIndex ].IsFree, "Allocated element is not free." ); Debug.Assert(m_elements[ elementIndex ].IsFree, "Allocated element is not free.");
// Move new entry to front // Move new entry to front
m_elements[ elementIndex ].Next = m_buckets[ bucketIndex ]; m_elements[ elementIndex ].Next = m_buckets[ bucketIndex ];
@ -1067,12 +1067,12 @@ namespace OpenSim.Framework
else else
{ {
// Existing key // Existing key
if( Size - m_elements[ elementIndex ].Size + size > m_cache.m_generationMaxSize ) if (Size - m_elements[ elementIndex ].Size + size > m_cache.m_generationMaxSize)
{ {
// Generation is full // Generation is full
// Remove existing element, because generation is going to be recycled to // Remove existing element, because generation is going to be recycled to
// old generation and element is stored to new generation // old generation and element is stored to new generation
RemoveElement( bucketIndex, elementIndex, previousIndex ); RemoveElement(bucketIndex, elementIndex, previousIndex);
return false; return false;
} }
@ -1113,12 +1113,12 @@ namespace OpenSim.Framework
/// are set to default value (default(TValue) and 0). /// are set to default value (default(TValue) and 0).
/// </para> /// </para>
/// </remarks> /// </remarks>
public bool TryGetValue( int bucketIndex, TKey key, out TValue value, out long size ) public bool TryGetValue(int bucketIndex, TKey key, out TValue value, out long size)
{ {
// Find entry index, // Find entry index,
int previousIndex; int previousIndex;
int elementIndex = FindElementIndex( bucketIndex, key, m_newGeneration, out previousIndex ); int elementIndex = FindElementIndex(bucketIndex, key, m_newGeneration, out previousIndex);
if( elementIndex == -1 ) if (elementIndex == -1)
{ {
value = default(TValue); value = default(TValue);
size = 0; size = 0;
@ -1128,10 +1128,10 @@ namespace OpenSim.Framework
value = m_elements[ elementIndex ].Value; value = m_elements[ elementIndex ].Value;
size = m_elements[ elementIndex ].Size; size = m_elements[ elementIndex ].Size;
if( !m_newGeneration ) if (!m_newGeneration)
{ {
// Old generation - remove element, because it is moved to new generation // Old generation - remove element, because it is moved to new generation
RemoveElement( bucketIndex, elementIndex, previousIndex ); RemoveElement(bucketIndex, elementIndex, previousIndex);
} }
AccessedSinceLastTimeCheck = true; AccessedSinceLastTimeCheck = true;
@ -1214,7 +1214,7 @@ namespace OpenSim.Framework
/// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>; /// <see langword="true"/>if the <see cref="IGeneration"/> contains an element with the <see cref="key"/>;
/// otherwise <see langword="false"/>. /// otherwise <see langword="false"/>.
/// </returns> /// </returns>
bool Contains( int bucketIndex, TKey key ); bool Contains(int bucketIndex, TKey key);
/// <summary> /// <summary>
/// Make from generation old generation. /// Make from generation old generation.
@ -1237,7 +1237,7 @@ namespace OpenSim.Framework
/// <returns> /// <returns>
/// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>. /// <see langword="true"/>, if remove was successful; otherwise <see langword="false"/>.
/// </returns> /// </returns>
bool Remove( int bucketIndex, TKey key ); bool Remove(int bucketIndex, TKey key);
/// <summary> /// <summary>
/// Set or add element to generation. /// Set or add element to generation.
@ -1265,7 +1265,7 @@ namespace OpenSim.Framework
/// size must fit generation's limits, before element is added to generation. /// size must fit generation's limits, before element is added to generation.
/// </para> /// </para>
/// </remarks> /// </remarks>
bool Set( int bucketIndex, TKey key, TValue value, long size ); bool Set(int bucketIndex, TKey key, TValue value, long size);
/// <summary> /// <summary>
/// Try to get element associated with key. /// Try to get element associated with key.
@ -1291,7 +1291,7 @@ namespace OpenSim.Framework
/// are set to default value (default(TValue) and 0). /// are set to default value (default(TValue) and 0).
/// </para> /// </para>
/// </remarks> /// </remarks>
bool TryGetValue( int bucketIndex, TKey key, out TValue value, out long size ); bool TryGetValue(int bucketIndex, TKey key, out TValue value, out long size);
} }
#endregion #endregion
@ -1357,10 +1357,10 @@ namespace OpenSim.Framework
set set
{ {
if( value < MinExpirationTime ) if (value < MinExpirationTime)
value = MinExpirationTime; value = MinExpirationTime;
if( m_expirationTime == value ) if (m_expirationTime == value)
return; return;
m_newGeneration.ExpirationTime = (m_newGeneration.ExpirationTime - m_expirationTime) + value; m_newGeneration.ExpirationTime = (m_newGeneration.ExpirationTime - m_expirationTime) + value;
@ -1478,9 +1478,9 @@ namespace OpenSim.Framework
set set
{ {
if( value < 8 ) if (value < 8)
value = 8; value = 8;
if( m_maxCount == value ) if (m_maxCount == value)
return; return;
m_maxCount = value; m_maxCount = value;
@ -1535,9 +1535,9 @@ namespace OpenSim.Framework
set set
{ {
if( value < 8 ) if (value < 8)
value = 8; value = 8;
if( m_maxSize == value ) if (m_maxSize == value)
return; return;
m_maxSize = value; m_maxSize = value;
@ -1618,7 +1618,7 @@ namespace OpenSim.Framework
/// <filterpriority>1</filterpriority> /// <filterpriority>1</filterpriority>
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{ {
return new Enumerator( this ); return new Enumerator(this);
} }
/// <summary> /// <summary>
@ -1644,28 +1644,28 @@ namespace OpenSim.Framework
{ {
m_operationsBetweenTimeChecks = DefaultOperationsBetweenTimeChecks; m_operationsBetweenTimeChecks = DefaultOperationsBetweenTimeChecks;
if( !IsTimeLimited ) if (!IsTimeLimited)
return; return;
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
if( m_newGeneration.AccessedSinceLastTimeCheck ) if (m_newGeneration.AccessedSinceLastTimeCheck)
{ {
// New generation has been accessed since last check // New generation has been accessed since last check
// Update it's expiration time. // Update it's expiration time.
m_newGeneration.ExpirationTime = now + ExpirationTime; m_newGeneration.ExpirationTime = now + ExpirationTime;
m_newGeneration.AccessedSinceLastTimeCheck = false; m_newGeneration.AccessedSinceLastTimeCheck = false;
} }
else if( m_newGeneration.ExpirationTime < now ) else if (m_newGeneration.ExpirationTime < now)
{ {
// New generation has been expired. // New generation has been expired.
// --> also old generation must be expired. // --> also old generation must be expired.
PurgeGeneration( m_newGeneration ); PurgeGeneration(m_newGeneration);
PurgeGeneration( m_oldGeneration ); PurgeGeneration(m_oldGeneration);
return; return;
} }
if( m_oldGeneration.ExpirationTime < now ) if (m_oldGeneration.ExpirationTime < now)
PurgeGeneration( m_oldGeneration ); PurgeGeneration(m_oldGeneration);
} }
/// <summary> /// <summary>
@ -1682,15 +1682,15 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public void Remove( TKey key ) public void Remove(TKey key)
{ {
if( key == null ) if (key == null)
throw new ArgumentNullException( "key" ); throw new ArgumentNullException("key");
int bucketIndex = GetBucketIndex( key ); int bucketIndex = GetBucketIndex(key);
if( !m_newGeneration.Remove( bucketIndex, key ) ) if (!m_newGeneration.Remove(bucketIndex, key))
{ {
if( !m_oldGeneration.Remove( bucketIndex, key ) ) if (!m_oldGeneration.Remove(bucketIndex, key))
{ {
CheckExpired(); CheckExpired();
return; return;
@ -1715,19 +1715,19 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public void RemoveRange( IEnumerable<TKey> keys ) public void RemoveRange(IEnumerable<TKey> keys)
{ {
if( keys == null ) if (keys == null)
throw new ArgumentNullException( "keys" ); throw new ArgumentNullException("keys");
foreach( TKey key in keys ) foreach (TKey key in keys)
{ {
if( key == null ) if (key == null)
continue; continue;
int bucketIndex = GetBucketIndex( key ); int bucketIndex = GetBucketIndex(key);
if( !m_newGeneration.Remove( bucketIndex, key ) ) if (!m_newGeneration.Remove(bucketIndex, key))
m_oldGeneration.Remove( bucketIndex, key ); m_oldGeneration.Remove(bucketIndex, key);
} }
CheckExpired(); CheckExpired();
@ -1779,27 +1779,27 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public bool Set( TKey key, TValue value, long size ) public bool Set(TKey key, TValue value, long size)
{ {
if( key == null ) if (key == null)
throw new ArgumentNullException( "key" ); throw new ArgumentNullException("key");
if( size < 0 ) if (size < 0)
throw new ArgumentOutOfRangeException( "size", size, "Value's size can't be less than 0." ); throw new ArgumentOutOfRangeException("size", size, "Value's size can't be less than 0.");
if( size > MaxElementSize ) if (size > MaxElementSize)
{ {
// Entry size is too big to fit cache - ignore it // Entry size is too big to fit cache - ignore it
Remove( key ); Remove(key);
return false; return false;
} }
if( size == 0 ) if (size == 0)
size = 1; size = 1;
int bucketIndex = GetBucketIndex( key ); int bucketIndex = GetBucketIndex(key);
m_oldGeneration.Remove( bucketIndex, key ); m_oldGeneration.Remove(bucketIndex, key);
AddToNewGeneration( bucketIndex, key, value, size ); AddToNewGeneration(bucketIndex, key, value, size);
CheckExpired(); CheckExpired();
return true; return true;
@ -1828,23 +1828,23 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/> /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public bool TryGetValue( TKey key, out TValue value ) public bool TryGetValue(TKey key, out TValue value)
{ {
if( key == null ) if (key == null)
throw new ArgumentNullException( "key" ); throw new ArgumentNullException("key");
int bucketIndex = GetBucketIndex( key ); int bucketIndex = GetBucketIndex(key);
long size; long size;
if( m_newGeneration.TryGetValue( bucketIndex, key, out value, out size ) ) if (m_newGeneration.TryGetValue(bucketIndex, key, out value, out size))
{ {
CheckExpired(); CheckExpired();
return true; return true;
} }
if( m_oldGeneration.TryGetValue( bucketIndex, key, out value, out size ) ) if (m_oldGeneration.TryGetValue(bucketIndex, key, out value, out size))
{ {
// Move element to new generation // Move element to new generation
AddToNewGeneration( bucketIndex, key, value, size ); AddToNewGeneration(bucketIndex, key, value, size);
CheckExpired(); CheckExpired();
return true; return true;
} }

View File

@ -24,6 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -65,7 +66,7 @@ namespace OpenSim.Framework
/// <param name="cache"> /// <param name="cache">
/// The cache. /// The cache.
/// </param> /// </param>
private CnmSynchronizedCache( ICnmCache<TKey, TValue> cache ) private CnmSynchronizedCache(ICnmCache<TKey, TValue> cache)
{ {
m_cache = cache; m_cache = cache;
m_syncRoot = m_cache.SyncRoot; m_syncRoot = m_cache.SyncRoot;
@ -83,11 +84,11 @@ namespace OpenSim.Framework
/// <exception cref="ArgumentNullException"> /// <exception cref="ArgumentNullException">
/// <paramref name="cache"/>is null. /// <paramref name="cache"/>is null.
/// </exception> /// </exception>
public static ICnmCache<TKey, TValue> Synchronized( ICnmCache<TKey, TValue> cache ) public static ICnmCache<TKey, TValue> Synchronized(ICnmCache<TKey, TValue> cache)
{ {
if( cache == null ) if (cache == null)
throw new ArgumentNullException( "cache" ); throw new ArgumentNullException("cache");
return cache.IsSynchronized ? cache : new CnmSynchronizedCache<TKey, TValue>( cache ); return cache.IsSynchronized ? cache : new CnmSynchronizedCache<TKey, TValue>(cache);
} }
#region Nested type: SynchronizedEnumerator #region Nested type: SynchronizedEnumerator
@ -116,11 +117,11 @@ namespace OpenSim.Framework
/// <param name="syncRoot"> /// <param name="syncRoot">
/// The sync root. /// The sync root.
/// </param> /// </param>
public SynchronizedEnumerator( IEnumerator<KeyValuePair<TKey, TValue>> enumerator, object syncRoot ) public SynchronizedEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator, object syncRoot)
{ {
m_syncRoot = syncRoot; m_syncRoot = syncRoot;
m_enumerator = enumerator; m_enumerator = enumerator;
Monitor.Enter( m_syncRoot ); Monitor.Enter(m_syncRoot);
} }
/// <summary> /// <summary>
@ -166,14 +167,14 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
if( m_syncRoot != null ) if (m_syncRoot != null)
{ {
Monitor.Exit( m_syncRoot ); Monitor.Exit(m_syncRoot);
m_syncRoot = null; m_syncRoot = null;
} }
m_enumerator.Dispose(); m_enumerator.Dispose();
GC.SuppressFinalize( this ); GC.SuppressFinalize(this);
} }
/// <summary> /// <summary>
@ -225,7 +226,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.Count; return m_cache.Count;
} }
@ -271,7 +272,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.ExpirationTime; return m_cache.ExpirationTime;
} }
@ -279,7 +280,7 @@ namespace OpenSim.Framework
set set
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.ExpirationTime = value; m_cache.ExpirationTime = value;
} }
@ -307,7 +308,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.IsCountLimited; return m_cache.IsCountLimited;
} }
@ -336,7 +337,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.IsSizeLimited; return m_cache.IsSizeLimited;
} }
@ -385,7 +386,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.IsTimeLimited; return m_cache.IsTimeLimited;
} }
@ -409,7 +410,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.MaxCount; return m_cache.MaxCount;
} }
@ -417,7 +418,7 @@ namespace OpenSim.Framework
set set
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.MaxCount = value; m_cache.MaxCount = value;
} }
@ -444,7 +445,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.MaxElementSize; return m_cache.MaxElementSize;
} }
@ -474,7 +475,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.MaxSize; return m_cache.MaxSize;
} }
@ -482,7 +483,7 @@ namespace OpenSim.Framework
set set
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.MaxSize = value; m_cache.MaxSize = value;
} }
@ -516,7 +517,7 @@ namespace OpenSim.Framework
{ {
get get
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.Size; return m_cache.Size;
} }
@ -553,7 +554,7 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public void Clear() public void Clear()
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.Clear(); m_cache.Clear();
} }
@ -568,9 +569,9 @@ namespace OpenSim.Framework
/// <filterpriority>1</filterpriority> /// <filterpriority>1</filterpriority>
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return new SynchronizedEnumerator( m_cache.GetEnumerator(), m_syncRoot ); return new SynchronizedEnumerator(m_cache.GetEnumerator(), m_syncRoot);
} }
} }
@ -595,7 +596,7 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
public void PurgeExpired() public void PurgeExpired()
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.PurgeExpired(); m_cache.PurgeExpired();
} }
@ -615,11 +616,11 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public void Remove( TKey key ) public void Remove(TKey key)
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.Remove( key ); m_cache.Remove(key);
} }
} }
@ -637,11 +638,11 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public void RemoveRange( IEnumerable<TKey> keys ) public void RemoveRange(IEnumerable<TKey> keys)
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
m_cache.RemoveRange( keys ); m_cache.RemoveRange(keys);
} }
} }
@ -690,11 +691,11 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/> /// <seealso cref="ICnmCache{TKey,TValue}.TryGetValue"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public bool Set( TKey key, TValue value, long size ) public bool Set(TKey key, TValue value, long size)
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.Set( key, value, size ); return m_cache.Set(key, value, size);
} }
} }
@ -721,11 +722,11 @@ namespace OpenSim.Framework
/// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/> /// <seealso cref="ICnmCache{TKey,TValue}.RemoveRange"/>
/// <seealso cref="ICnmCache{TKey,TValue}.Clear"/> /// <seealso cref="ICnmCache{TKey,TValue}.Clear"/>
/// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/> /// <seealso cref="ICnmCache{TKey,TValue}.PurgeExpired"/>
public bool TryGetValue( TKey key, out TValue value ) public bool TryGetValue(TKey key, out TValue value)
{ {
lock( m_syncRoot ) lock (m_syncRoot)
{ {
return m_cache.TryGetValue( key, out value ); return m_cache.TryGetValue(key, out value);
} }
} }

View File

@ -58,28 +58,28 @@ namespace OpenSim.Framework
/// <returns> /// <returns>
/// Primer number that is equal or larger than <see cref="min"/>. If <see cref="min"/> is too large, return -1. /// Primer number that is equal or larger than <see cref="min"/>. If <see cref="min"/> is too large, return -1.
/// </returns> /// </returns>
public static int GetPrime( int min ) public static int GetPrime(int min)
{ {
if( min <= 2 ) if (min <= 2)
return 2; return 2;
if( Primes[ Primes.Length - 1 ] < min ) if (Primes[ Primes.Length - 1 ] < min)
{ {
for( int i = min | 1 ; i < 0x7FFFFFFF ; i += 2 ) for (int i = min | 1 ; i < 0x7FFFFFFF ; i += 2)
{ {
if( IsPrime( i ) ) if (IsPrime(i))
return i; return i;
} }
return -1; return -1;
} }
for( int i = Primes.Length - 2 ; i >= 0 ; i-- ) for (int i = Primes.Length - 2 ; i >= 0 ; i--)
{ {
if( min == Primes[ i ] ) if (min == Primes[ i ])
return min; return min;
if( min > Primes[ i ] ) if (min > Primes[ i ])
return Primes[ i + 1 ]; return Primes[ i + 1 ];
} }
@ -95,17 +95,17 @@ namespace OpenSim.Framework
/// <returns> /// <returns>
/// true, if <see cref="candinate"/> is prime number; otherwise false. /// true, if <see cref="candinate"/> is prime number; otherwise false.
/// </returns> /// </returns>
public static bool IsPrime( int candinate ) public static bool IsPrime(int candinate)
{ {
if( (candinate & 1) == 0 ) if ((candinate & 1) == 0)
// Even number - only prime if 2 // Even number - only prime if 2
return candinate == 2; return candinate == 2;
int upperBound = (int) Math.Sqrt( candinate ); int upperBound = (int) Math.Sqrt(candinate);
for( int i = 3 ; i < upperBound ; i += 2 ) for (int i = 3 ; i < upperBound ; i += 2)
{ {
if( candinate % i == 0 ) if (candinate % i == 0)
return false; return false;
} }

View File

@ -114,12 +114,12 @@ namespace OpenSim.Region.CoreModules.Asset
/// <summary> /// <summary>
/// Asset's default expiration time in the cache. /// Asset's default expiration time in the cache.
/// </summary> /// </summary>
public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes( 30.0 ); public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes(30.0);
/// <summary> /// <summary>
/// Log manager instance. /// Log manager instance.
/// </summary> /// </summary>
private static readonly ILog Log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType ); private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary> /// <summary>
/// Cache object. /// Cache object.
@ -159,7 +159,7 @@ namespace OpenSim.Region.CoreModules.Asset
/// </summary> /// </summary>
public void Initialize() public void Initialize()
{ {
Initialize( DefaultMaxSize, DefaultMaxCount, DefaultExpirationTime ); Initialize(DefaultMaxSize, DefaultMaxCount, DefaultExpirationTime);
} }
/// <summary> /// <summary>
@ -174,16 +174,16 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="expirationTime"> /// <param name="expirationTime">
/// Asset's expiration time. /// Asset's expiration time.
/// </param> /// </param>
public void Initialize( long maximalSize, int maximalCount, TimeSpan expirationTime ) public void Initialize(long maximalSize, int maximalCount, TimeSpan expirationTime)
{ {
if( maximalSize <= 0 || maximalCount <= 0 ) if (maximalSize <= 0 || maximalCount <= 0)
{ {
Log.Info( "[ASSET CACHE]: Cenome asset cache is not enabled." ); Log.Info("[ASSET CACHE]: Cenome asset cache is not enabled.");
m_enabled = false; m_enabled = false;
return; return;
} }
if( expirationTime <= TimeSpan.Zero ) if (expirationTime <= TimeSpan.Zero)
{ {
// Disable expiration time // Disable expiration time
expirationTime = TimeSpan.MaxValue; expirationTime = TimeSpan.MaxValue;
@ -191,14 +191,14 @@ namespace OpenSim.Region.CoreModules.Asset
// Create cache and add synchronization wrapper over it // Create cache and add synchronization wrapper over it
m_cache = m_cache =
CnmSynchronizedCache<string, AssetBase>.Synchronized( new CnmMemoryCache<string, AssetBase>( CnmSynchronizedCache<string, AssetBase>.Synchronized(new CnmMemoryCache<string, AssetBase>(
maximalSize, maximalCount, expirationTime ) ); maximalSize, maximalCount, expirationTime));
m_enabled = true; m_enabled = true;
Log.InfoFormat( Log.InfoFormat(
"[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})", "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})",
maximalSize, maximalSize,
maximalCount, maximalCount,
expirationTime ); expirationTime);
} }
#region IImprovedAssetCache Members #region IImprovedAssetCache Members
@ -209,10 +209,10 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="asset"> /// <param name="asset">
/// The asset that is being cached. /// The asset that is being cached.
/// </param> /// </param>
public void Cache( AssetBase asset ) public void Cache(AssetBase asset)
{ {
long size = asset.Data != null ? asset.Data.Length : 1; long size = asset.Data != null ? asset.Data.Length : 1;
m_cache.Set( asset.ID, asset, size ); m_cache.Set(asset.ID, asset, size);
m_cachedCount++; m_cachedCount++;
} }
@ -230,9 +230,9 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="id"> /// <param name="id">
/// The expired asset's id. /// The expired asset's id.
/// </param> /// </param>
public void Expire( string id ) public void Expire(string id)
{ {
m_cache.Remove( id ); m_cache.Remove(id);
} }
/// <summary> /// <summary>
@ -250,14 +250,14 @@ namespace OpenSim.Region.CoreModules.Asset
/// Cache doesn't guarantee in any situation that asset is stored to it. /// Cache doesn't guarantee in any situation that asset is stored to it.
/// </para> /// </para>
/// </remarks> /// </remarks>
public AssetBase Get( string id ) public AssetBase Get(string id)
{ {
m_getCount++; m_getCount++;
AssetBase assetBase; AssetBase assetBase;
if( m_cache.TryGetValue( id, out assetBase ) ) if (m_cache.TryGetValue(id, out assetBase))
m_hitCount++; m_hitCount++;
if( m_getCount == m_debugEpoch ) if (m_getCount == m_debugEpoch)
{ {
Log.InfoFormat( Log.InfoFormat(
"[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes", "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes",
@ -265,7 +265,7 @@ namespace OpenSim.Region.CoreModules.Asset
m_getCount, m_getCount,
((double) m_hitCount / m_getCount) * 100.0, ((double) m_hitCount / m_getCount) * 100.0,
m_cache.Size, m_cache.Size,
m_cache.Size / m_cache.Count ); m_cache.Size / m_cache.Count);
m_getCount = 0; m_getCount = 0;
m_hitCount = 0; m_hitCount = 0;
m_cachedCount = 0; m_cachedCount = 0;
@ -292,10 +292,10 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="scene"> /// <param name="scene">
/// Region's scene. /// Region's scene.
/// </param> /// </param>
public void AddRegion( Scene scene ) public void AddRegion(Scene scene)
{ {
if( m_enabled ) if (m_enabled)
scene.RegisterModuleInterface<IImprovedAssetCache>( this ); scene.RegisterModuleInterface<IImprovedAssetCache>(this);
} }
/// <summary> /// <summary>
@ -314,19 +314,19 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="source"> /// <param name="source">
/// Configuration source. /// Configuration source.
/// </param> /// </param>
public void Initialise( IConfigSource source ) public void Initialise(IConfigSource source)
{ {
m_cache = null; m_cache = null;
m_enabled = false; m_enabled = false;
IConfig moduleConfig = source.Configs[ "Modules" ]; IConfig moduleConfig = source.Configs[ "Modules" ];
if( moduleConfig == null ) if (moduleConfig == null)
return; return;
string name = moduleConfig.GetString( "AssetCaching" ); string name = moduleConfig.GetString("AssetCaching");
Log.DebugFormat( "[XXX] name = {0} (this module's name: {1}", name, Name ); Log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);
if( name != Name ) if (name != Name)
return; return;
// This module is used // This module is used
@ -335,19 +335,19 @@ namespace OpenSim.Region.CoreModules.Asset
TimeSpan expirationTime = DefaultExpirationTime; TimeSpan expirationTime = DefaultExpirationTime;
IConfig assetConfig = source.Configs[ "AssetCache" ]; IConfig assetConfig = source.Configs[ "AssetCache" ];
if( assetConfig != null ) if (assetConfig != null)
{ {
// Get optional configurations // Get optional configurations
maxSize = assetConfig.GetLong( "MaxSize", DefaultMaxSize ); maxSize = assetConfig.GetLong("MaxSize", DefaultMaxSize);
maxCount = assetConfig.GetInt( "MaxCount", DefaultMaxCount ); maxCount = assetConfig.GetInt("MaxCount", DefaultMaxCount);
expirationTime = expirationTime =
TimeSpan.FromMinutes( assetConfig.GetInt( "ExpirationTime", (int) DefaultExpirationTime.TotalMinutes ) ); TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int) DefaultExpirationTime.TotalMinutes));
// Debugging purposes only // Debugging purposes only
m_debugEpoch = assetConfig.GetInt( "DebugEpoch", 0 ); m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
} }
Initialize( maxSize, maxCount, expirationTime ); Initialize(maxSize, maxCount, expirationTime);
} }
/// <summary> /// <summary>
@ -381,7 +381,7 @@ namespace OpenSim.Region.CoreModules.Asset
/// The extra function stub is just that much cleaner. /// The extra function stub is just that much cleaner.
/// </para> /// </para>
/// </remarks> /// </remarks>
public void RegionLoaded( Scene scene ) public void RegionLoaded(Scene scene)
{ {
} }
@ -391,7 +391,7 @@ namespace OpenSim.Region.CoreModules.Asset
/// <param name="scene"> /// <param name="scene">
/// Region scene that is being removed. /// Region scene that is being removed.
/// </param> /// </param>
public void RemoveRegion( Scene scene ) public void RemoveRegion(Scene scene)
{ {
} }

View File

@ -230,7 +230,7 @@ namespace Flotsam.RegionModules.AssetCache
private void UpdateMemoryCache(string key, AssetBase asset) private void UpdateMemoryCache(string key, AssetBase asset)
{ {
if( m_MemoryCacheEnabled ) if (m_MemoryCacheEnabled)
{ {
if (m_MemoryExpiration > TimeSpan.Zero) if (m_MemoryExpiration > TimeSpan.Zero)
{ {
@ -404,7 +404,7 @@ namespace Flotsam.RegionModules.AssetCache
File.Delete(filename); File.Delete(filename);
} }
if( m_MemoryCacheEnabled ) if (m_MemoryCacheEnabled)
m_MemoryCache.Remove(id); m_MemoryCache.Remove(id);
} }
catch (Exception e) catch (Exception e)
@ -423,7 +423,7 @@ namespace Flotsam.RegionModules.AssetCache
Directory.Delete(dir); Directory.Delete(dir);
} }
if( m_MemoryCacheEnabled ) if (m_MemoryCacheEnabled)
m_MemoryCache.Clear(); m_MemoryCache.Clear();
} }

View File

@ -332,7 +332,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
UUID oldID = UUID.Zero; UUID oldID = UUID.Zero;
lock(part) lock (part)
{ {
// mostly keep the values from before // mostly keep the values from before
Primitive.TextureEntry tmptex = part.Shape.Textures; Primitive.TextureEntry tmptex = part.Shape.Textures;
@ -340,7 +340,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
// remove the old asset from the cache // remove the old asset from the cache
oldID = tmptex.DefaultTexture.TextureID; oldID = tmptex.DefaultTexture.TextureID;
if(Face == ALL_SIDES) if (Face == ALL_SIDES)
{ {
tmptex.DefaultTexture.TextureID = asset.FullID; tmptex.DefaultTexture.TextureID = asset.FullID;
} }

View File

@ -243,7 +243,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
string grant = myConfig.GetString("GrantLSL",""); string grant = myConfig.GetString("GrantLSL","");
if(grant.Length > 0) { if (grant.Length > 0) {
foreach (string uuidl in grant.Split(',')) { foreach (string uuidl in grant.Split(',')) {
string uuid = uuidl.Trim(" \t".ToCharArray()); string uuid = uuidl.Trim(" \t".ToCharArray());
GrantLSL.Add(uuid, true); GrantLSL.Add(uuid, true);
@ -251,7 +251,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
} }
grant = myConfig.GetString("GrantCS",""); grant = myConfig.GetString("GrantCS","");
if(grant.Length > 0) { if (grant.Length > 0) {
foreach (string uuidl in grant.Split(',')) { foreach (string uuidl in grant.Split(',')) {
string uuid = uuidl.Trim(" \t".ToCharArray()); string uuid = uuidl.Trim(" \t".ToCharArray());
GrantCS.Add(uuid, true); GrantCS.Add(uuid, true);
@ -259,7 +259,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
} }
grant = myConfig.GetString("GrantVB",""); grant = myConfig.GetString("GrantVB","");
if(grant.Length > 0) { if (grant.Length > 0) {
foreach (string uuidl in grant.Split(',')) { foreach (string uuidl in grant.Split(',')) {
string uuid = uuidl.Trim(" \t".ToCharArray()); string uuid = uuidl.Trim(" \t".ToCharArray());
GrantVB.Add(uuid, true); GrantVB.Add(uuid, true);
@ -267,7 +267,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
} }
grant = myConfig.GetString("GrantJS",""); grant = myConfig.GetString("GrantJS","");
if(grant.Length > 0) { if (grant.Length > 0) {
foreach (string uuidl in grant.Split(',')) { foreach (string uuidl in grant.Split(',')) {
string uuid = uuidl.Trim(" \t".ToCharArray()); string uuid = uuidl.Trim(" \t".ToCharArray());
GrantJS.Add(uuid, true); GrantJS.Add(uuid, true);
@ -563,7 +563,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
} }
// Group permissions // Group permissions
if ( ( task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0) ) if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0))
return objectGroupMask; return objectGroupMask;
return objectEveryoneMask; return objectEveryoneMask;
@ -650,7 +650,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
} }
// Group members should be able to edit group objects // Group members should be able to edit group objects
if ( (group.GroupID != UUID.Zero) && ((m_scene.GetSceneObjectPart(objId).GroupMask & (uint)PermissionMask.Modify) != 0) && IsGroupMember(group.GroupID, currentUser, 0) ) if ((group.GroupID != UUID.Zero) && ((m_scene.GetSceneObjectPart(objId).GroupMask & (uint)PermissionMask.Modify) != 0) && IsGroupMember(group.GroupID, currentUser, 0))
{ {
// Return immediately, so that the administrator can shares group objects // Return immediately, so that the administrator can shares group objects
return true; return true;
@ -731,7 +731,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
permission = true; permission = true;
} }
if( ( parcel.landData.GroupID != UUID.Zero) && IsGroupMember(parcel.landData.GroupID, user, groupPowers) ) if ((parcel.landData.GroupID != UUID.Zero) && IsGroupMember(parcel.landData.GroupID, user, groupPowers))
{ {
permission = true; permission = true;
} }
@ -758,7 +758,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
permission = true; permission = true;
} }
if( parcel.landData.IsGroupOwned && IsGroupMember(parcel.landData.GroupID, user, groupPowers) ) if (parcel.landData.IsGroupOwned && IsGroupMember(parcel.landData.GroupID, user, groupPowers))
{ {
permission = true; permission = true;
} }
@ -982,7 +982,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (part.GroupID == UUID.Zero) if (part.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(part.GroupID, user, 0) ) if (!IsGroupMember(part.GroupID, user, 0))
return false; return false;
if ((part.GroupMask & (uint)PermissionMask.Modify) == 0) if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
@ -1002,7 +1002,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (ti.GroupID == UUID.Zero) if (ti.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(ti.GroupID, user, 0) ) if (!IsGroupMember(ti.GroupID, user, 0))
return false; return false;
} }
@ -1411,7 +1411,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (part.GroupID == UUID.Zero) if (part.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(part.GroupID, user, 0) ) if (!IsGroupMember(part.GroupID, user, 0))
return false; return false;
if ((part.GroupMask & (uint)PermissionMask.Modify) == 0) if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
@ -1431,7 +1431,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (ti.GroupID == UUID.Zero) if (ti.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(ti.GroupID, user, 0) ) if (!IsGroupMember(ti.GroupID, user, 0))
return false; return false;
} }
@ -1504,7 +1504,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (part.GroupID == UUID.Zero) if (part.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(part.GroupID, user, 0) ) if (!IsGroupMember(part.GroupID, user, 0))
return false; return false;
} }
@ -1521,7 +1521,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (ti.GroupID == UUID.Zero) if (ti.GroupID == UUID.Zero)
return false; return false;
if( !IsGroupMember(ti.GroupID, user, 0) ) if (!IsGroupMember(ti.GroupID, user, 0))
return false; return false;
} }
@ -1744,24 +1744,24 @@ namespace OpenSim.Region.CoreModules.World.Permissions
private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene) { private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene) {
//m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType); //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
switch(scriptType) { switch (scriptType) {
case 0: case 0:
if(GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) { if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
return(true); return(true);
} }
break; break;
case 1: case 1:
if(GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) { if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
return(true); return(true);
} }
break; break;
case 2: case 2:
if(GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) { if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
return(true); return(true);
} }
break; break;
case 3: case 3:
if(GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString())) { if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString())) {
return(true); return(true);
} }
break; break;

View File

@ -1528,7 +1528,7 @@ namespace OpenSim.Region.Framework.Scenes
if (part.OwnerID != remoteClient.AgentId) if (part.OwnerID != remoteClient.AgentId)
{ {
// Group permissions // Group permissions
if ( (part.GroupID == UUID.Zero) || (remoteClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0) ) if ((part.GroupID == UUID.Zero) || (remoteClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0))
return; return;
} else { } else {
if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0) if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
@ -1607,8 +1607,8 @@ namespace OpenSim.Region.Framework.Scenes
if (srcPart.OwnerID != destPart.OwnerID) if (srcPart.OwnerID != destPart.OwnerID)
{ {
// Group permissions // Group permissions
if ( (destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) || if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
((destPart.GroupMask & (uint)PermissionMask.Modify) == 0) ) ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0))
return; return;
} else { } else {
if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0) if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)

View File

@ -136,7 +136,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
m_AssetService = RequestModuleInterface<IAssetService>(); m_AssetService = RequestModuleInterface<IAssetService>();
if( m_AssetService == null ) if (m_AssetService == null)
{ {
throw new Exception("No IAssetService available."); throw new Exception("No IAssetService available.");
} }
@ -1097,7 +1097,7 @@ namespace OpenSim.Region.Framework.Scenes
IMessageTransferModule tr = RequestModuleInterface<IMessageTransferModule>(); IMessageTransferModule tr = RequestModuleInterface<IMessageTransferModule>();
if (tr != null) if (tr != null)
tr.SendInstantMessage(msg, delegate(bool success) {} ); tr.SendInstantMessage(msg, delegate(bool success) {});
} }
m_returns.Clear(); m_returns.Clear();
} }
@ -1465,7 +1465,7 @@ namespace OpenSim.Region.Framework.Scenes
foreach (SceneObjectPart part in group.Children.Values) foreach (SceneObjectPart part in group.Children.Values)
{ {
if (part.IsJoint() && ((part.ObjectFlags&(uint)PrimFlags.Physics) != 0) ) if (part.IsJoint() && ((part.ObjectFlags&(uint)PrimFlags.Physics) != 0))
{ {
PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed? PhysicsScene.RequestJointDeletion(part.Name); // FIXME: what if the name changed?
} }

View File

@ -342,7 +342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
throw new Exception(errtext); throw new Exception(errtext);
} }
if(m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)l) == false) { if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)l) == false) {
// Not allowed to compile to this language! // Not allowed to compile to this language!
string errtext = String.Empty; string errtext = String.Empty;
errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!";