Removes the use of Rpcs and RpcErrors in favor of RpcResultBuilder.
Change-Id: I9bd5f710321ab70098e79bbab463c7b5447ffa17
Signed-off-by: Robert Varga <rovarga@cisco.com>
import com.google.common.util.concurrent.SettableFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
-import java.util.Collections;
-import org.opendaylight.controller.sal.common.util.RpcErrors;
-import org.opendaylight.controller.sal.common.util.Rpcs;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
* @param cause - details of reason
* @return
*/
- static RpcError buildRpcError(final String info, final ErrorSeverity severity, final String message,
- final Throwable cause) {
- RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message,
- ErrorType.RPC, cause);
- return error;
+ static RpcError buildRpcError(final String info, final String message, final Throwable cause) {
+ return RpcResultBuilder.newError(ErrorType.RPC, TAG, message, APPLICATION_TAG, info, cause);
}
AbstractRpcListener(final Object message, final String failureInfo) {
protected abstract void operationSuccessful();
protected final void failedRpc(final Throwable cause) {
- final RpcError rpcError = buildRpcError(
- failureInfo, ErrorSeverity.ERROR, "check switch connection", cause);
- result.set(Rpcs.getRpcResult(
- false,
- (T)null,
- Collections.singletonList(rpcError)));
+ final RpcError rpcError = buildRpcError(failureInfo, "check switch connection", cause);
+ result.set(RpcResultBuilder.<T>failed().withRpcError(rpcError).build());
}
protected final void successfulRpc(final T value) {
package org.opendaylight.openflowjava.protocol.impl.core.connection;
import static org.junit.Assert.fail;
-
-import java.util.Collections;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.controller.sal.common.util.Rpcs;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.AbstractRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcResult;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-import com.google.common.util.concurrent.SettableFuture;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
/**
* @author michal.polkorab
}
};
private static final int RPC_RESPONSE_EXPIRATION = 1;
- private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache = CacheBuilder.newBuilder()
+ private final Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);
listener.discard();
RpcError rpcError = AbstractRpcListener.buildRpcError("Failed to send message",
- ErrorSeverity.ERROR, "check switch connection", new TimeoutException("Request timed out"));
+ "check switch connection", new TimeoutException("Request timed out"));
SettableFuture<RpcResult<?>> result = SettableFuture.create();
- result.set(Rpcs.getRpcResult(false, null, Collections.singletonList(rpcError)));
+ result.set(RpcResultBuilder.failed().withRpcError(rpcError).build());
try {
Assert.assertEquals("Wrong result", result.get().getErrors().iterator().next().getMessage(),
listener.getResult().get().getErrors().iterator().next().getMessage());
BarrierInput barrierInput = barrierBuilder.build();
listener.completed(barrierInput);
SettableFuture<RpcResult<?>> result = SettableFuture.create();
- result.set(Rpcs.getRpcResult(true, barrierInput, Collections.<RpcError>emptyList()));
+ result.set(RpcResultBuilder.success(barrierInput).build());
try {
Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());
Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.util.concurrent.SettableFuture;
import io.netty.util.concurrent.Future;
-
-import java.util.Collections;
import java.util.concurrent.ExecutionException;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.sal.common.util.Rpcs;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-
-import com.google.common.util.concurrent.SettableFuture;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
/**
* @author michal.polkorab
SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
listener.operationSuccessful();
SettableFuture<RpcResult<?>> result = SettableFuture.create();
- result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>emptyList()));
+ result.set(RpcResultBuilder.success((Void)null).build());
try {
Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());
Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
MessageTypeKey<?> key = keyMaker.make(action);
Assert.assertNotNull("Null key", key);
- Assert.assertEquals("Wrong key", new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID,
+ Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
CopyTtlInCase.class, 42L), key);
}
MessageTypeKey<?> key = keyMaker.make(instruction);
Assert.assertNotNull("Null key", key);
- Assert.assertEquals("Wrong key", new InstructionSerializerKey(EncodeConstants.OF13_VERSION_ID,
+ Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
ClearActionsCase.class, 42L), key);
}