Removed some sonar warnings from pcep. 39/3439/2
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 4 Dec 2013 12:35:16 +0000 (13:35 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 4 Dec 2013 13:05:11 +0000 (14:05 +0100)
Change-Id: I669cc2821455423424afa23497340cf95de4aed3
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
12 files changed:
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTerminationReason.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractMessageParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java
pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/TunnelProgramming.java

index 3b263b8a0201dcfd11bc323b43272c0d1fe612d4..ea4cd347777ee42b2a722f45293d1de97c128043 100644 (file)
@@ -19,5 +19,5 @@ public abstract class PCEPTerminationReason implements TerminationReason {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
-       abstract protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper);
+       protected abstract ToStringHelper addToStringAttributes(ToStringHelper toStringHelper);
 }
index 28d011fe154c195c5dd293900e126b8245ad38f4..50e1112d0d13ca9b4d0686fdea762d9d763199ce 100644 (file)
@@ -73,7 +73,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                Finished,
        }
 
-       private static final Logger logger = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class);
+       private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class);
 
        private final Timer timer;
 
@@ -184,7 +184,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
        }
 
        @Override
-       final synchronized protected void startNegotiation() {
+       protected final synchronized void startNegotiation() {
                Preconditions.checkState(this.state == State.Idle);
                this.localPrefs = getInitialProposal();
                final OpenMessage m = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder().setOpenMessage(
@@ -193,14 +193,14 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                this.state = State.OpenWait;
                scheduleFailTimer();
 
-               logger.debug("Channel {} started sent proposal {}", this.channel, this.localPrefs);
+               LOG.debug("Channel {} started sent proposal {}", this.channel, this.localPrefs);
        }
 
        @Override
-       final synchronized protected void handleMessage(final Message msg) {
+       protected final synchronized void handleMessage(final Message msg) {
                this.failTimer.cancel();
 
-               logger.debug("Channel {} handling message in state {}", this.channel, this.state);
+               LOG.debug("Channel {} handling message in state {}", this.channel, this.state);
 
                switch (this.state) {
                case Finished:
@@ -215,7 +215,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                                } else {
                                        scheduleFailTimer();
                                        this.state = State.OpenWait;
-                                       logger.debug("Channel {} moved to OpenWait state with localOK=1", this.channel);
+                                       LOG.debug("Channel {} moved to OpenWait state with localOK=1", this.channel);
                                }
 
                                return;
@@ -251,7 +251,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                                        } else {
                                                scheduleFailTimer();
                                                this.state = State.KeepWait;
-                                               logger.debug("Channel {} moved to KeepWait state with remoteOK=1", this.channel);
+                                               LOG.debug("Channel {} moved to KeepWait state with remoteOK=1", this.channel);
                                        }
                                        return;
                                }
@@ -282,7 +282,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
                        break;
                }
 
-               logger.warn("Channel {} in state {} received unexpected message {}", this.channel, this.state, msg);
+               LOG.warn("Channel {} in state {} received unexpected message {}", this.channel, this.state, msg);
                sendErrorMessage(PCEPErrors.NON_OR_INVALID_OPEN_MSG);
                negotiationFailed(new Exception("Illegal message encountered"));
                this.state = State.Finished;
index cf221f62314989c49679647f89c0fb851a3b7296..24eccb3a908bd687d9ae1f32ce0ee264c2569a85 100644 (file)
@@ -40,8 +40,8 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public abstract class AbstractPCEPSessionNegotiatorFactory implements
                SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> {
-       private static final Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator();
-       private static final Logger logger = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class);
+       private static final Comparator<byte[]> COMPARATOR = UnsignedBytes.lexicographicalComparator();
+       private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class);
        private final BiMap<byte[], Closeable> sessions = HashBiMap.create();
        private final Map<byte[], Short> sessionIds = new WeakHashMap<>();
 
@@ -62,11 +62,11 @@ public abstract class AbstractPCEPSessionNegotiatorFactory implements
 
                final Object lock = this;
 
-               logger.debug("Instantiating bootstrap negotiator for channel {}", channel);
+               LOG.debug("Instantiating bootstrap negotiator for channel {}", channel);
                return new AbstractSessionNegotiator<Message, PCEPSessionImpl>(promise, channel) {
                        @Override
                        protected void startNegotiation() throws Exception {
-                               logger.debug("Bootstrap negotiation for channel {} started", this.channel);
+                               LOG.debug("Bootstrap negotiation for channel {} started", this.channel);
 
                                /*
                                 * We have a chance to see if there's a client session already
@@ -78,12 +78,12 @@ public abstract class AbstractPCEPSessionNegotiatorFactory implements
 
                                        if (AbstractPCEPSessionNegotiatorFactory.this.sessions.containsKey(clientAddress)) {
                                                final byte[] serverAddress = ((InetSocketAddress) this.channel.localAddress()).getAddress().getAddress();
-                                               if (comparator.compare(serverAddress, clientAddress) > 0) {
+                                               if (COMPARATOR.compare(serverAddress, clientAddress) > 0) {
                                                        final Closeable n = AbstractPCEPSessionNegotiatorFactory.this.sessions.remove(clientAddress);
                                                        try {
                                                                n.close();
                                                        } catch (final IOException e) {
-                                                               logger.warn("Unexpected failure to close old session", e);
+                                                               LOG.warn("Unexpected failure to close old session", e);
                                                        }
                                                } else {
                                                        negotiationFailed(new RuntimeException("A conflicting session for address "
@@ -111,7 +111,7 @@ public abstract class AbstractPCEPSessionNegotiatorFactory implements
                                                }
                                        });
 
-                                       logger.debug("Replacing bootstrap negotiator for channel {}", this.channel);
+                                       LOG.debug("Replacing bootstrap negotiator for channel {}", this.channel);
                                        this.channel.pipeline().replace(this, "negotiator", n);
                                        n.startNegotiation();
                                }
index 99ef153985f55eb1e54d89ca296cb31e9917104b..6a8f930a775eb7e46d82da13888f6154fc7bd19b 100644 (file)
@@ -29,11 +29,11 @@ import com.google.common.primitives.UnsignedBytes;
  * A PCEP message parser which also does validation.
  */
 public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder {
-       private final static Logger LOG = LoggerFactory.getLogger(PCEPByteToMessageDecoder.class);
+       private static final Logger LOG = LoggerFactory.getLogger(PCEPByteToMessageDecoder.class);
 
-       private final static int TYPE_SIZE = 1; // bytes
+       private static final int TYPE_SIZE = 1;
 
-       private final static int LENGTH_SIZE = 2; // bytes
+       private static final int LENGTH_SIZE = 2;
 
        private final MessageHandlerRegistry registry;
 
@@ -57,7 +57,7 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder {
 
                try {
                        out.add(parse(bytes, errors));
-               } catch (PCEPDeserializerException e) {
+               } catch (final PCEPDeserializerException e) {
                        LOG.debug("Failed to decode protocol message", e);
                        this.exceptionCaught(ctx, e);
                }
index 771004d9a8f8a3735f1db40f48de7fab22379497..fedd8ad01417d5857f4d72a43c43e0430f19bd5b 100644 (file)
@@ -27,7 +27,7 @@ import com.google.common.primitives.UnsignedBytes;
  */
 @Sharable
 public final class PCEPMessageToByteEncoder extends MessageToByteEncoder<Message> {
-       private static final Logger logger = LoggerFactory.getLogger(PCEPMessageToByteEncoder.class);
+       private static final Logger LOG = LoggerFactory.getLogger(PCEPMessageToByteEncoder.class);
        private static final int VERSION_SF_LENGTH = 3;
        private final MessageHandlerRegistry registry;
 
@@ -38,7 +38,7 @@ public final class PCEPMessageToByteEncoder extends MessageToByteEncoder<Message
        @Override
        protected void encode(final ChannelHandlerContext ctx, final Message msg, final ByteBuf out) throws Exception {
                Preconditions.checkNotNull(msg);
-               logger.debug("Sent to encode : {}", msg);
+               LOG.debug("Sent to encode : {}", msg);
 
                final ByteBuf body = Unpooled.buffer();
                final MessageSerializer serializer = this.registry.getMessageSerializer(msg);
index ccbd514522ec71be3c0ae54d062a8964f5bd5937..258ab21f3f4ce28328ce7258b0eb32aff4e38b23 100644 (file)
@@ -93,7 +93,7 @@ abstract class AbstractMessageParser implements MessageParser, MessageSerializer
                return retBytes;
        }
 
-       private final List<Object> parseObjects(final byte[] bytes) throws PCEPDeserializerException {
+       private List<Object> parseObjects(final byte[] bytes) throws PCEPDeserializerException {
                int offset = 0;
                final List<Object> objs = Lists.newArrayList();
                while (bytes.length - offset > 0) {
@@ -161,7 +161,7 @@ abstract class AbstractMessageParser implements MessageParser, MessageSerializer
                                                                                maping.getFromErrorsEnum(e).value).build()).build())).build()).build();
        }
 
-       abstract protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException;
+       protected abstract Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException;
 
        @Override
        public final Message parseMessage(final byte[] buffer, final List<Message> errors) throws PCEPDeserializerException {
index 2b6757f5eb1180cd9943d2b9d9fb7fcc53cb3056..86bcd6ab606922a6c186be02ce864098f039c390 100644 (file)
@@ -174,7 +174,7 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
                                        rBuilder.setRp(rpObj);
                                }
                        } else {
-                               // if RP obj is missing return error only;
+                               // if RP obj is missing return error only
                                errors.add(createErrorMsg(PCEPErrors.RP_MISSING));
                                return null;
                        }
index bc63b6e69b90fc59f0e26d5b528824c44957ca69..1a6d0118f688f1804dc6a34766825426259da971 100644 (file)
@@ -28,14 +28,14 @@ public abstract class AbstractPCEPExtensionProviderActivator implements PCEPExte
        protected abstract List<AutoCloseable> startImpl(PCEPExtensionProviderContext context);
 
        @Override
-       public synchronized final void start(final PCEPExtensionProviderContext context) {
+       public final synchronized void start(final PCEPExtensionProviderContext context) {
                Preconditions.checkState(this.registrations == null);
 
                this.registrations = Preconditions.checkNotNull(startImpl(context));
        }
 
        @Override
-       public synchronized final void stop() {
+       public final synchronized void stop() {
                Preconditions.checkState(this.registrations != null);
 
                for (final AutoCloseable r : this.registrations) {
index f08a295dffcb2313bda29a7e665b36c59ba771a3..30a62268dc26514b1b5cac14809fbccb57d4aacc 100644 (file)
@@ -20,7 +20,7 @@ import com.google.common.collect.Lists;
 
 public class TestingSessionListener implements PCEPSessionListener {
 
-       public List<Message> messages = Lists.newArrayList();
+       private final List<Message> messages = Lists.newArrayList();
 
        public boolean up = false;
 
@@ -51,4 +51,8 @@ public class TestingSessionListener implements PCEPSessionListener {
        public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
                logger.debug("Session terminated. Cause : {}", cause);
        }
+
+       public List<Message> messages() {
+               return this.messages;
+       }
 }
index c3421ffefdba1739e94a2c431bc2b4203813682c..997eb0de6d425503d1c5c28b867e53b1f3155a58 100644 (file)
@@ -21,10 +21,10 @@ public class PCEPTestingToolTest {
        @Test
        public void testSimpleSessionListener() {
                final TestingSessionListener ssl = new TestingSessionListener();
-               assertEquals(0, ssl.messages.size());
+               assertEquals(0, ssl.messages().size());
                ssl.onMessage(null, new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build());
-               assertEquals(1, ssl.messages.size());
-               assertTrue(ssl.messages.get(0) instanceof KeepaliveMessage);
+               assertEquals(1, ssl.messages().size());
+               assertTrue(ssl.messages().get(0) instanceof KeepaliveMessage);
                assertFalse(ssl.up);
                ssl.onSessionUp(null);
                assertTrue(ssl.up);
index bbf2a93d93fa100e7872e5a807f0cee329427c73..ee4a16142dbf59f727fafd9e513b6b7211dc57f1 100644 (file)
@@ -115,7 +115,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                private long requestId = 1;
                private NodeId nodeId;
 
-               final Node topologyNode(final DataModificationTransaction trans, final InetAddress address) {
+               Node topologyNode(final DataModificationTransaction trans, final InetAddress address) {
                        final String pccId = createNodeId(address);
                        final Topology topo = (Topology) trans.readOperationalData(ServerSessionManager.this.topology);
 
@@ -252,7 +252,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                public synchronized void onMessage(final PCEPSession session, final Message message) {
                        if (!(message instanceof PcrptMessage)) {
                                LOG.info("Unhandled message {} on session {}", message, session);
-                               session.sendMessage(unhandledMessageError);
+                               session.sendMessage(UNHANDLED_MESSAGE_ERROR);
                        }
 
                        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessage rpt = ((PcrptMessage) message).getPcrptMessage();
@@ -370,9 +370,9 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
        }
 
        private static final Logger LOG = LoggerFactory.getLogger(ServerSessionManager.class);
-       private static final Pcerr unhandledMessageError = new PcerrBuilder().setPcerrMessage(
+       private static final Pcerr UNHANDLED_MESSAGE_ERROR = new PcerrBuilder().setPcerrMessage(
                        new PcerrMessageBuilder().setErrorType(null).build()).build();
-       private static final MessageHeader messageHeader = new MessageHeader() {
+       private static final MessageHeader MESSAGE_HEADER = new MessageHeader() {
                private final ProtocolVersion version = new ProtocolVersion((short) 1);
 
                @Override
@@ -410,10 +410,9 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                                new TopologyBuilder().setKey(k).setTopologyId(k.getTopologyId()).setTopologyTypes(
                                                new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class,
                                                                new TopologyTypes1Builder().setTopologyPcep(new TopologyPcepBuilder().build()).build()).build()).setNode(
-                                                                               new ArrayList<Node>()).build());
+                                               new ArrayList<Node>()).build());
 
-               Futures.addCallback(JdkFutureAdapters.listenInPoolThread(t.commit()),
-                               new FutureCallback<RpcResult<TransactionStatus>>() {
+               Futures.addCallback(JdkFutureAdapters.listenInPoolThread(t.commit()), new FutureCallback<RpcResult<TransactionStatus>>() {
                        @Override
                        public void onSuccess(final RpcResult<TransactionStatus> result) {
                                // Nothing to do
@@ -453,7 +452,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                rb.setLsp(new LspBuilder().setAdministrative(input.getArguments().isAdministrative()).setDelegate(Boolean.TRUE).setTlvs(
                                new TlvsBuilder().setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(input.getName()).build()).build()).build());
 
-               final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(messageHeader);
+               final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
                ib.setRequests(ImmutableList.of(rb.build()));
 
                // Send the message
@@ -496,7 +495,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                rb.setSrp(new SrpBuilder().setOperationId(l.nextRequest()).setProcessingRule(Boolean.TRUE).setFlags(new Flags(Boolean.TRUE)).build());
                rb.setLsp(new LspBuilder().setRemove(Boolean.TRUE).setPlspId(rep.getLsp().getPlspId()).setDelegate(Boolean.TRUE).build());
 
-               final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(messageHeader);
+               final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
                ib.setRequests(ImmutableList.of(rb.build()));
                return l.sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), rb.getSrp().getOperationId());
        }
@@ -525,7 +524,7 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                final PathBuilder pb = new PathBuilder();
                rb.setPath(pb.setEro(input.getArguments().getEro()).build());
 
-               final PcupdMessageBuilder ub = new PcupdMessageBuilder(messageHeader);
+               final PcupdMessageBuilder ub = new PcupdMessageBuilder(MESSAGE_HEADER);
                ub.setUpdates(ImmutableList.of(rb.build()));
                return l.sendMessage(new PcupdBuilder().setPcupdMessage(ub.build()).build(), rb.getSrp().getOperationId());
        }
index 6eb88b018caf2cef0238b97583f6f5777c8f8411..195f6876f1800fa2453194bab6c16394b483fb62 100644 (file)
@@ -176,7 +176,7 @@ public final class TunnelProgramming implements TopologyTunnelPcepProgrammingSer
                return null;
        }
 
-       private NodeId supportingNode(final DataModificationTransaction t, final Node node) {
+       private NodeId supportingNode(final Node node) {
                for (final SupportingNode n : node.getSupportingNode()) {
                        final SupportingNode1 n1 = n.getAugmentation(SupportingNode1.class);
                        if (n1 != null && n1.getPathComputationClient().isControlling()) {
@@ -226,7 +226,7 @@ public final class TunnelProgramming implements TopologyTunnelPcepProgrammingSer
                                final TerminationPoint dp = Preconditions.checkNotNull(dr.getTp());
 
                                final AddLspInputBuilder ab = new AddLspInputBuilder();
-                               ab.setNode(Preconditions.checkNotNull(supportingNode(t, sn)));
+                               ab.setNode(Preconditions.checkNotNull(supportingNode(sn)));
                                ab.setName(Preconditions.checkNotNull(input.getSymbolicPathName()));
 
                                // The link has to be non-existent
@@ -333,7 +333,7 @@ public final class TunnelProgramming implements TopologyTunnelPcepProgrammingSer
 
                                final UpdateLspInputBuilder ab = new UpdateLspInputBuilder();
                                ab.setName(link.getAugmentation(Link1.class).getSymbolicPathName());
-                               ab.setNode(Preconditions.checkNotNull(supportingNode(t, node)));
+                               ab.setNode(Preconditions.checkNotNull(supportingNode(node)));
 
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder args = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();