Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More meat-axe-ery
  • Loading branch information
ajs6f committed Jun 27, 2015
1 parent ba73229 commit 4ee65a5
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 283 deletions.
Expand Up @@ -16,7 +16,6 @@
package org.fcrepo.kernel.impl.services;

import static com.codahale.metrics.MetricRegistry.name;
import static com.google.common.base.Throwables.propagate;
import static org.fcrepo.kernel.impl.services.ServiceHelpers.getRepositoryCount;
import static org.slf4j.LoggerFactory.getLogger;

Expand Down Expand Up @@ -73,7 +72,7 @@ public Long getRepositorySize() {

}
} catch (final RepositoryException e) {
throw propagate(e);
throw new RepositoryRuntimeException(e);
}
}

Expand All @@ -87,7 +86,7 @@ public Long getRepositoryObjectCount() {
try {
return getRepositoryCount(repo);
} catch (final RepositoryException e) {
throw propagate(e);
throw new RepositoryRuntimeException(e);
}
}

Expand Down
Expand Up @@ -19,12 +19,11 @@

package org.fcrepo.kernel.impl.services;

import static com.google.common.collect.Maps.filterValues;
import static java.lang.System.currentTimeMillis;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import javax.jcr.RepositoryException;
Expand All @@ -37,6 +36,7 @@
import org.fcrepo.kernel.TxSession;
import org.fcrepo.kernel.exception.TransactionMissingException;
import org.fcrepo.kernel.services.TransactionService;

import org.slf4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
Expand All @@ -48,6 +48,7 @@
* annotation is used for removing timed out Transactions
*
* @author frank asseg
* @author ajs6f
*/
@Component
public class TransactionServiceImpl extends AbstractService implements TransactionService {
Expand Down Expand Up @@ -94,22 +95,15 @@ public static boolean isInTransaction(final Session session) {
@Scheduled(fixedRate = REAP_INTERVAL)
public void removeAndRollbackExpired() {
synchronized (transactions) {
final Iterator<Entry<String, Transaction>> txs =
transactions.entrySet().iterator();
while (txs.hasNext()) {
final Transaction tx = txs.next().getValue();
if (tx.getExpires().getTime() <= currentTimeMillis()) {
try {
tx.rollback();
} catch (final RepositoryRuntimeException e) {
LOGGER.error(
"Got exception rolling back expired" +
" transaction {}: {}",
tx, e);
}
txs.remove();
}
}
filterValues(transactions, tx -> tx.getExpires().getTime() <= currentTimeMillis())
.forEach((key, tx) -> {
try {
tx.rollback();
} catch (final RepositoryRuntimeException e) {
LOGGER.error("Got exception rolling back expired transaction {}: {}", tx, e);
}
transactions.remove(key);
});
}
}

Expand All @@ -134,13 +128,9 @@ public Transaction beginTransaction(final Session sess, final String userName) {

@Override
public Transaction getTransaction(final String txId, final String userName) {
final Transaction tx = transactions.get(txId);

if (tx == null) {
throw new TransactionMissingException(
"Transaction is not available");
}

final Transaction tx = transactions.computeIfAbsent(txId, s -> {
throw new TransactionMissingException("Transaction is not available");
});
if (!tx.isAssociatedWithUser(userName)) {
throw new TransactionMissingException("Transaction with id " +
txId + " is not available for user " + userName);
Expand All @@ -163,14 +153,9 @@ public Transaction getTransaction(final Session session) {
throw new TransactionMissingException(
"Transaction is not available");
}
final Transaction tx = transactions.get(txId);

if (tx == null) {
throw new TransactionMissingException(
"Transaction is not available");
}

return tx;
return transactions.computeIfAbsent(txId, s -> {
throw new TransactionMissingException("Transaction is not available");
});
}

/**
Expand Down

This file was deleted.

Expand Up @@ -15,12 +15,13 @@
*/
package org.fcrepo.kernel.impl.services.functions;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import javax.jcr.Repository;

Expand All @@ -31,16 +32,13 @@
import org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore;
import org.slf4j.Logger;

import com.google.common.base.Function;

/**
* Extract the Infinispan cluster configuration and state
* from a running Modeshape repository
* @author Gregory Jansen
* @since Apr 26, 2013
*/
public class GetClusterConfiguration implements
Function<Repository, Map<String, String>> {
public class GetClusterConfiguration implements Function<Repository, Map<String, String>> {

private static final Logger LOGGER =
getLogger(GetClusterConfiguration.class);
Expand All @@ -54,7 +52,7 @@ public class GetClusterConfiguration implements
public static final String CLUSTER_MEMBERS = "clusterMembers";
public static final int UNKNOWN_NODE_VIEW = -1;

private GetBinaryStore getBinaryStore = new GetBinaryStore();
private final GetBinaryStore getBinaryStore = new GetBinaryStore();

/**
* Extract the BinaryStore out of Modeshape
Expand All @@ -63,7 +61,7 @@ public class GetClusterConfiguration implements
*/
@Override
public Map<String, String> apply(final Repository input) {
checkNotNull(input, "null cannot have a BinaryStore!");
requireNonNull(input, "null cannot have a BinaryStore!");

final Map<String, String> result =
new LinkedHashMap<>();
Expand Down

This file was deleted.

Expand Up @@ -76,7 +76,7 @@ public void buildRepository() {
LOGGER.error("ModeShape Start Problem: {}", p.getMessageString());
// TODO determine problems that should be runtime errors
}
} catch (Exception e) {
} catch (final Exception e) {
throw new RepositoryRuntimeException(e);
}
}
Expand All @@ -92,14 +92,17 @@ public void stopRepository() throws InterruptedException {
LOGGER.info("Initiating shutdown of ModeShape");
final String repoName = repository.getName();
try {
final Future<Boolean> futureUndeployRepo =
modeShapeEngine.undeploy(repoName);
futureUndeployRepo.get();
final Future<Boolean> futureUndeployRepo = modeShapeEngine.undeploy(repoName);
if (futureUndeployRepo.get()) {
LOGGER.info("ModeShape repository {} has undeployed.", repoName);
} else {
LOGGER.error("ModeShape repository {} undeploy failed without an exception, still deployed.", repoName);
}
LOGGER.info("Repository {} undeployed.", repoName);
} catch (final NoSuchRepositoryException e) {
LOGGER.error("Repository {} unknown, cannot undeploy.", repoName, e);
} catch (final ExecutionException e) {
LOGGER.error("Repository {} cannot undeploy.", repoName, e);
LOGGER.error("Repository {} cannot undeploy.", repoName, e.getCause());
}
final Future<Boolean> futureShutdownEngine = modeShapeEngine.shutdown();
try {
Expand All @@ -109,7 +112,7 @@ public void stopRepository() throws InterruptedException {
LOGGER.error("ModeShape Engine shutdown failed without an exception, still running.");
}
} catch (final ExecutionException e) {
LOGGER.error("ModeShape Engine shutdown failed.", e);
LOGGER.error("ModeShape Engine shutdown failed.", e.getCause());
}
}

Expand Down
Expand Up @@ -15,22 +15,22 @@
*/
package org.fcrepo.kernel.impl.utils;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.io.IOUtils;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.utils.CacheEntry;
import org.fcrepo.kernel.utils.ContentDigest;
import org.fcrepo.kernel.utils.FixityResult;

import org.slf4j.Logger;

import javax.jcr.RepositoryException;

import java.io.IOException;
import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;

import static com.google.common.base.Throwables.propagate;
import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
import static java.util.Arrays.asList;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand All @@ -41,6 +41,8 @@
*/
public abstract class BasicCacheEntry implements CacheEntry {

private static final byte[] devNull = new byte[4096];

private static final Logger LOGGER = getLogger(BasicCacheEntry.class);

/**
Expand All @@ -57,8 +59,8 @@ public Collection<FixityResult> checkFixity(final String digest)

try (FixityInputStream fixityInputStream = new FixityInputStream(this.getInputStream(),
MessageDigest.getInstance(digest))) {

IOUtils.copy(fixityInputStream, NULL_OUTPUT_STREAM);
// exhaust our source
while (fixityInputStream.read(devNull) != -1) { }

final URI calculatedChecksum = ContentDigest.asURI(digest,
fixityInputStream.getMessageDigest().digest());
Expand All @@ -69,12 +71,12 @@ public Collection<FixityResult> checkFixity(final String digest)

LOGGER.debug("Got {}", result.toString());

return ImmutableSet.of(result);
return asList(result);
} catch (final IOException e) {
LOGGER.debug("Got error closing input stream: {}", e);
throw propagate(e);
throw new RepositoryRuntimeException(e);
} catch (final NoSuchAlgorithmException e1) {
throw propagate(e1);
throw new RepositoryRuntimeException(e1);
}

}
Expand Down
Expand Up @@ -38,13 +38,13 @@ public class FixityResultImpl implements FixityResult {
* the size computed by the fixity check
* @todo make this private
*/
private long computedSize;
private final long computedSize;

/**
* the checksum computed by the fixity check
* @todo make this private
*/
private URI computedChecksum;
private final URI computedChecksum;

private final String storeIdentifier;

Expand Down Expand Up @@ -111,8 +111,7 @@ public int hashCode() {

@Override
public String toString() {
return "Fixity: checksum: " + computedChecksum + " / " +
Long.toString(computedSize);
return "Fixity: checksum: " + computedChecksum + " / " + computedSize;
}

/**
Expand Down

0 comments on commit 4ee65a5

Please sign in to comment.