Committed by
Gerrit Code Review
Migrating netty messaging into netty messaging manager.
Change-Id: I971db195c9dc155cdf76850f0427ef9b9210113c
Showing
10 changed files
with
82 additions
and
143 deletions
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onlab.netty; | 16 | +package org.onosproject.store.cluster.messaging.impl; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * State transitions a decoder goes through as it is decoding an incoming message. | 19 | * State transitions a decoder goes through as it is decoding an incoming message. | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,13 +13,12 @@ | ... | @@ -13,13 +13,12 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onlab.netty; | 16 | +package org.onosproject.store.cluster.messaging.impl; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
18 | import org.onlab.util.ByteArraySizeHashPrinter; | 19 | import org.onlab.util.ByteArraySizeHashPrinter; |
19 | import org.onosproject.store.cluster.messaging.Endpoint; | 20 | import org.onosproject.store.cluster.messaging.Endpoint; |
20 | 21 | ||
21 | -import com.google.common.base.MoreObjects; | ||
22 | - | ||
23 | /** | 22 | /** |
24 | * Internal message representation with additional attributes | 23 | * Internal message representation with additional attributes |
25 | * for supporting, synchronous request/reply behavior. | 24 | * for supporting, synchronous request/reply behavior. | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,21 +13,19 @@ | ... | @@ -13,21 +13,19 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onlab.netty; | 16 | +package org.onosproject.store.cluster.messaging.impl; |
17 | 17 | ||
18 | +import com.google.common.base.Charsets; | ||
18 | import io.netty.buffer.ByteBuf; | 19 | import io.netty.buffer.ByteBuf; |
19 | import io.netty.channel.ChannelHandlerContext; | 20 | import io.netty.channel.ChannelHandlerContext; |
20 | import io.netty.handler.codec.ReplayingDecoder; | 21 | import io.netty.handler.codec.ReplayingDecoder; |
21 | - | ||
22 | -import java.util.List; | ||
23 | - | ||
24 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
25 | import org.onlab.packet.IpAddress.Version; | 23 | import org.onlab.packet.IpAddress.Version; |
26 | import org.onosproject.store.cluster.messaging.Endpoint; | 24 | import org.onosproject.store.cluster.messaging.Endpoint; |
27 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
28 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
29 | 27 | ||
30 | -import com.google.common.base.Charsets; | 28 | +import java.util.List; |
31 | 29 | ||
32 | import static com.google.common.base.Preconditions.checkState; | 30 | import static com.google.common.base.Preconditions.checkState; |
33 | 31 | ||
... | @@ -54,7 +52,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { | ... | @@ -54,7 +52,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { |
54 | } | 52 | } |
55 | 53 | ||
56 | @Override | 54 | @Override |
57 | - @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning | 55 | + @SuppressWarnings("squid:S128") // suppress switch fall through warning |
58 | protected void decode( | 56 | protected void decode( |
59 | ChannelHandlerContext context, | 57 | ChannelHandlerContext context, |
60 | ByteBuf buffer, | 58 | ByteBuf buffer, |
... | @@ -97,9 +95,9 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { | ... | @@ -97,9 +95,9 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { |
97 | byte[] payload = new byte[contentLength]; | 95 | byte[] payload = new byte[contentLength]; |
98 | buffer.readBytes(payload); | 96 | buffer.readBytes(payload); |
99 | InternalMessage message = new InternalMessage(messageId, | 97 | InternalMessage message = new InternalMessage(messageId, |
100 | - new Endpoint(senderIp, senderPort), | 98 | + new Endpoint(senderIp, senderPort), |
101 | - messageType, | 99 | + messageType, |
102 | - payload); | 100 | + payload); |
103 | out.add(message); | 101 | out.add(message); |
104 | checkpoint(DecoderState.READ_MESSAGE_PREAMBLE); | 102 | checkpoint(DecoderState.READ_MESSAGE_PREAMBLE); |
105 | break; | 103 | break; | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,22 +13,20 @@ | ... | @@ -13,22 +13,20 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onlab.netty; | 16 | +package org.onosproject.store.cluster.messaging.impl; |
17 | 17 | ||
18 | +import com.google.common.base.Charsets; | ||
18 | import io.netty.buffer.ByteBuf; | 19 | import io.netty.buffer.ByteBuf; |
19 | import io.netty.channel.ChannelHandler.Sharable; | 20 | import io.netty.channel.ChannelHandler.Sharable; |
20 | import io.netty.channel.ChannelHandlerContext; | 21 | import io.netty.channel.ChannelHandlerContext; |
21 | import io.netty.handler.codec.MessageToByteEncoder; | 22 | import io.netty.handler.codec.MessageToByteEncoder; |
22 | - | ||
23 | -import java.io.IOException; | ||
24 | - | ||
25 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
26 | import org.onlab.packet.IpAddress.Version; | 24 | import org.onlab.packet.IpAddress.Version; |
27 | import org.onosproject.store.cluster.messaging.Endpoint; | 25 | import org.onosproject.store.cluster.messaging.Endpoint; |
28 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
29 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
30 | 28 | ||
31 | -import com.google.common.base.Charsets; | 29 | +import java.io.IOException; |
32 | 30 | ||
33 | /** | 31 | /** |
34 | * Encode InternalMessage out into a byte buffer. | 32 | * Encode InternalMessage out into a byte buffer. | ... | ... |
This diff is collapsed. Click to expand it.
1 | -package org.onlab.netty; | 1 | +package org.onosproject.store.cluster.messaging.impl; |
2 | 2 | ||
3 | import java.util.Arrays; | 3 | import java.util.Arrays; |
4 | import java.util.concurrent.CompletableFuture; | 4 | import java.util.concurrent.CompletableFuture; |
... | @@ -9,10 +9,17 @@ import java.util.concurrent.atomic.AtomicBoolean; | ... | @@ -9,10 +9,17 @@ import java.util.concurrent.atomic.AtomicBoolean; |
9 | import java.util.concurrent.atomic.AtomicReference; | 9 | import java.util.concurrent.atomic.AtomicReference; |
10 | import java.util.function.BiFunction; | 10 | import java.util.function.BiFunction; |
11 | 11 | ||
12 | +import com.google.common.collect.Sets; | ||
12 | import org.junit.After; | 13 | import org.junit.After; |
13 | import org.junit.Before; | 14 | import org.junit.Before; |
14 | import org.junit.Test; | 15 | import org.junit.Test; |
15 | import org.onlab.packet.IpAddress; | 16 | import org.onlab.packet.IpAddress; |
17 | +import org.onosproject.cluster.ClusterMetadata; | ||
18 | +import org.onosproject.cluster.ClusterMetadataEventListener; | ||
19 | +import org.onosproject.cluster.ClusterMetadataService; | ||
20 | +import org.onosproject.cluster.ControllerNode; | ||
21 | +import org.onosproject.cluster.NodeId; | ||
22 | +import org.onosproject.net.provider.ProviderId; | ||
16 | import org.onosproject.store.cluster.messaging.Endpoint; | 23 | import org.onosproject.store.cluster.messaging.Endpoint; |
17 | 24 | ||
18 | import com.google.common.util.concurrent.MoreExecutors; | 25 | import com.google.common.util.concurrent.MoreExecutors; |
... | @@ -24,34 +31,39 @@ import static org.onlab.junit.TestTools.findAvailablePort; | ... | @@ -24,34 +31,39 @@ import static org.onlab.junit.TestTools.findAvailablePort; |
24 | /** | 31 | /** |
25 | * Unit tests for NettyMessaging. | 32 | * Unit tests for NettyMessaging. |
26 | */ | 33 | */ |
27 | -public class NettyMessagingTest { | 34 | +public class NettyMessagingManagerTest { |
28 | 35 | ||
29 | - NettyMessaging netty1; | 36 | + NettyMessagingManager netty1; |
30 | - NettyMessaging netty2; | 37 | + NettyMessagingManager netty2; |
31 | 38 | ||
32 | - Endpoint ep1 = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5001); | 39 | + private static final String DUMMY_NAME = "node"; |
33 | - Endpoint ep2 = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5002); | 40 | + private static final String IP_STRING = "127.0.0.1"; |
34 | - Endpoint invalidEndPoint = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5003); | 41 | + |
42 | + Endpoint ep1 = new Endpoint(IpAddress.valueOf(IP_STRING), 5001); | ||
43 | + Endpoint ep2 = new Endpoint(IpAddress.valueOf(IP_STRING), 5002); | ||
44 | + Endpoint invalidEndPoint = new Endpoint(IpAddress.valueOf(IP_STRING), 5003); | ||
35 | 45 | ||
36 | @Before | 46 | @Before |
37 | public void setUp() throws Exception { | 47 | public void setUp() throws Exception { |
38 | ep1 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5001)); | 48 | ep1 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5001)); |
39 | - netty1 = new NettyMessaging(); | 49 | + netty1 = new NettyMessagingManager(); |
40 | - netty1.start(12, ep1); | 50 | + netty1.clusterMetadataService = dummyMetadataService(DUMMY_NAME, IP_STRING, ep1); |
51 | + netty1.activate(); | ||
41 | 52 | ||
42 | ep2 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5003)); | 53 | ep2 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5003)); |
43 | - netty2 = new NettyMessaging(); | 54 | + netty2 = new NettyMessagingManager(); |
44 | - netty2.start(12, ep2); | 55 | + netty2.clusterMetadataService = dummyMetadataService(DUMMY_NAME, IP_STRING, ep2); |
56 | + netty2.activate(); | ||
45 | } | 57 | } |
46 | 58 | ||
47 | @After | 59 | @After |
48 | public void tearDown() throws Exception { | 60 | public void tearDown() throws Exception { |
49 | if (netty1 != null) { | 61 | if (netty1 != null) { |
50 | - netty1.stop(); | 62 | + netty1.deactivate(); |
51 | } | 63 | } |
52 | 64 | ||
53 | if (netty2 != null) { | 65 | if (netty2 != null) { |
54 | - netty2.stop(); | 66 | + netty2.deactivate(); |
55 | } | 67 | } |
56 | } | 68 | } |
57 | 69 | ||
... | @@ -113,9 +125,9 @@ public class NettyMessagingTest { | ... | @@ -113,9 +125,9 @@ public class NettyMessagingTest { |
113 | netty2.registerHandler("test-subject", handler, handlerExecutor); | 125 | netty2.registerHandler("test-subject", handler, handlerExecutor); |
114 | 126 | ||
115 | CompletableFuture<byte[]> response = netty1.sendAndReceive(ep2, | 127 | CompletableFuture<byte[]> response = netty1.sendAndReceive(ep2, |
116 | - "test-subject", | 128 | + "test-subject", |
117 | - "hello world".getBytes(), | 129 | + "hello world".getBytes(), |
118 | - completionExecutor); | 130 | + completionExecutor); |
119 | response.whenComplete((r, e) -> { | 131 | response.whenComplete((r, e) -> { |
120 | completionThreadName.set(Thread.currentThread().getName()); | 132 | completionThreadName.set(Thread.currentThread().getName()); |
121 | }); | 133 | }); |
... | @@ -125,4 +137,40 @@ public class NettyMessagingTest { | ... | @@ -125,4 +137,40 @@ public class NettyMessagingTest { |
125 | assertEquals("completion-thread", completionThreadName.get()); | 137 | assertEquals("completion-thread", completionThreadName.get()); |
126 | assertEquals("handler-thread", handlerThreadName.get()); | 138 | assertEquals("handler-thread", handlerThreadName.get()); |
127 | } | 139 | } |
128 | -} | 140 | + |
141 | + private ClusterMetadataService dummyMetadataService(String name, String ipAddress, Endpoint ep) { | ||
142 | + return new ClusterMetadataService() { | ||
143 | + @Override | ||
144 | + public ClusterMetadata getClusterMetadata() { | ||
145 | + return new ClusterMetadata(new ProviderId(DUMMY_NAME, DUMMY_NAME), | ||
146 | + name, Sets.newHashSet(), Sets.newHashSet()); | ||
147 | + } | ||
148 | + | ||
149 | + @Override | ||
150 | + public ControllerNode getLocalNode() { | ||
151 | + return new ControllerNode() { | ||
152 | + @Override | ||
153 | + public NodeId id() { | ||
154 | + return null; | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public IpAddress ip() { | ||
159 | + return IpAddress.valueOf(ipAddress); | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public int tcpPort() { | ||
164 | + return ep.port(); | ||
165 | + } | ||
166 | + }; | ||
167 | + } | ||
168 | + | ||
169 | + @Override | ||
170 | + public void addListener(ClusterMetadataEventListener listener) {} | ||
171 | + | ||
172 | + @Override | ||
173 | + public void removeListener(ClusterMetadataEventListener listener) {} | ||
174 | + }; | ||
175 | + } | ||
176 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
utils/netty/pom.xml
deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2014 Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
20 | - <modelVersion>4.0.0</modelVersion> | ||
21 | - | ||
22 | - <parent> | ||
23 | - <groupId>org.onosproject</groupId> | ||
24 | - <artifactId>onlab-utils</artifactId> | ||
25 | - <version>1.5.0-SNAPSHOT</version> | ||
26 | - <relativePath>../pom.xml</relativePath> | ||
27 | - </parent> | ||
28 | - | ||
29 | - <artifactId>onlab-netty</artifactId> | ||
30 | - <packaging>bundle</packaging> | ||
31 | - | ||
32 | - <description>Network I/O using Netty framework</description> | ||
33 | - | ||
34 | - <dependencies> | ||
35 | - <dependency> | ||
36 | - <groupId>com.google.guava</groupId> | ||
37 | - <artifactId>guava-testlib</artifactId> | ||
38 | - <scope>test</scope> | ||
39 | - </dependency> | ||
40 | - <dependency> | ||
41 | - <groupId>org.onosproject</groupId> | ||
42 | - <artifactId>onos-api</artifactId> | ||
43 | - </dependency> | ||
44 | - <dependency> | ||
45 | - <groupId>org.onosproject</groupId> | ||
46 | - <artifactId>onlab-misc</artifactId> | ||
47 | - </dependency> | ||
48 | - <dependency> | ||
49 | - <groupId>org.onosproject</groupId> | ||
50 | - <artifactId>onlab-junit</artifactId> | ||
51 | - <scope>test</scope> | ||
52 | - </dependency> | ||
53 | - <dependency> | ||
54 | - <groupId>commons-pool</groupId> | ||
55 | - <artifactId>commons-pool</artifactId> | ||
56 | - </dependency> | ||
57 | - <dependency> | ||
58 | - <groupId>io.netty</groupId> | ||
59 | - <artifactId>netty-common</artifactId> | ||
60 | - </dependency> | ||
61 | - <dependency> | ||
62 | - <groupId>io.netty</groupId> | ||
63 | - <artifactId>netty-buffer</artifactId> | ||
64 | - </dependency> | ||
65 | - <dependency> | ||
66 | - <groupId>io.netty</groupId> | ||
67 | - <artifactId>netty-transport</artifactId> | ||
68 | - </dependency> | ||
69 | - <dependency> | ||
70 | - <groupId>io.netty</groupId> | ||
71 | - <artifactId>netty-handler</artifactId> | ||
72 | - </dependency> | ||
73 | - <dependency> | ||
74 | - <groupId>io.netty</groupId> | ||
75 | - <artifactId>netty-codec</artifactId> | ||
76 | - </dependency> | ||
77 | - <dependency> | ||
78 | - <groupId>io.netty</groupId> | ||
79 | - <artifactId>netty-transport-native-epoll</artifactId> | ||
80 | - <version>${netty4.version}</version> | ||
81 | - </dependency> | ||
82 | - </dependencies> | ||
83 | -</project> |
This diff is collapsed. Click to expand it.
1 | -/* | ||
2 | - * Copyright 2014 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | - | ||
17 | -/** | ||
18 | - * Asynchronous messaging APIs implemented using the Netty framework. | ||
19 | - */ | ||
20 | -package org.onlab.netty; |
... | @@ -34,7 +34,6 @@ | ... | @@ -34,7 +34,6 @@ |
34 | <modules> | 34 | <modules> |
35 | <module>junit</module> | 35 | <module>junit</module> |
36 | <module>misc</module> | 36 | <module>misc</module> |
37 | - <module>netty</module> | ||
38 | <module>nio</module> | 37 | <module>nio</module> |
39 | <module>yangutils</module> | 38 | <module>yangutils</module> |
40 | <module>osgi</module> | 39 | <module>osgi</module> | ... | ... |
-
Please register or login to post a comment