Fix a few deprecation warnings in framework 04/3904/1
authorRobert Varga <rovarga@cisco.com>
Mon, 23 Dec 2013 07:33:14 +0000 (08:33 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 23 Dec 2013 07:46:39 +0000 (08:46 +0100)
Change-Id: I8eacfe7e84b2322d6daf8d0838fcb69ec391a050
Signed-off-by: Robert Varga <rovarga@cisco.com>
framework/src/test/java/org/opendaylight/protocol/framework/ComplementaryTest.java
framework/src/test/java/org/opendaylight/protocol/framework/MessageFactory.java [deleted file]
framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java
framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java [new file with mode: 0644]
framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java
framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java [new file with mode: 0644]

index 82cc18c6b18693cab6b0ec8d0cacef00264de6e9..ad47adb0b42d5fabe18c6955ee17483695e132ee 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
 
+@Deprecated
 public class ComplementaryTest {
 
        @Test
diff --git a/framework/src/test/java/org/opendaylight/protocol/framework/MessageFactory.java b/framework/src/test/java/org/opendaylight/protocol/framework/MessageFactory.java
deleted file mode 100644 (file)
index be188dd..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.protocol.framework;
-
-import java.nio.ByteBuffer;
-
-import com.google.common.base.Charsets;
-
-public class MessageFactory implements ProtocolMessageFactory<SimpleMessage> {
-
-       @Override
-       public SimpleMessage parse(final byte[] bytes) throws DeserializerException, DocumentedException {
-               return new SimpleMessage(Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString());
-       }
-
-       @Override
-       public byte[] put(final SimpleMessage msg) {
-               return msg.getMessage().getBytes();
-       }
-}
index 1570b969c0217866141ebbc3645054a3cfe3c858..cb6c93e224a225c33183c105a25486e976da0d73 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.framework;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -14,9 +16,6 @@ import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -24,8 +23,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 
 public class ServerTest {
        SimpleDispatcher clientDispatcher, dispatcher;
@@ -59,7 +59,7 @@ public class ServerTest {
                                p.setSuccess(true);
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
+               }, new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.server = this.dispatcher.createServer(this.serverAddress, new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
@@ -76,9 +76,9 @@ public class ServerTest {
                                        final Channel channel, final Promise<SimpleSession> promise) {
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
+               }, new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
-               this.session = (SimpleSession) this.clientDispatcher.createClient(this.serverAddress,
+               this.session = this.clientDispatcher.createClient(this.serverAddress,
                                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
                        public SimpleSessionListener getSessionListener() {
@@ -101,7 +101,7 @@ public class ServerTest {
                                p.setSuccess(true);
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
+               }, new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.server = this.dispatcher.createServer(this.serverAddress, new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
@@ -118,9 +118,9 @@ public class ServerTest {
                                        final Channel channel, final Promise<SimpleSession> promise) {
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
+               }, new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
-               this.session = (SimpleSession) this.clientDispatcher.createClient(this.serverAddress,
+               this.session = this.clientDispatcher.createClient(this.serverAddress,
                                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
                        public SimpleSessionListener getSessionListener() {
diff --git a/framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java b/framework/src/test/java/org/opendaylight/protocol/framework/SimpleByteToMessageDecoder.java
new file mode 100644 (file)
index 0000000..59452d7
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.protocol.framework;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
+
+import java.util.List;
+
+import com.google.common.base.Charsets;
+
+/**
+ *
+ */
+public class SimpleByteToMessageDecoder extends ByteToMessageDecoder {
+       @Override
+       protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) {
+               out.add(new SimpleMessage(Charsets.UTF_8.decode(in.nioBuffer()).toString()));
+       }
+}
index 11e6bfbe1d5e3a1c0b8b1f6daae3beb8ee0142bf..33723c62c56112eb7dfef743e9f4f2fe9159242d 100644 (file)
@@ -1,23 +1,24 @@
 package org.opendaylight.protocol.framework;
 
-import com.google.common.base.Preconditions;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOutboundHandler;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.Promise;
+
+import java.net.InetSocketAddress;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.net.InetSocketAddress;
+import com.google.common.base.Preconditions;
 
 public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSessionListener> {
-
        private static final Logger logger = LoggerFactory.getLogger(SimpleDispatcher.class);
 
        private final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory;
-       private final ProtocolHandlerFactory<?> factory;
-
+       private final ChannelOutboundHandler encoder = new SimpleMessageToByteEncoder();
 
        private final class SimplePipelineInitializer implements PipelineInitializer<SimpleSession> {
                final SessionListenerFactory<SimpleSessionListener> listenerFactory;
@@ -28,19 +29,18 @@ public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSe
 
                @Override
                public void initializeChannel(final SocketChannel channel, final Promise<SimpleSession> promise) {
-                       channel.pipeline().addLast(factory.getDecoders());
+                       channel.pipeline().addLast(new SimpleByteToMessageDecoder());
                        channel.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise));
-                       channel.pipeline().addLast(factory.getEncoders());
+                       channel.pipeline().addLast(encoder);
                        logger.debug("initialization completed for channel {}", channel);
                }
 
        }
 
-       public SimpleDispatcher(final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
-                       final Promise<SimpleSession> promise, EventLoopGroup eventLoopGroup) {
+       public SimpleDispatcher(final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory,
+                       final Promise<SimpleSession> promise, final EventLoopGroup eventLoopGroup) {
                super(eventLoopGroup, eventLoopGroup);
                this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
-               this.factory = Preconditions.checkNotNull(factory);
        }
 
        public Future<SimpleSession> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
@@ -51,7 +51,7 @@ public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSe
                return super.createServer(address, new SimplePipelineInitializer(listenerFactory));
        }
 
-    @Override
-    public void close() {
-    }
+       @Override
+       public void close() {
+       }
 }
diff --git a/framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java b/framework/src/test/java/org/opendaylight/protocol/framework/SimpleMessageToByteEncoder.java
new file mode 100644 (file)
index 0000000..5b7ee50
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.protocol.framework;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToByteEncoder;
+
+/**
+ *
+ */
+@Sharable
+public class SimpleMessageToByteEncoder extends MessageToByteEncoder<SimpleMessage> {
+       @Override
+       protected void encode(final ChannelHandlerContext ctx, final SimpleMessage msg, final ByteBuf out) {
+               out.writeBytes(msg.getMessage().getBytes());
+       }
+}