Nothing in this package is needed here, remove it.
JIRA: CONTROLLER-2071
Change-Id: Ib3d75d07b4e9c7b902471c31863bd6fe2b558e19
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
+++ /dev/null
-/*
- * Copyright 2014-present Open Networking Foundation
- *
- * 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 io.atomix.utils.event;
-
-import io.atomix.utils.misc.TimestampPrinter;
-
-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 TimestampPrinter(time))
- .add("type", type())
- .add("subject", subject())
- .toString();
- }
-}
+++ /dev/null
-/*
- * Copyright 2015-present Open Networking Foundation
- *
- * 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 io.atomix.utils.event;
-
-/**
- * Basis for components which need to export listener mechanism.
- */
-public abstract class AbstractListenerManager<E extends Event, L extends EventListener<E>> implements ListenerService<E, L> {
-
- protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
-
- @Override
- public void addListener(L listener) {
- listenerRegistry.addListener(listener);
- }
-
- @Override
- public void removeListener(L listener) {
- listenerRegistry.removeListener(listener);
- }
-
- /**
- * Posts the specified event to the local event dispatcher.
- *
- * @param event event to be posted; may be null
- */
- protected void post(E event) {
- listenerRegistry.process(event);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2014-present Open Networking Foundation
- *
- * 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 io.atomix.utils.event;
-
-/**
- * Abstraction of an of a time-stamped event pertaining to an arbitrary subject.
- */
-public interface Event<T, 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();
-
-}
+++ /dev/null
-/*
- * Copyright 2015-present Open Networking Foundation
- *
- * 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 io.atomix.utils.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;
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2014-present Open Networking Foundation
- *
- * 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 io.atomix.utils.event;
-
-/**
- * Entity capable of receiving events.
- */
-@FunctionalInterface
-public interface EventListener<E extends Event> extends EventFilter<E> {
-
- /**
- * Reacts to the specified event.
- *
- * @param event event to be processed
- */
- void event(E event);
-
-}
+++ /dev/null
-/*
- * Copyright 2014-present Open Networking Foundation
- *
- * 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 io.atomix.utils.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() {
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2015-present Open Networking Foundation
- *
- * 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 io.atomix.utils.event;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * 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 = LoggerFactory.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);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2015-present Open Networking Foundation
- *
- * 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 io.atomix.utils.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);
-
-}
+++ /dev/null
-/*
- * Copyright 2017-present Open Networking Foundation
- *
- * 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.
- */
-
-/**
- * Provides classes and interfaces for creating and handling generic events.
- */
-package io.atomix.utils.event;