Madan Jampani

Moved Netty messaging out of onos-core-dist to under onos-utils

Showing 21 changed files with 79 additions and 63 deletions
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
33 <artifactId>onlab-nio</artifactId> 33 <artifactId>onlab-nio</artifactId>
34 <version>${project.version}</version> 34 <version>${project.version}</version>
35 </dependency> 35 </dependency>
36 +
37 + <dependency>
38 + <groupId>org.onlab.onos</groupId>
39 + <artifactId>onlab-netty</artifactId>
40 + <version>${project.version}</version>
41 + </dependency>
36 42
37 <dependency> 43 <dependency>
38 <groupId>com.fasterxml.jackson.core</groupId> 44 <groupId>com.fasterxml.jackson.core</groupId>
...@@ -51,15 +57,6 @@ ...@@ -51,15 +57,6 @@
51 <groupId>de.javakaffee</groupId> 57 <groupId>de.javakaffee</groupId>
52 <artifactId>kryo-serializers</artifactId> 58 <artifactId>kryo-serializers</artifactId>
53 </dependency> 59 </dependency>
54 - <dependency>
55 - <groupId>io.netty</groupId>
56 - <artifactId>netty-all</artifactId>
57 - </dependency>
58 - <dependency>
59 - <groupId>commons-pool</groupId>
60 - <artifactId>commons-pool</artifactId>
61 - <version>1.6</version>
62 - </dependency>
63 </dependencies> 60 </dependencies>
64 61
65 <build> 62 <build>
......
...@@ -23,10 +23,10 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; ...@@ -23,10 +23,10 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
23 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 23 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
24 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; 24 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
25 import org.onlab.onos.store.cluster.messaging.MessageSubject; 25 import org.onlab.onos.store.cluster.messaging.MessageSubject;
26 -import org.onlab.onos.store.messaging.Endpoint; 26 +import org.onlab.netty.Endpoint;
27 -import org.onlab.onos.store.messaging.Message; 27 +import org.onlab.netty.Message;
28 -import org.onlab.onos.store.messaging.MessageHandler; 28 +import org.onlab.netty.MessageHandler;
29 -import org.onlab.onos.store.messaging.MessagingService; 29 +import org.onlab.netty.MessagingService;
30 import org.slf4j.Logger; 30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory; 31 import org.slf4j.LoggerFactory;
32 32
......
...@@ -7,7 +7,7 @@ import org.junit.Test; ...@@ -7,7 +7,7 @@ import org.junit.Test;
7 import org.onlab.onos.cluster.DefaultControllerNode; 7 import org.onlab.onos.cluster.DefaultControllerNode;
8 import org.onlab.onos.cluster.NodeId; 8 import org.onlab.onos.cluster.NodeId;
9 import org.onlab.onos.store.cluster.messaging.impl.OnosClusterCommunicationManager; 9 import org.onlab.onos.store.cluster.messaging.impl.OnosClusterCommunicationManager;
10 -import org.onlab.onos.store.messaging.impl.NettyMessagingService; 10 +import org.onlab.netty.NettyMessagingService;
11 import org.onlab.packet.IpPrefix; 11 import org.onlab.packet.IpPrefix;
12 12
13 import java.util.concurrent.CountDownLatch; 13 import java.util.concurrent.CountDownLatch;
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 + <modelVersion>4.0.0</modelVersion>
6 +
7 + <parent>
8 + <groupId>org.onlab.onos</groupId>
9 + <artifactId>onlab-utils</artifactId>
10 + <version>1.0.0-SNAPSHOT</version>
11 + <relativePath>../pom.xml</relativePath>
12 + </parent>
13 +
14 + <artifactId>onlab-netty</artifactId>
15 + <packaging>bundle</packaging>
16 +
17 + <description>Network I/O using Netty framework</description>
18 +
19 + <dependencies>
20 + <dependency>
21 + <groupId>com.google.guava</groupId>
22 + <artifactId>guava-testlib</artifactId>
23 + <scope>test</scope>
24 + </dependency>
25 + <dependency>
26 + <groupId>org.onlab.onos</groupId>
27 + <artifactId>onlab-misc</artifactId>
28 + </dependency>
29 + <dependency>
30 + <groupId>org.onlab.onos</groupId>
31 + <artifactId>onlab-junit</artifactId>
32 + <scope>test</scope>
33 + </dependency>
34 + <dependency>
35 + <groupId>de.javakaffee</groupId>
36 + <artifactId>kryo-serializers</artifactId>
37 + </dependency>
38 + <dependency>
39 + <groupId>io.netty</groupId>
40 + <artifactId>netty-all</artifactId>
41 + </dependency>
42 + <dependency>
43 + <groupId>commons-pool</groupId>
44 + <artifactId>commons-pool</artifactId>
45 + <version>1.6</version>
46 + </dependency>
47 + </dependencies>
48 +
49 +</project>
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.util.concurrent.TimeUnit; 3 import java.util.concurrent.TimeUnit;
4 import java.util.concurrent.TimeoutException; 4 import java.util.concurrent.TimeoutException;
5 5
6 -import org.onlab.onos.store.messaging.Response;
7 -
8 /** 6 /**
9 * An asynchronous response. 7 * An asynchronous response.
10 * This class provides a base implementation of Response, with methods to retrieve the 8 * This class provides a base implementation of Response, with methods to retrieve the
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
5 -import org.onlab.onos.store.messaging.Message;
6 -import org.onlab.onos.store.messaging.MessageHandler;
7 -
8 /** 5 /**
9 * Message handler that echos the message back to the sender. 6 * Message handler that echos the message back to the sender.
10 */ 7 */
......
1 -package org.onlab.onos.store.messaging; 1 +package org.onlab.netty;
2 2
3 /** 3 /**
4 * Representation of a TCP/UDP communication end point. 4 * Representation of a TCP/UDP communication end point.
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
5 -import org.onlab.onos.store.messaging.Endpoint;
6 -import org.onlab.onos.store.messaging.Message;
7 -
8 /** 5 /**
9 * Internal message representation with additional attributes 6 * Internal message representation with additional attributes
10 * for supporting, synchronous request/reply behavior. 7 * for supporting, synchronous request/reply behavior.
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import org.onlab.util.KryoPool; 3 import org.onlab.util.KryoPool;
4 import org.slf4j.Logger; 4 import org.slf4j.Logger;
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 -
3 -import org.onlab.onos.store.messaging.Message;
4 -import org.onlab.onos.store.messaging.MessageHandler;
5 2
6 /** 3 /**
7 * A MessageHandler that simply logs the information. 4 * A MessageHandler that simply logs the information.
...@@ -12,4 +9,4 @@ public class LoggingHandler implements MessageHandler { ...@@ -12,4 +9,4 @@ public class LoggingHandler implements MessageHandler {
12 public void handle(Message message) { 9 public void handle(Message message) {
13 System.out.println("Received: " + message.payload()); 10 System.out.println("Received: " + message.payload());
14 } 11 }
15 -}
...\ No newline at end of file ...\ No newline at end of file
12 +}
......
1 -package org.onlab.onos.store.messaging; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.util.Arrays; 3 import java.util.Arrays;
4 import java.util.List; 4 import java.util.List;
5 5
6 import static com.google.common.base.Preconditions.checkState; 6 import static com.google.common.base.Preconditions.checkState;
7 7
8 -import org.onlab.onos.store.messaging.Endpoint;
9 -
10 import io.netty.buffer.ByteBuf; 8 import io.netty.buffer.ByteBuf;
11 import io.netty.channel.ChannelHandlerContext; 9 import io.netty.channel.ChannelHandlerContext;
12 import io.netty.handler.codec.ByteToMessageDecoder; 10 import io.netty.handler.codec.ByteToMessageDecoder;
13 11
14 /** 12 /**
15 - * Decode bytes into a InrenalMessage. 13 + * Decode bytes into a InternalMessage.
16 */ 14 */
17 public class MessageDecoder extends ByteToMessageDecoder { 15 public class MessageDecoder extends ByteToMessageDecoder {
18 16
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import io.netty.buffer.ByteBuf; 3 import io.netty.buffer.ByteBuf;
4 import io.netty.channel.ChannelHandlerContext; 4 import io.netty.channel.ChannelHandlerContext;
......
1 -package org.onlab.onos.store.messaging; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
......
1 -package org.onlab.onos.store.messaging; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.net.UnknownHostException; 4 import java.net.UnknownHostException;
...@@ -25,16 +25,6 @@ import org.apache.commons.lang.math.RandomUtils; ...@@ -25,16 +25,6 @@ import org.apache.commons.lang.math.RandomUtils;
25 import org.apache.commons.pool.KeyedObjectPool; 25 import org.apache.commons.pool.KeyedObjectPool;
26 import org.apache.commons.pool.KeyedPoolableObjectFactory; 26 import org.apache.commons.pool.KeyedPoolableObjectFactory;
27 import org.apache.commons.pool.impl.GenericKeyedObjectPool; 27 import org.apache.commons.pool.impl.GenericKeyedObjectPool;
28 -import org.apache.felix.scr.annotations.Activate;
29 -import org.apache.felix.scr.annotations.Component;
30 -import org.apache.felix.scr.annotations.Deactivate;
31 -import org.apache.felix.scr.annotations.Reference;
32 -import org.apache.felix.scr.annotations.ReferenceCardinality;
33 -import org.apache.felix.scr.annotations.Service;
34 -import org.onlab.onos.store.messaging.Endpoint;
35 -import org.onlab.onos.store.messaging.MessageHandler;
36 -import org.onlab.onos.store.messaging.MessagingService;
37 -import org.onlab.onos.store.messaging.Response;
38 import org.slf4j.Logger; 28 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory; 29 import org.slf4j.LoggerFactory;
40 30
...@@ -44,8 +34,6 @@ import com.google.common.cache.CacheBuilder; ...@@ -44,8 +34,6 @@ import com.google.common.cache.CacheBuilder;
44 /** 34 /**
45 * A Netty based implementation of MessagingService. 35 * A Netty based implementation of MessagingService.
46 */ 36 */
47 -@Component(immediate = true)
48 -@Service
49 public class NettyMessagingService implements MessagingService { 37 public class NettyMessagingService implements MessagingService {
50 38
51 private final Logger log = LoggerFactory.getLogger(getClass()); 39 private final Logger log = LoggerFactory.getLogger(getClass());
...@@ -59,7 +47,6 @@ public class NettyMessagingService implements MessagingService { ...@@ -59,7 +47,6 @@ public class NettyMessagingService implements MessagingService {
59 private Cache<Long, AsyncResponse<?>> responseFutures; 47 private Cache<Long, AsyncResponse<?>> responseFutures;
60 private final Endpoint localEp; 48 private final Endpoint localEp;
61 49
62 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected Serializer serializer; 50 protected Serializer serializer;
64 51
65 public NettyMessagingService() { 52 public NettyMessagingService() {
...@@ -78,7 +65,6 @@ public class NettyMessagingService implements MessagingService { ...@@ -78,7 +65,6 @@ public class NettyMessagingService implements MessagingService {
78 } 65 }
79 } 66 }
80 67
81 - @Activate
82 public void activate() throws Exception { 68 public void activate() throws Exception {
83 responseFutures = CacheBuilder.newBuilder() 69 responseFutures = CacheBuilder.newBuilder()
84 .maximumSize(100000) 70 .maximumSize(100000)
...@@ -89,7 +75,6 @@ public class NettyMessagingService implements MessagingService { ...@@ -89,7 +75,6 @@ public class NettyMessagingService implements MessagingService {
89 startAcceptingConnections(); 75 startAcceptingConnections();
90 } 76 }
91 77
92 - @Deactivate
93 public void deactivate() throws Exception { 78 public void deactivate() throws Exception {
94 channels.close(); 79 channels.close();
95 bossGroup.shutdownGracefully(); 80 bossGroup.shutdownGracefully();
......
1 -package org.onlab.onos.store.messaging; 1 +package org.onlab.netty;
2 2
3 import java.util.concurrent.TimeUnit; 3 import java.util.concurrent.TimeUnit;
4 import java.util.concurrent.TimeoutException; 4 import java.util.concurrent.TimeoutException;
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 /** 3 /**
4 * Interface for encoding/decoding message payloads. 4 * Interface for encoding/decoding message payloads.
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 import java.util.concurrent.TimeUnit; 3 import java.util.concurrent.TimeUnit;
4 4
5 -import org.onlab.onos.store.messaging.Endpoint;
6 -import org.onlab.onos.store.messaging.Response;
7 -
8 public final class SimpleClient { 5 public final class SimpleClient {
9 private SimpleClient() {} 6 private SimpleClient() {}
10 7
......
1 -package org.onlab.onos.store.messaging.impl; 1 +package org.onlab.netty;
2 2
3 public final class SimpleServer { 3 public final class SimpleServer {
4 private SimpleServer() {} 4 private SimpleServer() {}
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 <modules> 19 <modules>
20 <module>junit</module> 20 <module>junit</module>
21 <module>misc</module> 21 <module>misc</module>
22 + <module>netty</module>
22 <module>nio</module> 23 <module>nio</module>
23 <module>osgi</module> 24 <module>osgi</module>
24 <module>rest</module> 25 <module>rest</module>
......