Search in sources :

Example 1 with JournalException

use of org.apache.jackrabbit.core.journal.JournalException 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 JournalException

use of org.apache.jackrabbit.core.journal.JournalException in project jackrabbit by apache.

the class SearchIndex method getChangeLogRecords.

/**
 * Polls the underlying journal for events of the type ChangeLogRecord that
 * happened after a given revision, on a given workspace.
 *
 * @param revision
 *            starting revision
 * @param workspace
 *            the workspace name
 * @return
 */
private List<ChangeLogRecord> getChangeLogRecords(long revision, final String workspace) {
    log.debug("Get changes from the Journal for revision {} and workspace {}.", revision, workspace);
    ClusterNode cn = getContext().getClusterNode();
    if (cn == null) {
        return Collections.emptyList();
    }
    Journal journal = cn.getJournal();
    final List<ChangeLogRecord> events = new ArrayList<ChangeLogRecord>();
    ClusterRecordDeserializer deserializer = new ClusterRecordDeserializer();
    RecordIterator records = null;
    try {
        records = journal.getRecords(revision);
        while (records.hasNext()) {
            Record record = records.nextRecord();
            if (!record.getProducerId().equals(cn.getId())) {
                continue;
            }
            ClusterRecord r = null;
            try {
                r = deserializer.deserialize(record);
            } catch (JournalException e) {
                log.error("Unable to read revision '" + record.getRevision() + "'.", e);
            }
            if (r == null) {
                continue;
            }
            r.process(new ClusterRecordProcessor() {

                public void process(ChangeLogRecord record) {
                    String eventW = record.getWorkspace();
                    if (eventW != null ? eventW.equals(workspace) : workspace == null) {
                        events.add(record);
                    }
                }

                public void process(LockRecord record) {
                }

                public void process(NamespaceRecord record) {
                }

                public void process(NodeTypeRecord record) {
                }

                public void process(PrivilegeRecord record) {
                }

                public void process(WorkspaceRecord record) {
                }
            });
        }
    } catch (JournalException e1) {
        log.error(e1.getMessage(), e1);
    } finally {
        if (records != null) {
            records.close();
        }
    }
    return events;
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) RecordIterator(org.apache.jackrabbit.core.journal.RecordIterator) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) JournalException(org.apache.jackrabbit.core.journal.JournalException) ArrayList(java.util.ArrayList) LockRecord(org.apache.jackrabbit.core.cluster.LockRecord) NamespaceRecord(org.apache.jackrabbit.core.cluster.NamespaceRecord) Journal(org.apache.jackrabbit.core.journal.Journal) ClusterRecordDeserializer(org.apache.jackrabbit.core.cluster.ClusterRecordDeserializer) WorkspaceRecord(org.apache.jackrabbit.core.cluster.WorkspaceRecord) NodeTypeRecord(org.apache.jackrabbit.core.cluster.NodeTypeRecord) PrivilegeRecord(org.apache.jackrabbit.core.cluster.PrivilegeRecord) ClusterRecordProcessor(org.apache.jackrabbit.core.cluster.ClusterRecordProcessor) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) Record(org.apache.jackrabbit.core.journal.Record) NamespaceRecord(org.apache.jackrabbit.core.cluster.NamespaceRecord) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) PrivilegeRecord(org.apache.jackrabbit.core.cluster.PrivilegeRecord) NodeTypeRecord(org.apache.jackrabbit.core.cluster.NodeTypeRecord) LockRecord(org.apache.jackrabbit.core.cluster.LockRecord) WorkspaceRecord(org.apache.jackrabbit.core.cluster.WorkspaceRecord)

Example 3 with JournalException

use of org.apache.jackrabbit.core.journal.JournalException in project jackrabbit by apache.

the class EventJournalImpl method refill.

/**
 * Refills the {@link #eventBundleBuffer}.
 */
private void refill() {
    assert eventBundleBuffer.isEmpty();
    try {
        RecordProcessor processor = new RecordProcessor();
        ClusterRecordDeserializer deserializer = new ClusterRecordDeserializer();
        RecordIterator records;
        if (lastRevision != null) {
            log.debug("refilling event bundle buffer starting at revision {}", lastRevision);
            records = journal.getRecords(lastRevision.longValue());
        } else {
            log.debug("refilling event bundle buffer starting at journal beginning");
            records = journal.getRecords();
        }
        try {
            while (processor.getNumEvents() < MIN_BUFFER_SIZE && records.hasNext()) {
                Record record = records.nextRecord();
                if (record.getProducerId().equals(producerId)) {
                    ClusterRecord cr = deserializer.deserialize(record);
                    if (!session.getWorkspace().getName().equals(cr.getWorkspace())) {
                        continue;
                    }
                    cr.process(processor);
                    lastRevision = new Long(cr.getRevision());
                }
            }
            if (processor.getNumEvents() >= MIN_BUFFER_SIZE) {
                // remember in skip map
                SortedMap<Long, Long> skipMap = getSkipMap();
                Long timestamp = new Long(processor.getLastTimestamp());
                synchronized (skipMap) {
                    if (log.isDebugEnabled()) {
                        DateFormat df = DateFormat.getDateTimeInstance();
                        log.debug("remember record in skip map: {} -> {}", df.format(new Date(timestamp.longValue())), lastRevision);
                    }
                    skipMap.put(timestamp, lastRevision);
                }
            }
        } finally {
            records.close();
        }
    } catch (JournalException e) {
        log.warn("Unable to read journal records", e);
    }
}
Also used : RecordIterator(org.apache.jackrabbit.core.journal.RecordIterator) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) ClusterRecordProcessor(org.apache.jackrabbit.core.cluster.ClusterRecordProcessor) JournalException(org.apache.jackrabbit.core.journal.JournalException) DateFormat(java.text.DateFormat) PrivilegeRecord(org.apache.jackrabbit.core.cluster.PrivilegeRecord) ClusterRecord(org.apache.jackrabbit.core.cluster.ClusterRecord) Record(org.apache.jackrabbit.core.journal.Record) NamespaceRecord(org.apache.jackrabbit.core.cluster.NamespaceRecord) ChangeLogRecord(org.apache.jackrabbit.core.cluster.ChangeLogRecord) NodeTypeRecord(org.apache.jackrabbit.core.cluster.NodeTypeRecord) LockRecord(org.apache.jackrabbit.core.cluster.LockRecord) WorkspaceRecord(org.apache.jackrabbit.core.cluster.WorkspaceRecord) ClusterRecordDeserializer(org.apache.jackrabbit.core.cluster.ClusterRecordDeserializer) Date(java.util.Date)

Example 4 with JournalException

use of org.apache.jackrabbit.core.journal.JournalException in project jackrabbit by apache.

the class NodeTypeRecord method doRead.

/**
 * {@inheritDoc}
 */
@Override
protected void doRead() throws JournalException {
    int size = record.readInt();
    int opcode = size & NTREG_MASK;
    size &= ~NTREG_MASK;
    switch(opcode) {
        case NTREG_REGISTER:
            operation = REGISTER;
            collection = new HashSet();
            for (int i = 0; i < size; i++) {
                collection.add(record.readNodeTypeDef());
            }
            break;
        case NTREG_REREGISTER:
            operation = REREGISTER;
            collection = new HashSet();
            collection.add(record.readNodeTypeDef());
            break;
        case NTREG_UNREGISTER:
            operation = UNREGISTER;
            collection = new HashSet();
            for (int i = 0; i < size; i++) {
                collection.add(record.readQName());
            }
            break;
        default:
            String msg = "Unknown opcode: " + opcode;
            throw new JournalException(msg);
    }
}
Also used : JournalException(org.apache.jackrabbit.core.journal.JournalException) HashSet(java.util.HashSet)

Example 5 with JournalException

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

Aggregations

JournalException (org.apache.jackrabbit.core.journal.JournalException)5 RepositoryException (javax.jcr.RepositoryException)2 ChangeLogRecord (org.apache.jackrabbit.core.cluster.ChangeLogRecord)2 ClusterRecord (org.apache.jackrabbit.core.cluster.ClusterRecord)2 ClusterRecordDeserializer (org.apache.jackrabbit.core.cluster.ClusterRecordDeserializer)2 ClusterRecordProcessor (org.apache.jackrabbit.core.cluster.ClusterRecordProcessor)2 LockRecord (org.apache.jackrabbit.core.cluster.LockRecord)2 NamespaceRecord (org.apache.jackrabbit.core.cluster.NamespaceRecord)2 NodeTypeRecord (org.apache.jackrabbit.core.cluster.NodeTypeRecord)2 PrivilegeRecord (org.apache.jackrabbit.core.cluster.PrivilegeRecord)2 WorkspaceRecord (org.apache.jackrabbit.core.cluster.WorkspaceRecord)2 Journal (org.apache.jackrabbit.core.journal.Journal)2 Record (org.apache.jackrabbit.core.journal.Record)2 RecordIterator (org.apache.jackrabbit.core.journal.RecordIterator)2 DateFormat (java.text.DateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)1