Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Caching constraint violation checking results (focus and shadow). Mov…
…ed shadow constraint checking to provisioning.
- Loading branch information
Showing
20 changed files
with
817 additions
and
141 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
infra/util/src/main/java/com/evolveum/midpoint/util/caching/AbstractCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2010-2014 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.util.caching; | ||
|
||
import com.evolveum.midpoint.util.exception.SystemException; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
/** | ||
* @author mederly | ||
*/ | ||
public class AbstractCache { | ||
|
||
private int entryCount = 0; | ||
|
||
public static <T extends AbstractCache> void enter(ThreadLocal<T> cacheThreadLocal, Class<T> cacheClass, Trace logger) { | ||
T inst = cacheThreadLocal.get(); | ||
logger.trace("Cache: ENTER for thread {}, {}", Thread.currentThread().getName(), inst); | ||
if (inst == null) { | ||
logger.info("Cache: creating for thread {}",Thread.currentThread().getName()); | ||
try { | ||
inst = cacheClass.newInstance(); | ||
} catch (InstantiationException|IllegalAccessException e) { | ||
throw new SystemException("Couldn't instantiate cache: " + e.getMessage(), e); | ||
} | ||
cacheThreadLocal.set(inst); | ||
} | ||
inst.incrementEntryCount(); | ||
} | ||
|
||
public static <T extends AbstractCache> void exit(ThreadLocal<T> cacheThreadLocal, Trace logger) { | ||
T inst = cacheThreadLocal.get(); | ||
logger.trace("Cache: EXIT for thread {}, {}", Thread.currentThread().getName(), inst); | ||
if (inst == null || inst.getEntryCount() == 0) { | ||
logger.error("Cache: Attempt to exit cache that does not exist or has entry count 0: {}", inst); | ||
cacheThreadLocal.set(null); | ||
} else { | ||
inst.decrementEntryCount(); | ||
if (inst.getEntryCount() <= 0) { | ||
logger.info("Cache: DESTROY for thread {}", Thread.currentThread().getName()); | ||
cacheThreadLocal.set(null); | ||
} | ||
} | ||
} | ||
|
||
public void incrementEntryCount() { | ||
entryCount++; | ||
} | ||
|
||
public void decrementEntryCount() { | ||
entryCount--; | ||
} | ||
|
||
public int getEntryCount() { | ||
return entryCount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.