import org.junit.Test;
+@Deprecated
public class ComplementaryTest {
@Test
+++ /dev/null
-/*
- * 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();
- }
-}
*/
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;
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;
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;
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
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() {
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
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() {
--- /dev/null
+/*
+ * 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()));
+ }
+}
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;
@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) {
return super.createServer(address, new SimplePipelineInitializer(listenerFactory));
}
- @Override
- public void close() {
- }
+ @Override
+ public void close() {
+ }
}
--- /dev/null
+/*
+ * 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());
+ }
+}