You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2017/02/27 18:55:02 UTC
svn commit: r1784627 -
/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java
Author: schor
Date: Mon Feb 27 18:55:02 2017
New Revision: 1784627
URL: http://svn.apache.org/viewvc?rev=1784627&view=rev
Log:
no Jira - make logger cache use threadsafe concurrent hash map, plus cleanup
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java?rev=1784627&r1=1784626&r2=1784627&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UIMAFramework_impl.java Mon Feb 27 18:55:02 2017
@@ -24,10 +24,10 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -157,7 +157,7 @@ public class UIMAFramework_impl extends
/**
* HashMap includes all log wrapper classes
*/
- private HashMap mLoggers;
+ private ConcurrentHashMap<String, Logger> mLoggers;
/**
* Creates a new UIMAFramework_impl.
@@ -168,6 +168,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#_initialize()
*/
+ @Override
protected void _initialize() throws Exception {
// attempt to improve initialization performance
Introspector.setBeanInfoSearchPath(new String[0]);
@@ -184,12 +185,13 @@ public class UIMAFramework_impl extends
.getResourceAsStream("performanceTuning.properties"));
// create new HashMap for the LogWrappers
- mLoggers = new HashMap(200, 1.0f);
+ mLoggers = new ConcurrentHashMap<>(200, 1.0f);
}
/**
* @see org.apache.uima.UIMAFramework#_getMajorVersion()
*/
+ @Override
public short _getMajorVersion() {
return UimaVersion.getMajorVersion(); // major version
}
@@ -197,6 +199,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#_getMinorVersion()
*/
+ @Override
public short _getMinorVersion() {
return UimaVersion.getMinorVersion(); // minor version
}
@@ -204,6 +207,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#_getBuildRevision()
*/
+ @Override
public short _getBuildRevision() {
return UimaVersion.getBuildRevision(); // build revision
}
@@ -214,6 +218,7 @@ public class UIMAFramework_impl extends
*
* @return the <code>ResourceFactory</code> to be used by the application
*/
+ @Override
protected CompositeResourceFactory _getResourceFactory() {
return mResourceFactory;
}
@@ -224,6 +229,7 @@ public class UIMAFramework_impl extends
*
* @return the <code>ResourceSpecifierFactory</code> to be used by the application.
*/
+ @Override
protected ResourceSpecifierFactory _getResourceSpecifierFactory() {
return mResourceSpecifierFactory;
}
@@ -234,6 +240,7 @@ public class UIMAFramework_impl extends
*
* @return the <code>XMLParser</code> to be used by the application.
*/
+ @Override
protected XMLParser _getXMLParser() {
return mXMLParser;
}
@@ -241,6 +248,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#newCollectionProcessingManager()
*/
+ @Override
protected CollectionProcessingManager _newCollectionProcessingManager(
ResourceManager aResourceManager) {
try {
@@ -262,6 +270,7 @@ public class UIMAFramework_impl extends
*
* @return the <code>Logger</code> to be used by the application.
*/
+ @Override
protected Logger _getLogger() {
return mDefaultLogger;
}
@@ -272,9 +281,10 @@ public class UIMAFramework_impl extends
*
* @return the <code>Logger</code> of the specified source class
*/
+ @Override
protected Logger _getLogger(Class component) {
// search for the source class logger in the HashMap
- Object o = mLoggers.get(component.getName());
+ Logger o = mLoggers.get(component.getName());
if (o == null) // source class logger not available
{
@@ -287,7 +297,7 @@ public class UIMAFramework_impl extends
// get static method getInstance(Class component)
Method instanceMethod = mLoggerClass.getMethod("getInstance", argumentTypes);
// invoke getInstance(Class component) method and retrieve logger object
- o = instanceMethod.invoke(null, arguments);
+ o = (Logger) instanceMethod.invoke(null, arguments);
} catch (NoSuchMethodException e) {
throw new UIMARuntimeException(e);
} catch (InvocationTargetException e) {
@@ -300,12 +310,13 @@ public class UIMAFramework_impl extends
mLoggers.put(component.getName(), o);
}
- return (Logger) o;
+ return o;
}
/**
* @see org.apache.uima.UIMAFramework#_newLogger()
*/
+ @Override
protected Logger _newLogger() {
try {
// get static method getInstance()
@@ -327,6 +338,7 @@ public class UIMAFramework_impl extends
*
* @return a new <code>ResourceManager</code> to be used by the application.
*/
+ @Override
protected ResourceManager _newDefaultResourceManager() {
try {
return (ResourceManager) Class.forName(mResourceManagerImplClassName).newInstance();
@@ -345,6 +357,7 @@ public class UIMAFramework_impl extends
*
* @return a new <code>ResourceManager</code> to be used by the application.
*/
+ @Override
protected ResourceManager _newDefaultResourceManagerPearWrapper() {
try {
return (ResourceManager) Class.forName(mResourceManagerPearWrapperImplClassName).newInstance();
@@ -363,6 +376,7 @@ public class UIMAFramework_impl extends
*
* @return a new <code>ConfigurationManager</code> to be used by the application.
*/
+ @Override
protected ConfigurationManager _newConfigurationManager() {
try {
return (ConfigurationManager) Class.forName(mConfigurationManagerImplClassName).newInstance();
@@ -378,6 +392,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#_newUimaContext()
*/
+ @Override
protected UimaContextAdmin _newUimaContext() {
try {
return (UimaContextAdmin) Class.forName(mUimaContextImplClassName).newInstance();
@@ -393,6 +408,7 @@ public class UIMAFramework_impl extends
/**
* @see org.apache.uima.UIMAFramework#_newTimer()
*/
+ @Override
protected UimaTimer _newTimer() {
try {
return (UimaTimer) Class.forName(mTimerClassName).newInstance();
@@ -411,6 +427,7 @@ public class UIMAFramework_impl extends
* @see org.apache.uima.UIMAFramework#_produceCollectionProcessingEngine(org.apache.uima.collection.metadata.cpeDescription,
* java.util.Map)
*/
+ @Override
protected CollectionProcessingEngine _produceCollectionProcessingEngine(
CpeDescription aCpeDescription, Map<String, Object> aAdditionalParams)
throws ResourceInitializationException {
@@ -433,6 +450,7 @@ public class UIMAFramework_impl extends
*
* @see org.apache.uima.UIMAFramework#_getDefaultPerformanceTuningProperties()
*/
+ @Override
protected Properties _getDefaultPerformanceTuningProperties() {
return (Properties) mDefaultPerformanceTuningProperties.clone();
}
@@ -492,6 +510,7 @@ public class UIMAFramework_impl extends
/**
* @see org.xml.sax.ContentHandler#startDocument()
*/
+ @Override
public void startDocument() throws SAXException {
context = CONTEXT_NONE;
}
@@ -500,6 +519,7 @@ public class UIMAFramework_impl extends
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
* java.lang.String, org.xml.sax.Attributes)
*/
+ @Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if ("logger".equals(qName)) {
@@ -662,6 +682,7 @@ public class UIMAFramework_impl extends
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String,
* java.lang.String)
*/
+ @Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("factoryConfig".equals(qName)) {
context = CONTEXT_NONE;
@@ -683,6 +704,7 @@ public class UIMAFramework_impl extends
/**
* @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
*/
+ @Override
public void warning(SAXParseException e) throws SAXException {
if (_getLogger() != null) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "warning",
@@ -693,6 +715,7 @@ public class UIMAFramework_impl extends
/**
* @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
*/
+ @Override
public void error(SAXParseException e) throws SAXException {
throw new UIMARuntimeException(e);
}