use of org.apache.jackrabbit.core.journal.JournalFactory in project jackrabbit by apache.
the class ConsistencyCheckerImplTest method createClusterNode.
private ClusterNode createClusterNode(String id) throws Exception {
final MemoryJournal journal = new MemoryJournal() {
protected boolean syncAgainOnNewRecords() {
return true;
}
};
JournalFactory jf = new JournalFactory() {
public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
return journal;
}
};
ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
SimpleClusterContext context = new SimpleClusterContext(cc);
journal.setRepositoryHome(context.getRepositoryHome());
journal.init(id, context.getNamespaceResolver());
journal.setRecords(records);
ClusterNode clusterNode = new ClusterNode();
clusterNode.init(context);
return clusterNode;
}
use of org.apache.jackrabbit.core.journal.JournalFactory in project jackrabbit by apache.
the class ClusterSyncTest method createClusterNode.
/**
* Create a cluster node, with a memory journal referencing a list of records.
*
* @param id cluster node id
* @param records memory journal's list of records
* @param disableAutoSync if <code>true</code> background synchronization is disabled
*/
private ClusterNode createClusterNode(String id, boolean disableAutoSync) throws Exception {
final MemoryJournal journal = new MemoryJournal() {
protected boolean syncAgainOnNewRecords() {
return true;
}
};
JournalFactory jf = new JournalFactory() {
public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
return journal;
}
};
ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
SimpleClusterContext context = new SimpleClusterContext(cc);
journal.setRepositoryHome(context.getRepositoryHome());
journal.init(id, context.getNamespaceResolver());
journal.setRecords(records);
ClusterNode clusterNode = new ClusterNode();
clusterNode.init(context);
if (disableAutoSync) {
clusterNode.disableAutoSync();
}
return clusterNode;
}
use of org.apache.jackrabbit.core.journal.JournalFactory in project jackrabbit by apache.
the class ClusterRecordTest method createClusterNode.
/**
* Create a cluster node, with a memory journal referencing a list of records.
*
* @param id cluster node id
* @param records memory journal's list of records
*/
private ClusterNode createClusterNode(String id, ArrayList<MemoryRecord> records) throws Exception {
final MemoryJournal journal = new MemoryJournal();
JournalFactory jf = new JournalFactory() {
public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
return journal;
}
};
ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
SimpleClusterContext context = new SimpleClusterContext(cc);
journal.setRepositoryHome(context.getRepositoryHome());
journal.init(id, context.getNamespaceResolver());
if (records != null) {
journal.setRecords(records);
}
ClusterNode clusterNode = new ClusterNode();
clusterNode.init(context);
return clusterNode;
}
use of org.apache.jackrabbit.core.journal.JournalFactory in project jackrabbit by apache.
the class RepositoryConfigurationParser method getJournalFactory.
/**
* Parses journal configuration. Journal configuration uses the following format:
* <pre>
* <Journal class="...">
* <param name="..." value="...">
* ...
* </Journal>
* </pre>
* <p>
* <code>Journal</code> is a {@link #parseBeanConfig(Element,String) bean configuration}
* element.
*
* @param cluster parent cluster element
* @param home repository home directory
* @param id cluster node id
* @return journal factory
* @throws ConfigurationException if the configuration is broken
*/
protected JournalFactory getJournalFactory(final Element cluster, final File home, final String id) throws ConfigurationException {
return new JournalFactory() {
public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
BeanConfig config = parseBeanConfig(cluster, JOURNAL_ELEMENT);
Journal journal = config.newInstance(Journal.class);
if (journal instanceof AbstractJournal) {
((AbstractJournal) journal).setRepositoryHome(home);
}
try {
journal.init(id, resolver);
} catch (JournalException e) {
// TODO: Should JournalException extend RepositoryException?
throw new RepositoryException("Journal initialization failed: " + journal, e);
}
return journal;
}
};
}
use of org.apache.jackrabbit.core.journal.JournalFactory in project jackrabbit by apache.
the class RepositoryConfigurationParser method parseClusterConfig.
/**
* Parses cluster configuration. Cluster configuration uses the following format:
* <pre>
* <Cluster>
* <Journal ...>
* </Journal>
* </pre>
* <p>
* <code>Cluster</code> is a {@link #parseBeanConfig(Element,String) bean configuration}
* element.
* <p>
* Clustering is an optional feature. If the cluster element is not found, then this
* method returns <code>null</code>.
*
* @param parent parent of the <code>Journal</code> element
* @param home repository home directory
* @return cluster configuration, or <code>null</code>
* @throws ConfigurationException if the configuration is broken
*/
protected ClusterConfig parseClusterConfig(Element parent, File home) throws ConfigurationException {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE && CLUSTER_ELEMENT.equals(child.getNodeName())) {
Element element = (Element) child;
// Find the cluster node id
String id = System.getProperty(ClusterNode.SYSTEM_PROPERTY_NODE_ID);
String value = getAttribute(element, ID_ATTRIBUTE, null);
if (value != null) {
id = replaceVariables(value);
} else if (id == null) {
File file = new File(home, CLUSTER_NODE_ID_FILE);
try {
if (file.exists() && file.canRead()) {
id = FileUtils.readFileToString(file).trim();
} else {
id = UUID.randomUUID().toString();
FileUtils.writeStringToFile(file, id);
}
} catch (IOException e) {
throw new ConfigurationException("Failed to access cluster node id: " + file, e);
}
}
long syncDelay = Long.parseLong(replaceVariables(getAttribute(element, SYNC_DELAY_ATTRIBUTE, DEFAULT_SYNC_DELAY)));
long stopDelay = Long.parseLong(replaceVariables(getAttribute(element, STOP_DELAY_ATTRIBUTE, "-1")));
JournalFactory jf = getJournalFactory(element, home, id);
return new ClusterConfig(id, syncDelay, stopDelay, jf);
}
}
return null;
}
Aggregations