summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/api/src/main/java/org/onosproject/event
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/event')
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractEvent.java78
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractListenerManager.java58
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/DefaultEventSinkRegistry.java62
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/Event.java45
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDeliveryService.java38
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDispatcher.java33
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventFilter.java34
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventListener.java30
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSink.java36
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSinkRegistry.java60
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerRegistry.java99
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerService.java38
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/event/package-info.java20
13 files changed, 0 insertions, 631 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractEvent.java
deleted file mode 100644
index 67b10292..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractEvent.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.joda.time.LocalDateTime;
-
-import static com.google.common.base.MoreObjects.toStringHelper;
-
-/**
- * Base event implementation.
- */
-public class AbstractEvent<T extends Enum, S> implements Event<T, S> {
-
- private final long time;
- private final T type;
- private final S subject;
-
- /**
- * Creates an event of a given type and for the specified subject and the
- * current time.
- *
- * @param type event type
- * @param subject event subject
- */
- protected AbstractEvent(T type, S subject) {
- this(type, subject, System.currentTimeMillis());
- }
-
- /**
- * Creates an event of a given type and for the specified subject and time.
- *
- * @param type event type
- * @param subject event subject
- * @param time occurrence time
- */
- protected AbstractEvent(T type, S subject, long time) {
- this.type = type;
- this.subject = subject;
- this.time = time;
- }
-
- @Override
- public long time() {
- return time;
- }
-
- @Override
- public T type() {
- return type;
- }
-
- @Override
- public S subject() {
- return subject;
- }
-
- @Override
- public String toString() {
- return toStringHelper(this)
- .add("time", new LocalDateTime(time))
- .add("type", type())
- .add("subject", subject())
- .toString();
- }
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractListenerManager.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractListenerManager.java
deleted file mode 100644
index cbe7421f..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/AbstractListenerManager.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-
-/**
- * Basis for components which need to export listener mechanism.
- */
-@Component(componentAbstract = true)
-public abstract class AbstractListenerManager<E extends Event, L extends EventListener<E>>
- implements ListenerService<E, L> {
-
- protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected EventDeliveryService eventDispatcher;
-
- @Override
- public void addListener(L listener) {
- listenerRegistry.addListener(listener);
- }
-
- @Override
- public void removeListener(L listener) {
- listenerRegistry.removeListener(listener);
- }
-
-
- /**
- * Safely posts the specified event to the local event dispatcher.
- * If there is no event dispatcher or if the event is null, this method
- * is a noop.
- *
- * @param event event to be posted; may be null
- */
- protected void post(E event) {
- if (event != null && eventDispatcher != null) {
- eventDispatcher.post(event);
- }
- }
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/DefaultEventSinkRegistry.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/DefaultEventSinkRegistry.java
deleted file mode 100644
index be6ddb61..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/DefaultEventSinkRegistry.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import com.google.common.collect.ImmutableSet;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Base implementation of event sink registry.
- */
-public class DefaultEventSinkRegistry implements EventSinkRegistry {
-
- private final Map<Class<? extends Event>, EventSink<? extends Event>>
- sinks = new ConcurrentHashMap<>();
-
- @Override
- public <E extends Event> void addSink(Class<E> eventClass, EventSink<E> sink) {
- checkNotNull(eventClass, "Event class cannot be null");
- checkNotNull(sink, "Event sink cannot be null");
- checkArgument(!sinks.containsKey(eventClass),
- "Event sink already registered for %s", eventClass.getName());
- sinks.put(eventClass, sink);
- }
-
- @Override
- public <E extends Event> void removeSink(Class<E> eventClass) {
- checkNotNull(eventClass, "Event class cannot be null");
- checkArgument(sinks.remove(eventClass) != null,
- "Event sink not registered for %s", eventClass.getName());
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <E extends Event> EventSink<E> getSink(Class<E> eventClass) {
- checkNotNull(eventClass, "Event class cannot be null");
- return (EventSink<E>) sinks.get(eventClass);
- }
-
- @Override
- public Set<Class<? extends Event>> getSinks() {
- return ImmutableSet.copyOf(sinks.keySet());
- }
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/Event.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/Event.java
deleted file mode 100644
index e7cbb60f..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/Event.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2014-2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Abstraction of an of a time-stamped event pertaining to an arbitrary subject.
- */
-public interface Event<T extends Enum, S> {
-
- /**
- * Returns the timestamp of when the event occurred, given in milliseconds
- * since the start of epoch.
- *
- * @return timestamp in milliseconds
- */
- long time();
-
- /**
- * Returns the type of the event.
- *
- * @return event type
- */
- T type();
-
- /**
- * Returns the subject of the event.
- *
- * @return subject to which this event pertains
- */
- S subject();
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDeliveryService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDeliveryService.java
deleted file mode 100644
index ff268935..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDeliveryService.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Abstraction of an entity capable of accepting events to be posted and
- * then dispatching them to the appropriate event sink.
- */
-public interface EventDeliveryService extends EventDispatcher, EventSinkRegistry {
-
- /**
- * Sets the number of millis that an event sink has to process an event.
- *
- * @param millis number of millis allowed per sink per event
- */
- void setDispatchTimeLimit(long millis);
-
- /**
- * Returns the number of millis that an event sink has to process an event.
- *
- * @return number of millis allowed per sink per event
- */
- long getDispatchTimeLimit();
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDispatcher.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDispatcher.java
deleted file mode 100644
index daebd8b0..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventDispatcher.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Abstraction of a mechanism capable of accepting and dispatching events to
- * appropriate event sinks. Where the event sinks are obtained is unspecified.
- * Similarly, whether the events are accepted and dispatched synchronously
- * or asynchronously is unspecified as well.
- */
-public interface EventDispatcher {
-
- /**
- * Posts the specified event for dispatching.
- *
- * @param event event to be posted
- */
- void post(Event event);
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventFilter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventFilter.java
deleted file mode 100644
index 3b2498f6..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventFilter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Entity capable of filtering events.
- */
-public interface EventFilter<E extends Event> {
-
- /**
- * Indicates whether the specified event is of interest or not.
- * Default implementation always returns true.
- *
- * @param event event to be inspected
- * @return true if event is relevant; false otherwise
- */
- default boolean isRelevant(E event) {
- return true;
- }
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventListener.java
deleted file mode 100644
index e77369fc..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Entity capable of receiving events.
- */
-public interface EventListener<E extends Event> extends EventFilter<E> {
-
- /**
- * Reacts to the specified event.
- *
- * @param event event to be processed
- */
- void event(E event);
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSink.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSink.java
deleted file mode 100644
index 221b3224..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSink.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Abstraction of an event sink capable of processing the specified event types.
- */
-public interface EventSink<E extends Event> {
-
- /**
- * Processes the specified event.
- *
- * @param event event to be processed
- */
- void process(E event);
-
- /**
- * Handles notification that event processing time limit has been exceeded.
- */
- default void onProcessLimit() {
- }
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSinkRegistry.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSinkRegistry.java
deleted file mode 100644
index bb054a30..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/EventSinkRegistry.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import java.util.Set;
-
-/**
- * Abstraction of an event sink registry capable of tracking sinks based on
- * their event class.
- */
-public interface EventSinkRegistry {
-
- /**
- * Adds the specified sink for the given event class.
- *
- * @param eventClass event class
- * @param sink event sink
- * @param <E> type of event
- */
- <E extends Event> void addSink(Class<E> eventClass, EventSink<E> sink);
-
- /**
- * Removes the sink associated with the given event class.
- *
- * @param eventClass event class
- * @param <E> type of event
- */
- <E extends Event> void removeSink(Class<E> eventClass);
-
- /**
- * Returns the event sink associated with the specified event class.
- *
- * @param eventClass event class
- * @param <E> type of event
- * @return event sink or null if none found
- */
- <E extends Event> EventSink<E> getSink(Class<E> eventClass);
-
- /**
- * Returns the set of all event classes for which sinks are presently
- * registered.
- *
- * @return set of event classes
- */
- Set<Class<? extends Event>> getSinks();
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerRegistry.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerRegistry.java
deleted file mode 100644
index ef02af06..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerRegistry.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.slf4j.Logger;
-
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Base implementation of an event sink and a registry capable of tracking
- * listeners and dispatching events to them as part of event sink processing.
- */
-public class ListenerRegistry<E extends Event, L extends EventListener<E>>
- implements ListenerService<E, L>, EventSink<E> {
-
- private static final long LIMIT = 1_800; // ms
-
- private final Logger log = getLogger(getClass());
-
- private long lastStart;
- private L lastListener;
-
- /**
- * Set of listeners that have registered.
- */
- protected final Set<L> listeners = new CopyOnWriteArraySet<>();
-
- @Override
- public void addListener(L listener) {
- checkNotNull(listener, "Listener cannot be null");
- listeners.add(listener);
- }
-
- @Override
- public void removeListener(L listener) {
- checkNotNull(listener, "Listener cannot be null");
- if (!listeners.remove(listener)) {
- log.warn("Listener {} not registered", listener);
- }
- }
-
- @Override
- public void process(E event) {
- for (L listener : listeners) {
- try {
- lastListener = listener;
- lastStart = System.currentTimeMillis();
- if (listener.isRelevant(event)) {
- listener.event(event);
- }
- lastStart = 0;
- } catch (Exception error) {
- reportProblem(event, error);
- }
- }
- }
-
- @Override
- public void onProcessLimit() {
- if (lastStart > 0) {
- long duration = System.currentTimeMillis() - lastStart;
- if (duration > LIMIT) {
- log.error("Listener {} exceeded execution time limit: {} ms; ejected",
- lastListener.getClass().getName(),
- duration);
- removeListener(lastListener);
- }
- lastStart = 0;
- }
- }
-
- /**
- * Reports a problem encountered while processing an event.
- *
- * @param event event being processed
- * @param error error encountered while processing
- */
- protected void reportProblem(E event, Throwable error) {
- log.warn("Exception encountered while processing event " + event, error);
- }
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerService.java
deleted file mode 100644
index a4a36319..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/ListenerService.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-/**
- * Abstraction of a service capable of asynchronously notifying listeners.
- */
-public interface ListenerService<E extends Event, L extends EventListener<E>> {
-
- /**
- * Adds the specified listener.
- *
- * @param listener listener to be added
- */
- void addListener(L listener);
-
- /**
- * Removes the specified listener.
- *
- * @param listener listener to be removed
- */
- void removeListener(L listener);
-
-
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/event/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/event/package-info.java
deleted file mode 100644
index 6b10bcf5..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/event/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Local event delivery subsystem interfaces &amp; supporting abstractions.
- */
-package org.onosproject.event;