From: Dana Kutenicsova Date: Wed, 4 Dec 2013 12:35:16 +0000 (+0100) Subject: Removed some sonar warnings from pcep. X-Git-Tag: jenkins-bgpcep-bulk-release-prepare-only-1~124^2~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7916d241b3ba1e58495cb63f860a85819e821360;p=bgpcep.git Removed some sonar warnings from pcep. Change-Id: I669cc2821455423424afa23497340cf95de4aed3 Signed-off-by: Dana Kutenicsova --- diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTerminationReason.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTerminationReason.java index 3b263b8a02..ea4cd34777 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTerminationReason.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTerminationReason.java @@ -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); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java index 28d011fe15..50e1112d0d 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java @@ -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; diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java index cf221f6231..24eccb3a90 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiatorFactory.java @@ -40,8 +40,8 @@ import com.google.common.primitives.UnsignedBytes; */ public abstract class AbstractPCEPSessionNegotiatorFactory implements SessionNegotiatorFactory { - private static final Comparator comparator = UnsignedBytes.lexicographicalComparator(); - private static final Logger logger = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class); + private static final Comparator COMPARATOR = UnsignedBytes.lexicographicalComparator(); + private static final Logger LOG = LoggerFactory.getLogger(AbstractPCEPSessionNegotiatorFactory.class); private final BiMap sessions = HashBiMap.create(); private final Map 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(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(); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java index 99ef153985..6a8f930a77 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java @@ -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); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java index 771004d9a8..fedd8ad014 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java @@ -27,7 +27,7 @@ import com.google.common.primitives.UnsignedBytes; */ @Sharable public final class PCEPMessageToByteEncoder extends MessageToByteEncoder { - 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 parseObjects(final byte[] bytes) throws PCEPDeserializerException { + private List parseObjects(final byte[] bytes) throws PCEPDeserializerException { int offset = 0; final List 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 objects, final List errors) throws PCEPDeserializerException; + protected abstract Message validate(final List objects, final List errors) throws PCEPDeserializerException; @Override public final Message parseMessage(final byte[] buffer, final List errors) throws PCEPDeserializerException { diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java index 2b6757f5eb..86bcd6ab60 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java @@ -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; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java index bc63b6e69b..1a6d0118f6 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/AbstractPCEPExtensionProviderActivator.java @@ -28,14 +28,14 @@ public abstract class AbstractPCEPExtensionProviderActivator implements PCEPExte protected abstract List 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) { diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java index f08a295dff..30a62268dc 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java @@ -20,7 +20,7 @@ import com.google.common.collect.Lists; public class TestingSessionListener implements PCEPSessionListener { - public List messages = Lists.newArrayList(); + private final List 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 messages() { + return this.messages; + } } diff --git a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java index c3421ffefd..997eb0de6d 100644 --- a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java +++ b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java @@ -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); diff --git a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java index bbf2a93d93..ee4a16142d 100644 --- a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java +++ b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java @@ -115,7 +115,7 @@ final class ServerSessionManager implements SessionListenerFactory()).build()); + new ArrayList()).build()); - Futures.addCallback(JdkFutureAdapters.listenInPoolThread(t.commit()), - new FutureCallback>() { + Futures.addCallback(JdkFutureAdapters.listenInPoolThread(t.commit()), new FutureCallback>() { @Override public void onSuccess(final RpcResult result) { // Nothing to do @@ -453,7 +452,7 @@ final class ServerSessionManager implements SessionListenerFactory