Define DataStoreVersions.MAGNESIUM_VERSION
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / shardmanager / ShardManagerInfo.java
index 61f9c1ca719909f4951a140c1c25189949bd8c05..244b0a186cdaba4b3400a5be8dcc3d08e08d30ae 100644 (file)
@@ -5,14 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore.shardmanager;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.pattern.Patterns;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import java.util.List;
+import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
 import org.opendaylight.controller.cluster.raft.RaftState;
 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
@@ -29,26 +29,28 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
     private static final long ASK_TIMEOUT_MILLIS = 5000;
 
     private final ActorRef shardManager;
-    private final String memberName;
+    private final MemberName memberName;
 
     private volatile boolean syncStatus = false;
 
 
-    ShardManagerInfo(final ActorRef shardManager, final String memberName, final String name,
+    ShardManagerInfo(final ActorRef shardManager, final MemberName memberName, final String name,
         final String mxBeanType) {
         super(name, mxBeanType, JMX_CATEGORY_SHARD_MANAGER);
-        this.shardManager = Preconditions.checkNotNull(shardManager);
-        this.memberName = Preconditions.checkNotNull(memberName);
+        this.shardManager = requireNonNull(shardManager);
+        this.memberName = requireNonNull(memberName);
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch"})
     @Override
     public List<String> getLocalShards() {
         try {
             return (List<String>) Await.result(
                 Patterns.ask(shardManager, GetLocalShardIds.INSTANCE, ASK_TIMEOUT_MILLIS), Duration.Inf());
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
-            throw Throwables.propagate(e);
+            throw new RuntimeException(e);
         }
     }
 
@@ -57,15 +59,16 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
         return syncStatus;
     }
 
-    void setSyncStatus(boolean syncStatus) {
+    void setSyncStatus(final boolean syncStatus) {
         this.syncStatus = syncStatus;
     }
 
     @Override
     public String getMemberName() {
-        return memberName;
+        return memberName.getName();
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void requestSwitchShardState(final ShardIdentifier shardId, final String newState, final long term) {
         // Validates strings argument
         final RaftState state = RaftState.valueOf(newState);
@@ -77,8 +80,10 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
                 try {
                     Await.result(Patterns.ask(shardManager, new SwitchShardBehavior(shardId, state, term),
                         ASK_TIMEOUT_MILLIS), Duration.Inf());
+                } catch (RuntimeException e) {
+                    throw e;
                 } catch (Exception e) {
-                    throw Throwables.propagate(e);
+                    throw new RuntimeException(e);
                 }
                 break;
             case Candidate:
@@ -89,15 +94,14 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
     }
 
     @Override
-    public void switchAllLocalShardsState(String newState, long term) {
+    public void switchAllLocalShardsState(final String newState, final long term) {
         LOG.info("switchAllLocalShardsState called newState = {}, term = {}", newState, term);
         requestSwitchShardState(null, newState, term);
     }
 
     @Override
-    public void switchShardState(String shardId, String newState, long term) {
-        final ShardIdentifier identifier = ShardIdentifier.builder().fromShardIdString(
-                Preconditions.checkNotNull(shardId, "Shard id may not be null")).build();
+    public void switchShardState(final String shardId, final String newState, final long term) {
+        final ShardIdentifier identifier = ShardIdentifier.fromShardIdString(shardId);
         LOG.info("switchShardState called shardName = {}, newState = {}, term = {}", shardId, newState, term);
         requestSwitchShardState(identifier, newState, term);
     }