X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fcore%2FOFEncoder.java;h=4c54732bda6ed0b91274dc56858d921bae13620e;hb=22d96bf79e25f975b81cd8e95f1ec61378118976;hp=075b99da2bb30bddaca8c1fc4707cdd18d44b1eb;hpb=521335a2a2c5c95a4213dc78bbbde74042a87f78;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java index 075b99da..4c54732b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoder.java @@ -12,7 +12,6 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import io.netty.util.concurrent.Future; - import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper; import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; import org.opendaylight.openflowjava.statistics.CounterEventTypes; @@ -28,31 +27,33 @@ import org.slf4j.LoggerFactory; */ public class OFEncoder extends MessageToByteEncoder { - private static final Logger LOGGER = LoggerFactory.getLogger(OFEncoder.class); + private static final Logger LOG = LoggerFactory.getLogger(OFEncoder.class); private SerializationFactory serializationFactory; - private StatisticsCounters statisticsCounters; + private final StatisticsCounters statisticsCounters; /** Constructor of class */ public OFEncoder() { statisticsCounters = StatisticsCounters.getInstance(); - LOGGER.trace("Creating OF13Encoder"); + LOG.trace("Creating OF13Encoder"); } @Override - protected void encode(ChannelHandlerContext ctx, MessageListenerWrapper wrapper, ByteBuf out) + protected void encode(final ChannelHandlerContext ctx, final MessageListenerWrapper wrapper, final ByteBuf out) throws Exception { - LOGGER.trace("Encoding"); + LOG.trace("Encoding"); try { serializationFactory.messageToBuffer(wrapper.getMsg().getVersion(), out, wrapper.getMsg()); if(wrapper.getMsg() instanceof FlowModInput){ statisticsCounters.incrementCounter(CounterEventTypes.DS_FLOW_MODS_SENT); } statisticsCounters.incrementCounter(CounterEventTypes.DS_ENCODE_SUCCESS); - } catch(Exception e) { - LOGGER.warn("Message serialization failed ", e); + } catch(final Exception e) { + LOG.warn("Message serialization failed ", e); statisticsCounters.incrementCounter(CounterEventTypes.DS_ENCODE_FAIL); - Future newFailedFuture = ctx.newFailedFuture(e); - wrapper.getListener().operationComplete(newFailedFuture); + if (wrapper.getListener() != null) { + final Future newFailedFuture = ctx.newFailedFuture(e); + wrapper.getListener().operationComplete(newFailedFuture); + } out.clear(); return; } @@ -61,7 +62,7 @@ public class OFEncoder extends MessageToByteEncoder { /** * @param serializationFactory */ - public void setSerializationFactory(SerializationFactory serializationFactory) { + public void setSerializationFactory(final SerializationFactory serializationFactory) { this.serializationFactory = serializationFactory; }