Search in sources :

Example 1 with ClusterConfig

use of org.apache.jackrabbit.core.config.ClusterConfig in project jackrabbit by apache.

the class ClusterNode method init.

/**
     * Initialize this cluster node (overridable).
     *
     * @throws ClusterException if an error occurs
     */
protected void init() throws ClusterException {
    ClusterConfig cc = clusterContext.getClusterConfig();
    clusterNodeId = cc.getId();
    syncDelay = cc.getSyncDelay();
    stopDelay = cc.getStopDelay();
    try {
        journal = cc.getJournal(clusterContext.getNamespaceResolver());
        instanceRevision = journal.getInstanceRevision();
        journal.register(this);
        producer = journal.getProducer(PRODUCER_ID);
    } catch (RepositoryException e) {
        throw new ClusterException("Cluster initialization failed: " + this, e);
    } catch (JournalException e) {
        throw new ClusterException("Journal initialization failed: " + this, e);
    }
}
Also used : JournalException(org.apache.jackrabbit.core.journal.JournalException) RepositoryException(javax.jcr.RepositoryException) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 2 with ClusterConfig

use of org.apache.jackrabbit.core.config.ClusterConfig in project jackrabbit by apache.

the class FileJournalTest method testClusterInitIncompleteMissingParam.

/**
     * Verify that <code>ClusterNode.stop</code> can be invoked even when
     * <code>ClusterNode.init</code> throws because the journal can not
     * be initialized. Note: this is done by omitting the required argument
     * <code>directory</code>.
     *
     * @throws Exception
     */
public void testClusterInitIncompleteMissingParam() throws Exception {
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            try {
                FileJournal journal = new FileJournal();
                // no setDirectory() call here
                journal.init(CLUSTER_NODE_ID, resolver);
                return journal;
            } catch (JournalException e) {
                throw new RepositoryException("Expected failure", e);
            }
        }
    };
    ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
    SimpleClusterContext context = new SimpleClusterContext(cc);
    ClusterNode clusterNode = new ClusterNode();
    try {
        clusterNode.init(context);
        fail("Bad cluster configuration.");
    } catch (Exception e) {
    }
    clusterNode.stop();
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) SimpleClusterContext(org.apache.jackrabbit.core.cluster.SimpleClusterContext) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) RepositoryException(javax.jcr.RepositoryException) RepositoryException(javax.jcr.RepositoryException) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 3 with ClusterConfig

use of org.apache.jackrabbit.core.config.ClusterConfig 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 4 with ClusterConfig

use of org.apache.jackrabbit.core.config.ClusterConfig 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 5 with ClusterConfig

use of org.apache.jackrabbit.core.config.ClusterConfig 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)

Aggregations

ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)7 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)6 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)4 SimpleClusterContext (org.apache.jackrabbit.core.cluster.SimpleClusterContext)4 RepositoryException (javax.jcr.RepositoryException)3 JournalFactory (org.apache.jackrabbit.core.journal.JournalFactory)3 MemoryJournal (org.apache.jackrabbit.core.journal.MemoryJournal)3 File (java.io.File)1 JournalException (org.apache.jackrabbit.core.journal.JournalException)1