use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class RepositoryAccessServlet method getRepositoryByJNDI.
/**
* Checks if the repository is available via JNDI and returns it.
* @return the repository or <code>null</code>
* @throws ServletException if this servlet is not properly configured.
*/
private Repository getRepositoryByJNDI() throws ServletException {
BootstrapConfig config = getConfig();
if (!config.getJndiConfig().isValid() || !config.getJndiConfig().enabled()) {
return null;
}
// acquire via JNDI
String repositoryName = config.getRepositoryName();
InitialContext ctx = getInitialContext();
if (ctx == null) {
return null;
}
try {
Repository r = (Repository) ctx.lookup(repositoryName);
log.info("Acquired repository via JNDI.");
return r;
} catch (NamingException e) {
log.error("Error while retrieving repository using JNDI (name={})", repositoryName, e);
return null;
}
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class RemotingInitializer method webDavServlet.
@Bean
public ServletRegistrationBean webDavServlet() {
ServletRegistrationBean bean = new ServletRegistrationBean(new SimpleWebdavServlet() {
@Override
public Repository getRepository() {
return repository;
}
@Override
public ServletContext getServletContext() {
return RemotingInitializer.this.getServletContext();
}
}, "/repository/*");
bean.addInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, "/repository");
bean.addInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_CONFIG, "/remoting/webdav-config.xml");
return bean;
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ConcurrentAddNodesClusterIT method addNodesConcurrent2.
@Ignore("OAK-1807")
@Test
public void addNodesConcurrent2() throws Exception {
final Thread mainThread = Thread.currentThread();
for (int i = 0; i < NUM_CLUSTER_NODES; i++) {
DocumentMK mk = new DocumentMK.Builder().setMongoDB(createConnection().getDB()).setClusterId(i + 1).open();
mks.add(mk);
}
final Map<String, Exception> exceptions = Collections.synchronizedMap(new HashMap<String, Exception>());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean stop = new AtomicBoolean();
final UncaughtExceptionHandler ueh = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
RuntimeException r = new RuntimeException("Exception in thread " + t.getName(), e);
r.printStackTrace();
}
};
for (int i = 0; i < mks.size(); i++) {
DocumentMK mk = mks.get(i);
final Repository repo = new Jcr(mk.getNodeStore()).createRepository();
repos.add(repo);
for (int w = 0; w <= WORKER_COUNT; w++) {
final String name = "Worker-" + (i + 1) + "-" + (w + 1);
final Runnable r = new Runnable() {
final Session session = createAdminSession(repo);
int count = 0;
@Override
public void run() {
try {
Uninterruptibles.awaitUninterruptibly(latch);
session.refresh(false);
Node node = session.getRootNode().addNode(name + count++, "oak:Unstructured");
for (int j = 0; j < NODE_COUNT && !stop.get(); j++) {
node.addNode("node" + j);
session.save();
}
} catch (RepositoryException e) {
RuntimeException r = new RuntimeException("Exception in thread " + name, e);
r.printStackTrace();
exceptions.put(Thread.currentThread().getName(), r);
stop.set(true);
mainThread.interrupt();
} finally {
session.logout();
}
}
};
//Last runnable would be a long running one
Runnable runnable = r;
if (w == WORKER_COUNT) {
runnable = new Runnable() {
@Override
public void run() {
while (!stop.get()) {
r.run();
}
}
};
}
Thread t = new Thread(runnable);
t.setName(name);
t.setUncaughtExceptionHandler(ueh);
workers.add(t);
}
}
for (Thread t : workers) {
t.start();
}
latch.countDown();
TimeUnit.MINUTES.sleep(10);
stop.set(true);
for (Thread t : workers) {
t.join();
}
for (Map.Entry<String, Exception> entry : exceptions.entrySet()) {
// System.out.println("exception in thread " + entry.getKey());
throw entry.getValue();
}
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ConcurrentAddNodesClusterIT method addNodes2.
@Test
public void addNodes2() throws Exception {
for (int i = 0; i < 3; i++) {
DocumentMK mk = new DocumentMK.Builder().setMongoDB(createConnection().getDB()).setAsyncDelay(0).setClusterId(i + 1).open();
mks.add(mk);
}
final DocumentMK mk1 = mks.get(0);
final DocumentMK mk2 = mks.get(1);
final DocumentMK mk3 = mks.get(2);
Repository r1 = new Jcr(mk1.getNodeStore()).createRepository();
repos.add(r1);
Repository r2 = new Jcr(mk2.getNodeStore()).createRepository();
repos.add(r2);
Repository r3 = new Jcr(mk3.getNodeStore()).createRepository();
repos.add(r3);
Session s1 = r1.login(new SimpleCredentials("admin", "admin".toCharArray()));
Session s2 = r2.login(new SimpleCredentials("admin", "admin".toCharArray()));
Session s3 = r3.login(new SimpleCredentials("admin", "admin".toCharArray()));
ensureIndex(s1.getRootNode(), PROP_NAME);
runBackgroundOps(mk1);
runBackgroundOps(mk2);
runBackgroundOps(mk3);
// begin test
Node root2 = s2.getRootNode().addNode("testroot-Worker-2", "nt:unstructured");
createNodes(root2, "testnode0");
s2.save();
createNodes(root2, "testnode1");
runBackgroundOps(mk1);
runBackgroundOps(mk3);
// publish 'testroot-Worker-2/testnode0'
runBackgroundOps(mk2);
Node root3 = s3.getRootNode().addNode("testroot-Worker-3", "nt:unstructured");
createNodes(root3, "testnode0");
s2.save();
createNodes(root2, "testnode2");
// sees 'testroot-Worker-2/testnode0'
runBackgroundOps(mk1);
// sees 'testroot-Worker-2/testnode0'
runBackgroundOps(mk3);
// publish 'testroot-Worker-2/testnode1'
runBackgroundOps(mk2);
// subsequent read on mk3 will read already published docs from mk2
s3.save();
createNodes(root3, "testnode1");
Node root1 = s1.getRootNode().addNode("testroot-Worker-1", "nt:unstructured");
createNodes(root1, "testnode0");
s2.save();
createNodes(root2, "testnode3");
runBackgroundOps(mk1);
runBackgroundOps(mk3);
runBackgroundOps(mk2);
s1.save();
createNodes(root1, "testnode1");
s3.save();
createNodes(root3, "testnode2");
runBackgroundOps(mk1);
s1.save();
s1.logout();
s2.logout();
s3.logout();
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ConcurrentAddNodesClusterIT method after.
@After
public void after() throws Exception {
workers.clear();
for (Repository repo : repos) {
dispose(repo);
}
repos.clear();
for (DocumentMK mk : mks) {
mk.dispose();
}
mks.clear();
dropDB();
}
Aggregations