in src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java [726:905]
public void initialize() throws Exception
{
Map<AppData, File> appDataElements = null;
groupNames = new HashMap<String, AppData>();
groupKeyMap = new HashMap<String, String>();
groupNameMap = new HashMap<String, String>();
getterMap = new HashMap<String, Map<String,Method>>();
setterMap = new HashMap<String, Map<String,Method>>();
keyedPools = new HashMap<AppData, KeyedObjectPool<String, Group>>();
Set<File> xmlFiles = new HashSet<File>();
long timeStamp = 0;
getLogger().debug("logger is " + getLogger().getClass().getSimpleName());
for (String xmlPath : xmlPathes)
{
// Files are webapp.root relative
File xmlFile = new File(applicationRoot, xmlPath).getAbsoluteFile();
getLogger().debug("Path for XML File: " + xmlFile);
if (!xmlFile.canRead())
{
String READ_ERR = "Could not read input file with path "
+ xmlPath + ". Looking for file " + xmlFile;
getLogger().error(READ_ERR);
throw new Exception(READ_ERR);
}
xmlFiles.add(xmlFile);
getLogger().debug("Added " + xmlPath + " as File to parse");
// Get the timestamp of the youngest file to be compared with
// a serialized file. If it is younger than the serialized file,
// then we have to parse the XML anyway.
timeStamp = xmlFile.lastModified() > timeStamp ? xmlFile
.lastModified() : timeStamp;
}
Map<AppData, File> serializedMap = loadSerialized(serialDataPath, timeStamp);
if (serializedMap != null)
{
// Use the serialized data as XML groups. Don't parse.
appDataElements = serializedMap;
getLogger().debug("Using the serialized map");
}
else
{
long timer = System.currentTimeMillis();
// Parse all the given XML files
JAXBContext jaxb = JAXBContext.newInstance(AppData.class);
Unmarshaller um = jaxb.createUnmarshaller();
// Debug mapping
um.setEventHandler(new DefaultValidationEventHandler());
// Enable logging
Listener logEnabledListener = new AvalonLogEnabledListener();
um.setListener(logEnabledListener);
URL schemaURL = getClass().getResource("/intake.xsd");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
um.setSchema(schemaFactory.newSchema(schemaURL));
appDataElements = new HashMap<AppData, File>();
for (File xmlFile : xmlFiles)
{
getLogger().debug("Now parsing: " + xmlFile);
FileInputStream fis = null;
try
{
fis = new FileInputStream(xmlFile);
AppData appData = (AppData) um.unmarshal(fis);
appDataElements.put(appData, xmlFile);
getLogger().debug("Saving AppData for " + xmlFile);
}
finally
{
if (fis != null)
{
try
{
fis.close();
}
catch (IOException e)
{
getLogger().warn("Could not close file " + xmlFile);
}
}
}
}
getLogger().debug("Parsing took " + (System.currentTimeMillis() - timer));
saveSerialized(serialDataPath, appDataElements);
}
int counter = 0;
AppData appData;
File dataFile;
for ( Entry<AppData, File> entry : appDataElements.entrySet() )
{
// Set the entry pair
appData = entry.getKey();
dataFile = entry.getValue();
int maxPooledGroups = 0;
List<Group> glist = appData.getGroups();
String groupPrefix = appData.getGroupPrefix();
for (ListIterator<Group> i = glist.listIterator(glist.size()); i.hasPrevious();)
{
Group g = i.previous();
String groupName = g.getIntakeGroupName();
boolean registerUnqualified = registerGroup(groupName, g, appData, true);
if (!registerUnqualified)
{
getLogger().info(
"Ignored redefinition of Group " + groupName
+ " or Key " + g.getGID() + " from "
+ dataFile);
}
if (groupPrefix != null)
{
StringBuilder qualifiedName = new StringBuilder();
qualifiedName.append(groupPrefix).append(':').append(groupName);
// Add the fully qualified group name. Do _not_ check
// for
// the existence of the key if the unqualified
// registration succeeded
// (because then it was added by the registerGroup
// above).
if (!registerGroup(qualifiedName.toString(), g,
appData, !registerUnqualified))
{
getLogger().error(
"Could not register fully qualified name "
+ qualifiedName
+ ", maybe two XML files have the same prefix. Ignoring it.");
}
}
// Init fields
for (Field<?> f : g.getFields())
{
f.initGetterAndSetter();
}
maxPooledGroups = Math.max(maxPooledGroups, g.getPoolCapacity());
}
KeyedPooledObjectFactory<String, Group> factory =
new Group.GroupFactory(appData);
GenericKeyedObjectPoolConfig<Group> poolConfig = new GenericKeyedObjectPoolConfig<Group>();
poolConfig.setMaxTotalPerKey(maxPooledGroups);
poolConfig.setJmxEnabled(true);
poolConfig.setJmxNamePrefix("fulcrum-intake-pool-" + counter++);
keyedPools.put(appData,
new GenericKeyedObjectPool<String, Group>(factory, poolConfig));
}
if (getLogger().isInfoEnabled())
{
getLogger().info("Intake Service is initialized now.");
}
}