Search in sources :

Example 1 with JournalFactory

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;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) SimpleClusterContext(org.apache.jackrabbit.core.cluster.SimpleClusterContext) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) MemoryJournal(org.apache.jackrabbit.core.journal.MemoryJournal) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 2 with JournalFactory

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;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) MemoryJournal(org.apache.jackrabbit.core.journal.MemoryJournal) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 3 with JournalFactory

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;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) MemoryJournal(org.apache.jackrabbit.core.journal.MemoryJournal) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 4 with JournalFactory

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>
 *   &lt;Journal class="..."&gt;
 *     &lt;param name="..." value="..."&gt;
 *     ...
 *   &lt;/Journal&gt;
 * </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;
        }
    };
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) AbstractJournal(org.apache.jackrabbit.core.journal.AbstractJournal) JournalException(org.apache.jackrabbit.core.journal.JournalException) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) Journal(org.apache.jackrabbit.core.journal.Journal) AbstractJournal(org.apache.jackrabbit.core.journal.AbstractJournal) RepositoryException(javax.jcr.RepositoryException)

Example 5 with JournalFactory

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>
 *   &lt;Cluster&gt;
 *     &lt;Journal ...&gt;
 *   &lt;/Journal&gt;
 * </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;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) Element(org.w3c.dom.Element) IOException(java.io.IOException) File(java.io.File)

Aggregations

JournalFactory (org.apache.jackrabbit.core.journal.JournalFactory)5 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)4 ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)3 MemoryJournal (org.apache.jackrabbit.core.journal.MemoryJournal)3 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)2 File (java.io.File)1 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 SimpleClusterContext (org.apache.jackrabbit.core.cluster.SimpleClusterContext)1 AbstractJournal (org.apache.jackrabbit.core.journal.AbstractJournal)1 Journal (org.apache.jackrabbit.core.journal.Journal)1 JournalException (org.apache.jackrabbit.core.journal.JournalException)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1