Search in sources :

Example 6 with ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode in project jackrabbit by apache.

the class RepositoryImpl method doShutdown.

/**
     * Protected method that performs the actual shutdown after the shutdown
     * lock has been acquired by the {@link #shutdown()} method.
     */
protected synchronized void doShutdown() {
    log.info("Shutting down repository...");
    // stop optional cluster node
    ClusterNode clusterNode = context.getClusterNode();
    if (clusterNode != null) {
        clusterNode.stop();
    }
    if (securityMgr != null) {
        securityMgr.close();
    }
    // close active user sessions
    // (copy sessions to array to avoid ConcurrentModificationException;
    // manually copy entries rather than calling ReferenceMap#toArray() in
    // order to work around  http://issues.apache.org/bugzilla/show_bug.cgi?id=25551)
    List<Session> sa;
    synchronized (activeSessions) {
        sa = new ArrayList<Session>(activeSessions.size());
        for (Session session : activeSessions.values()) {
            sa.add(session);
        }
    }
    for (Session session : sa) {
        if (session != null) {
            session.logout();
        }
    }
    // shutdown system search manager if there is one
    if (systemSearchMgr != null) {
        systemSearchMgr.close();
    }
    // shut down workspaces
    synchronized (wspInfos) {
        for (WorkspaceInfo wspInfo : wspInfos.values()) {
            wspInfo.dispose();
        }
    }
    try {
        InternalVersionManager m = context.getInternalVersionManager();
        if (m != null) {
            m.close();
        }
    } catch (Exception e) {
        log.error("Error while closing Version Manager.", e);
    }
    repDescriptors.clear();
    DataStore dataStore = context.getDataStore();
    if (dataStore != null) {
        try {
            // close the datastore
            dataStore.close();
        } catch (DataStoreException e) {
            log.error("error while closing datastore", e);
        }
    }
    try {
        // close repository file system
        context.getFileSystem().close();
    } catch (FileSystemException e) {
        log.error("error while closing repository file system", e);
    }
    try {
        nodeIdFactory.close();
    } catch (RepositoryException e) {
        log.error("error while closing repository file system", e);
    }
    // make sure this instance is not used anymore
    disposed = true;
    // wake up threads waiting on this instance's monitor (e.g. workspace janitor)
    notifyAll();
    // Shut down the executor service
    ScheduledExecutorService executor = context.getExecutor();
    executor.shutdown();
    try {
        // Wait for all remaining background threads to terminate
        if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
            log.warn("Attempting to forcibly shutdown runaway threads");
            executor.shutdownNow();
        }
    } catch (InterruptedException e) {
        log.warn("Interrupted while waiting for background threads", e);
    }
    repConfig.getConnectionFactory().close();
    // finally release repository lock
    if (repLock != null) {
        try {
            repLock.release();
        } catch (RepositoryException e) {
            log.error("failed to release the repository lock", e);
        }
    }
    log.info("Repository has been shutdown");
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RepositoryException(javax.jcr.RepositoryException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) AccessDeniedException(javax.jcr.AccessDeniedException) IOException(java.io.IOException) LoginException(javax.jcr.LoginException) TransactionException(org.apache.jackrabbit.data.core.TransactionException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) DataStore(org.apache.jackrabbit.core.data.DataStore) Session(javax.jcr.Session) InternalVersionManager(org.apache.jackrabbit.core.version.InternalVersionManager)

Example 7 with ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode in project jackrabbit by apache.

the class RepositoryImpl method createClusterNode.

/**
     * Creates the cluster node.
     *
     * @return clustered node
     */
protected ClusterNode createClusterNode() throws RepositoryException {
    try {
        ClusterNode clusterNode = new ClusterNode();
        clusterNode.init(new ExternalEventListener());
        return clusterNode;
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) RepositoryException(javax.jcr.RepositoryException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) AccessDeniedException(javax.jcr.AccessDeniedException) IOException(java.io.IOException) LoginException(javax.jcr.LoginException) TransactionException(org.apache.jackrabbit.data.core.TransactionException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 with ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode in project jackrabbit by apache.

the class FileJournalTest method testRevisionIsOptional.

/**
     * Create a journal with no revision file name. Verify that the journal
     * is created nonetheless, with a revision file in the repository home.
     *
     * @throws Exception
     * @see <a href="http://issues.apache.org/jira/browse/JCR-904">JCR-904</a>
     */
public void testRevisionIsOptional() throws Exception {
    final FileJournal journal = new FileJournal();
    journal.setDirectory(journalDirectory.getPath());
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) {
            return journal;
        }
    };
    ClusterConfig cc = new ClusterConfig(CLUSTER_NODE_ID, SYNC_DELAY, jf);
    SimpleClusterContext context = new SimpleClusterContext(cc, repositoryHome);
    journal.setRepositoryHome(repositoryHome);
    journal.init(CLUSTER_NODE_ID, context.getNamespaceResolver());
    ClusterNode clusterNode = new ClusterNode();
    clusterNode.init(context);
    try {
        File revisionFile = new File(repositoryHome, FileJournal.DEFAULT_INSTANCE_FILE_NAME);
        assertTrue(revisionFile.exists());
    } finally {
        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) File(java.io.File) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 9 with ClusterNode

use of org.apache.jackrabbit.core.cluster.ClusterNode in project jackrabbit by apache.

the class FileJournalTest method testClusterInitIncompleteBadJournalClass.

/**
     * Verify that <code>ClusterNode.stop</code> can be invoked even when
     * <code>ClusterNode.init</code> throws because of a bad journal class.
     *
     * @throws Exception
     */
public void testClusterInitIncompleteBadJournalClass() throws Exception {
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            throw new RepositoryException("Journal not available");
        }
    };
    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)

Aggregations

ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)9 RepositoryException (javax.jcr.RepositoryException)6 IOException (java.io.IOException)4 SimpleClusterContext (org.apache.jackrabbit.core.cluster.SimpleClusterContext)4 ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)4 NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)4 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)3 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)3 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 ArrayList (java.util.ArrayList)2 AccessDeniedException (javax.jcr.AccessDeniedException)2 LoginException (javax.jcr.LoginException)2 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)2 ChangeLogRecord (org.apache.jackrabbit.core.cluster.ChangeLogRecord)2 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)2 JournalException (org.apache.jackrabbit.core.journal.JournalException)2 TransactionException (org.apache.jackrabbit.data.core.TransactionException)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1