Skip to content

Commit

Permalink
Fix deprecation and other warnings
Browse files Browse the repository at this point in the history
Modification:

Fixes many deprecation warnings, many from Guava and Parboiled. Fixes
various other minor warnings.

Result:

No user visible changes.

Target: trunk
Require-notes: no
Require-book: no
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Patch: https://rb.dcache.org/r/9088/
  • Loading branch information
gbehrmann committed Mar 4, 2016
1 parent 95d0966 commit 02100c8
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 164 deletions.
@@ -1,6 +1,6 @@
package dmg.cells.applets.login ;

import com.google.common.base.Objects;
import com.google.common.base.MoreObjects;

import java.io.Serializable;

Expand Down Expand Up @@ -41,7 +41,7 @@ public boolean equals( Object obj ){
@Override
public String toString()
{
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.add("payload", _payload)
.add("destination", _destination)
.add("id", _id)
Expand Down
@@ -1,6 +1,6 @@
package dmg.cells.services ;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -129,7 +129,7 @@ public void say(String str ){
}

@Override
@SuppressWarnings(
@SuppressFBWarnings(
value="DM_GC",
justification="Although bad practice, the GC call is part of the design of the cell"
)
Expand Down
@@ -1,6 +1,6 @@
package dmg.util.command;

import com.google.common.base.Objects;
import com.google.common.base.MoreObjects;
import com.google.common.base.Throwables;

import java.io.Serializable;
Expand All @@ -12,6 +12,7 @@
import dmg.util.CommandPanicException;
import dmg.util.CommandSyntaxException;
import dmg.util.CommandThrowableException;

import org.dcache.util.Args;
import org.dcache.util.cli.CommandExecutor;

Expand Down Expand Up @@ -175,7 +176,7 @@ public Serializable execute(Args arguments) throws CommandException
@Override
public String toString()
{
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.addValue(_method)
.addValue(_fullHelp)
.addValue(_helpHint)
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class AnnotatedCommandScanner implements CommandScanner
@SuppressWarnings("unchecked")
private Class<? extends Callable<? extends Serializable>> cast(Class<?> clazz)
{
if (EXPECTED_TYPE.isAssignableFrom(clazz)) {
if (EXPECTED_TYPE.isSupertypeOf(clazz)) {
return (Class<? extends Callable<? extends Serializable>>) clazz.asSubclass(Callable.class);
}
throw new RuntimeException("This is a bug. Please notify support@dcache.org (" + clazz +
Expand Down
Expand Up @@ -320,11 +320,11 @@ private ListenableFuture<List<String>> getCells(String domain, Predicate<String>
.map(cell -> cell + "@" + domain)
.collect(toList()));
/* Log and ignore any errors. */
return withFallback(future,
t -> {
_log.debug("Failed to query the System cell of domain {}: {}", domain, t);
return immediateFuture(emptyList());
});
return catchingAsync(future, Throwable.class,
t -> {
_log.debug("Failed to query the System cell of domain {}: {}", domain, t);
return immediateFuture(emptyList());
});
}

/**
Expand Down Expand Up @@ -368,7 +368,7 @@ private ListenableFuture<List<String>> getPoolsInGroups(Predicate<String> predic
ListenableFuture<List<String>> poolGroups = getPoolGroups();

/* Query the pools of each pool group so we have a list of list of pools. */
ListenableFuture<List<Stream<String>>> pools = transform(
ListenableFuture<List<Stream<String>>> pools = transformAsync(
poolGroups,
(List<String> groups) ->
allAsList(groups.stream().filter(predicate).map(this::getPools).collect(toList())));
Expand Down
83 changes: 34 additions & 49 deletions modules/dcache/src/main/java/org/dcache/cells/CellStub.java
Expand Up @@ -8,8 +8,6 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.RateLimiter;

import javax.annotation.Nullable;

import java.io.Serializable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -497,31 +495,26 @@ public String toString()
public static <T extends Message> void addCallback(
final ListenableFuture<T> future, final MessageCallback<? super T> callback, Executor executor)
{
future.addListener(new Runnable()
{
@Override
public void run()
{
try {
T reply = getUninterruptibly(future);
callback.setReply(reply);
if (reply.getReturnCode() != 0) {
callback.failure(reply.getReturnCode(), reply.getErrorObject());
} else {
callback.success();
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof TimeoutCacheException) {
callback.timeout(cause.getMessage());
} else if (cause instanceof CacheException) {
CacheException cacheException = (CacheException) cause;
callback.failure(cacheException.getRc(), cacheException.getMessage());
} else if (cause instanceof NoRouteToCellException) {
callback.noroute(((NoRouteToCellException) cause).getDestinationPath());
} else {
callback.failure(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, cause);
}
future.addListener(() -> {
try {
T reply = getUninterruptibly(future);
callback.setReply(reply);
if (reply.getReturnCode() != 0) {
callback.failure(reply.getReturnCode(), reply.getErrorObject());
} else {
callback.success();
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof TimeoutCacheException) {
callback.timeout(cause.getMessage());
} else if (cause instanceof CacheException) {
CacheException cacheException = (CacheException) cause;
callback.failure(cacheException.getRc(), cacheException.getMessage());
} else if (cause instanceof NoRouteToCellException) {
callback.noroute(((NoRouteToCellException) cause).getDestinationPath());
} else {
callback.failure(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, cause);
}
}
}, executor);
Expand Down Expand Up @@ -560,17 +553,13 @@ public static <T extends Message> T getMessage(Future<T> future)
public static <T extends Message, V> ListenableFuture<V> transform(
ListenableFuture<T> future, Function<T, V> f)
{
return Futures.transform(future,
new AsyncFunction<T, V>() {
@Override
public ListenableFuture<V> apply(T msg) throws Exception
{
if (msg.getReturnCode() != 0) {
throw CacheExceptionFactory.exceptionOf(msg);
}
return Futures.immediateFuture(f.apply(msg));
}
});
return Futures.transformAsync(future,
msg -> {
if (msg.getReturnCode() != 0) {
throw CacheExceptionFactory.exceptionOf(msg);
}
return Futures.immediateFuture(f.apply(msg));
});
}

/**
Expand All @@ -587,17 +576,13 @@ public ListenableFuture<V> apply(T msg) throws Exception
public static <T extends Message, V> ListenableFuture<V> transform(
ListenableFuture<T> future, AsyncFunction<T, V> f)
{
return Futures.transform(future,
new AsyncFunction<T, V>() {
@Override
public ListenableFuture<V> apply(T msg) throws Exception
{
if (msg.getReturnCode() != 0) {
throw CacheExceptionFactory.exceptionOf(msg);
}
return f.apply(msg);
}
});
return Futures.transformAsync(future,
msg -> {
if (msg.getReturnCode() != 0) {
throw CacheExceptionFactory.exceptionOf(msg);
}
return f.apply(msg);
});
}

/**
Expand Down
Expand Up @@ -681,7 +681,7 @@ private Expression createPredicate(String s, Expression ifNull,
ParsingResult<Expression> result =
new ReportingParseRunner<Expression>(parser.Top()).run(s);

if (result.hasErrors()) {
if (!result.isSuccess()) {
throw new IllegalArgumentException("Invalid expression: " +
printParseErrors(result));
}
Expand Down
Expand Up @@ -26,16 +26,16 @@

import javax.security.auth.Subject;

import java.io.InterruptedIOException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.channels.CompletionHandler;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Set;

import diskCacheV111.util.CacheException;
import diskCacheV111.util.DiskErrorCacheException;
import diskCacheV111.util.ChecksumFactory;
import diskCacheV111.util.DiskErrorCacheException;
import diskCacheV111.vehicles.PoolAcceptFileMessage;
import diskCacheV111.vehicles.PoolIoFileMessage;
import diskCacheV111.vehicles.ProtocolInfo;
Expand All @@ -45,7 +45,6 @@
import org.dcache.pool.classic.Cancellable;
import org.dcache.pool.classic.ChecksumModule;
import org.dcache.pool.classic.TransferService;
import org.dcache.pool.repository.FileRepositoryChannel;
import org.dcache.pool.repository.ReplicaDescriptor;
import org.dcache.pool.repository.RepositoryChannel;
import org.dcache.util.Checksum;
Expand Down Expand Up @@ -83,7 +82,7 @@ public AbstractMover(ReplicaDescriptor handle, PoolIoFileMessage message, CellPa
ChecksumModule checksumModule)
{
TypeToken<M> type = new TypeToken<M>(getClass()) {};
checkArgument(type.isAssignableFrom(getClass()));
checkArgument(type.isSupertypeOf(getClass()));

_queue = message.getIoQueueName();
_protocolInfo = (P) message.getProtocolInfo();
Expand Down
Expand Up @@ -102,6 +102,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.util.concurrent.Futures.transformAsync;
import static org.dcache.namespace.FileAttribute.*;

/**
Expand Down Expand Up @@ -743,14 +744,14 @@ public long getDeadline()
public ListenableFuture<Void> activate()
{
LOGGER.debug("Activating flush of {}.", getFileAttributes().getPnfsId());
return register(Futures.transform(super.activate(), new PreFlushFunction(), executor));
return register(transformAsync(super.activate(), new PreFlushFunction(), executor));
}

@Override
public ListenableFuture<String> activateWithPath()
{
LOGGER.debug("Activating flush of {}.", getFileAttributes().getPnfsId());
return register(Futures.transform(super.activate(), new PreFlushWithPathFunction(), executor));
return register(transformAsync(super.activate(), new PreFlushWithPathFunction(), executor));
}

@Override
Expand Down
@@ -1,6 +1,6 @@
package org.dcache.poolmanager;

import com.google.common.base.Objects;
import com.google.common.base.MoreObjects;

import diskCacheV111.poolManager.PoolSelectionUnit.SelectionLinkGroup;

Expand Down Expand Up @@ -94,7 +94,7 @@ public boolean isNearlineAllowed() {
@Override
public String toString()
{
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.add("groupName", _groupName)
.add("totalSpace", _totalSpaceInBytes)
.add("availableSpace", _availableSpaceInBytes)
Expand Down

0 comments on commit 02100c8

Please sign in to comment.