Committed by
Gerrit Code Review
[ONOS-3537] Initial implementation of ControlMessageManager
- Add skeletal code of ControlMessageStore - Add initial implementation of ControlMessageManager Change-Id: I17161ce18b67e8f35ea9b80832f3732a55de323b
Showing
6 changed files
with
204 additions
and
8 deletions
... | @@ -18,13 +18,15 @@ package org.onosproject.cpman.message; | ... | @@ -18,13 +18,15 @@ package org.onosproject.cpman.message; |
18 | import org.onosproject.event.AbstractEvent; | 18 | import org.onosproject.event.AbstractEvent; |
19 | import org.onosproject.cpman.ControlMessage; | 19 | import org.onosproject.cpman.ControlMessage; |
20 | 20 | ||
21 | +import java.util.Collection; | ||
22 | + | ||
21 | import static com.google.common.base.MoreObjects.toStringHelper; | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
22 | 24 | ||
23 | /** | 25 | /** |
24 | * Describes control message event. | 26 | * Describes control message event. |
25 | */ | 27 | */ |
26 | public class ControlMessageEvent | 28 | public class ControlMessageEvent |
27 | - extends AbstractEvent<ControlMessageEvent.Type, ControlMessage> { | 29 | + extends AbstractEvent<ControlMessageEvent.Type, Collection<ControlMessage>> { |
28 | 30 | ||
29 | /** | 31 | /** |
30 | * Type of control message events. | 32 | * Type of control message events. |
... | @@ -39,11 +41,11 @@ public class ControlMessageEvent | ... | @@ -39,11 +41,11 @@ public class ControlMessageEvent |
39 | /** | 41 | /** |
40 | * Creates an event of given type and the current time. | 42 | * Creates an event of given type and the current time. |
41 | * | 43 | * |
42 | - * @param type control message event type | 44 | + * @param type control message event type |
43 | - * @param controlMessage event control message subject | 45 | + * @param controlMessages event control message subject |
44 | */ | 46 | */ |
45 | - public ControlMessageEvent(Type type, ControlMessage controlMessage) { | 47 | + public ControlMessageEvent(Type type, Collection<ControlMessage> controlMessages) { |
46 | - super(type, controlMessage); | 48 | + super(type, controlMessages); |
47 | } | 49 | } |
48 | 50 | ||
49 | @Override | 51 | @Override | ... | ... |
... | @@ -20,5 +20,8 @@ import org.onosproject.event.ListenerService; | ... | @@ -20,5 +20,8 @@ import org.onosproject.event.ListenerService; |
20 | /** | 20 | /** |
21 | * Service for obtaining control message statistic information. | 21 | * Service for obtaining control message statistic information. |
22 | */ | 22 | */ |
23 | -public interface ControlMessageService extends ListenerService { | 23 | +public interface ControlMessageService |
24 | + extends ListenerService<ControlMessageEvent, ControlMessageListener> { | ||
25 | + | ||
26 | + | ||
24 | } | 27 | } | ... | ... |
... | @@ -36,8 +36,7 @@ public interface ControlMessageStore | ... | @@ -36,8 +36,7 @@ public interface ControlMessageStore |
36 | * @param controlMessages a collection of control message stats | 36 | * @param controlMessages a collection of control message stats |
37 | * @return ready to send event describing what occurred | 37 | * @return ready to send event describing what occurred |
38 | */ | 38 | */ |
39 | - ControlMessageEvent updateStatsInfo(ProviderId providerId, | 39 | + ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, |
40 | - DeviceId deviceId, | ||
41 | Collection<ControlMessage> controlMessages); | 40 | Collection<ControlMessage> controlMessages); |
42 | 41 | ||
43 | } | 42 | } | ... | ... |
apps/cpman/app/src/main/java/org/onosproject/cpman/impl/message/ControlMessageManager.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.cpman.impl.message; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.apache.felix.scr.annotations.Service; | ||
24 | +import org.onosproject.cpman.ControlMessage; | ||
25 | +import org.onosproject.cpman.message.ControlMessageAdminService; | ||
26 | +import org.onosproject.cpman.message.ControlMessageEvent; | ||
27 | +import org.onosproject.cpman.message.ControlMessageListener; | ||
28 | +import org.onosproject.cpman.message.ControlMessageProvider; | ||
29 | +import org.onosproject.cpman.message.ControlMessageProviderRegistry; | ||
30 | +import org.onosproject.cpman.message.ControlMessageProviderService; | ||
31 | +import org.onosproject.cpman.message.ControlMessageService; | ||
32 | +import org.onosproject.cpman.message.ControlMessageStore; | ||
33 | +import org.onosproject.cpman.message.ControlMessageStoreDelegate; | ||
34 | +import org.onosproject.net.DeviceId; | ||
35 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
36 | +import org.onosproject.net.provider.AbstractProviderService; | ||
37 | +import org.slf4j.Logger; | ||
38 | + | ||
39 | +import java.util.Collection; | ||
40 | + | ||
41 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
42 | +import static org.slf4j.LoggerFactory.getLogger; | ||
43 | + | ||
44 | +/** | ||
45 | + * Provides implementation of the control message SB & NB APIs. | ||
46 | + */ | ||
47 | +@Component(immediate = true) | ||
48 | +@Service | ||
49 | +public class ControlMessageManager | ||
50 | + extends AbstractListenerProviderRegistry<ControlMessageEvent, ControlMessageListener, | ||
51 | + ControlMessageProvider, ControlMessageProviderService> | ||
52 | + implements ControlMessageService, ControlMessageAdminService, | ||
53 | + ControlMessageProviderRegistry { | ||
54 | + | ||
55 | + private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | ||
56 | + | ||
57 | + private final Logger log = getLogger(getClass()); | ||
58 | + | ||
59 | + private final ControlMessageStoreDelegate delegate = new InternalStoreDelegate(); | ||
60 | + | ||
61 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
62 | + protected ControlMessageStore store; | ||
63 | + | ||
64 | + @Activate | ||
65 | + public void activate() { | ||
66 | + store.setDelegate(delegate); | ||
67 | + eventDispatcher.addSink(ControlMessageEvent.class, listenerRegistry); | ||
68 | + | ||
69 | + log.info("Started"); | ||
70 | + } | ||
71 | + | ||
72 | + @Deactivate | ||
73 | + public void deactivate() { | ||
74 | + store.unsetDelegate(delegate); | ||
75 | + eventDispatcher.removeSink(ControlMessageEvent.class); | ||
76 | + | ||
77 | + log.info("Stopped"); | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + protected ControlMessageProviderService createProviderService(ControlMessageProvider provider) { | ||
82 | + return new InternalControlMessageProviderService(provider); | ||
83 | + } | ||
84 | + | ||
85 | + private class InternalControlMessageProviderService | ||
86 | + extends AbstractProviderService<ControlMessageProvider> | ||
87 | + implements ControlMessageProviderService { | ||
88 | + InternalControlMessageProviderService(ControlMessageProvider provider) { | ||
89 | + super(provider); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public void updateStatsInfo(DeviceId deviceId, Collection<ControlMessage> controlMessages) { | ||
94 | + checkNotNull(deviceId, DEVICE_ID_NULL); | ||
95 | + checkValidity(); | ||
96 | + | ||
97 | + ControlMessageEvent event = | ||
98 | + store.updateStatsInfo(this.provider().id(), deviceId, controlMessages); | ||
99 | + | ||
100 | + post(event); | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + private class InternalStoreDelegate implements ControlMessageStoreDelegate { | ||
105 | + @Override | ||
106 | + public void notify(ControlMessageEvent event) { | ||
107 | + post(event); | ||
108 | + } | ||
109 | + } | ||
110 | +} |
apps/cpman/app/src/main/java/org/onosproject/cpman/impl/message/DefaultControlMessageStore.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016 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 | +package org.onosproject.cpman.impl.message; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Service; | ||
22 | +import org.onosproject.cpman.ControlMessage; | ||
23 | +import org.onosproject.cpman.message.ControlMessageEvent; | ||
24 | +import org.onosproject.cpman.message.ControlMessageStore; | ||
25 | +import org.onosproject.cpman.message.ControlMessageStoreDelegate; | ||
26 | +import org.onosproject.net.DeviceId; | ||
27 | +import org.onosproject.net.provider.ProviderId; | ||
28 | +import org.onosproject.store.AbstractStore; | ||
29 | +import org.slf4j.Logger; | ||
30 | + | ||
31 | +import java.util.Collection; | ||
32 | + | ||
33 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | + | ||
35 | +/** | ||
36 | + * Manages inventory of control message using trivial in-memory structures | ||
37 | + * implementation. | ||
38 | + */ | ||
39 | +@Component(immediate = true) | ||
40 | +@Service | ||
41 | +public class DefaultControlMessageStore | ||
42 | + extends AbstractStore<ControlMessageEvent, ControlMessageStoreDelegate> | ||
43 | + implements ControlMessageStore { | ||
44 | + | ||
45 | + private final Logger log = getLogger(getClass()); | ||
46 | + | ||
47 | + @Override | ||
48 | + public ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, | ||
49 | + Collection<ControlMessage> controlMessages) { | ||
50 | + | ||
51 | + return new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, controlMessages); | ||
52 | + } | ||
53 | + | ||
54 | + @Activate | ||
55 | + public void activate() { | ||
56 | + log.info("Started"); | ||
57 | + } | ||
58 | + | ||
59 | + @Deactivate | ||
60 | + public void deactivate() { | ||
61 | + log.info("Stopped"); | ||
62 | + } | ||
63 | +} |
1 | +/* | ||
2 | + * Copyright 2016 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 | + * Implementation of control message manager. | ||
18 | + */ | ||
19 | +package org.onosproject.cpman.impl.message; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment