use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class GarbageCollector method scanPersistenceManagersByNodeIds.
private void scanPersistenceManagersByNodeIds() throws RepositoryException, ItemStateException {
int pmCount = 0;
for (IterablePersistenceManager pm : pmList) {
pmCount++;
List<NodeId> allNodeIds = pm.getAllNodeIds(null, 0);
int overAllCount = allNodeIds.size();
if (overAllCount > minSplitSize) {
final int splits = getConcurrentThreadSize();
ExecutorService executorService = Executors.newFixedThreadPool(splits);
try {
Set<Future<Void>> futures = new HashSet<Future<Void>>();
List<List<NodeId>> lists = splitIntoParts(allNodeIds, splits);
LOG.debug(splits + " concurrent Threads will be started. Split Size: " + lists.get(0).size() + " Total Size: " + overAllCount);
for (int i = 0; i < splits; i++) {
List<NodeId> subList = lists.get(i);
futures.add(executorService.submit(new ScanNodeIdListTask(i + 1, subList, pm, pmCount)));
}
for (Future<Void> future : futures) {
future.get();
}
} catch (Exception e) {
throw new RepositoryException(e);
} finally {
executorService.shutdown();
}
} else {
scanNodeIdList(0, allNodeIds, pm, pmCount);
}
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class GarbageCollector method mark.
public void mark() throws RepositoryException {
if (store == null) {
throw new RepositoryException("No DataStore configured.");
}
long now = System.currentTimeMillis();
if (startScanTimestamp == 0) {
startScanTimestamp = now;
store.updateModifiedDateOnAccess(startScanTimestamp);
}
if (pmList == null || !persistenceManagerScan) {
for (SessionImpl s : sessionList) {
scanNodes(s);
}
} else {
try {
if (!NODE_ID_SCAN) {
scanPersistenceManagersByNodeInfos();
} else {
scanPersistenceManagersByNodeIds();
}
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class DatabasePersistenceManager method store.
/**
* {@inheritDoc}
* <p>
* This method uses shared <code>PreparedStatement</code>s which must
* be executed strictly sequentially. Because this method synchronizes on
* the persistence manager instance there is no need to synchronize on the
* shared statement. If the method would not be synchronized the shared
* statements would have to be synchronized.
*/
@Override
public synchronized void store(PropertyState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
// check if insert or update
boolean update = state.getStatus() != ItemState.STATUS_NEW;
//boolean update = exists(state.getId());
String sql = (update) ? propertyStateUpdateSQL : propertyStateInsertSQL;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
// serialize property state
Serializer.serialize(state, out, blobStore);
// we are synchronized on this instance, therefore we do not
// not have to additionally synchronize on the sql statement
executeStmt(sql, new Object[] { out.toByteArray(), state.getPropertyId().toString() });
// there's no need to close a ByteArrayOutputStream
//out.close();
} catch (Exception e) {
String msg = "failed to write property state: " + state.getPropertyId();
log.error(msg, e);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class DatabasePersistenceManager method load.
/**
* {@inheritDoc}
*/
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
synchronized (propertyStateSelectSQL) {
ResultSet rs = null;
InputStream in = null;
try {
Statement stmt = executeStmt(propertyStateSelectSQL, new Object[] { id.toString() });
rs = stmt.getResultSet();
if (!rs.next()) {
throw new NoSuchItemStateException(id.toString());
}
in = rs.getBinaryStream(1);
if (!externalBLOBs) {
// JCR-1532: pre-fetch/buffer stream data
ByteArrayInputStream bain = new ByteArrayInputStream(IOUtils.toByteArray(in));
IOUtils.closeQuietly(in);
in = bain;
}
PropertyState state = createNew(id);
Serializer.deserialize(state, in, blobStore);
return state;
} catch (Exception e) {
if (e instanceof NoSuchItemStateException) {
throw (NoSuchItemStateException) e;
}
String msg = "failed to read property state: " + id;
log.error(msg, e);
throw new ItemStateException(msg, e);
} finally {
IOUtils.closeQuietly(in);
closeResultSet(rs);
}
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class DatabasePersistenceManager method exists.
/**
* {@inheritDoc}
*/
public boolean exists(NodeId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
synchronized (nodeStateSelectExistSQL) {
ResultSet rs = null;
try {
Statement stmt = executeStmt(nodeStateSelectExistSQL, new Object[] { id.toString() });
rs = stmt.getResultSet();
// a node state exists if the result has at least one entry
return rs.next();
} catch (Exception e) {
String msg = "failed to check existence of node state: " + id;
log.error(msg, e);
throw new ItemStateException(msg, e);
} finally {
closeResultSet(rs);
}
}
}
Aggregations