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");
}
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);
}
}
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();
}
}
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();
}
Aggregations