From 026b08b4898a5bcae35dbace1a26e2e8997c8ec5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 2 Mar 2023 01:19:32 +0100 Subject: [PATCH] Remove io.atomix.utils.event Nothing in this package is needed here, remove it. JIRA: CONTROLLER-2071 Change-Id: Ib3d75d07b4e9c7b902471c31863bd6fe2b558e19 Signed-off-by: Robert Varga --- .../io/atomix/utils/event/AbstractEvent.java | 77 --------------- .../utils/event/AbstractListenerManager.java | 44 --------- .../java/io/atomix/utils/event/Event.java | 45 --------- .../io/atomix/utils/event/EventFilter.java | 34 ------- .../io/atomix/utils/event/EventListener.java | 31 ------ .../java/io/atomix/utils/event/EventSink.java | 36 ------- .../atomix/utils/event/ListenerRegistry.java | 99 ------------------- .../atomix/utils/event/ListenerService.java | 37 ------- .../io/atomix/utils/event/package-info.java | 20 ---- 9 files changed, 423 deletions(-) delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractEvent.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractListenerManager.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/Event.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventFilter.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventListener.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventSink.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerRegistry.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerService.java delete mode 100644 third-party/atomix/utils/src/main/java/io/atomix/utils/event/package-info.java diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractEvent.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractEvent.java deleted file mode 100644 index cd34430c6a..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractEvent.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 implements Event { - 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(); - } -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractListenerManager.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractListenerManager.java deleted file mode 100644 index 55d96264a7..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/AbstractListenerManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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> implements ListenerService { - - protected final ListenerRegistry 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); - } - -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/Event.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/Event.java deleted file mode 100644 index 24849006be..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/Event.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 { - - /** - * 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/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventFilter.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventFilter.java deleted file mode 100644 index fa38b723c2..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventFilter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 { - - /** - * 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/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventListener.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventListener.java deleted file mode 100644 index 6e0e1c71d3..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 extends EventFilter { - - /** - * Reacts to the specified event. - * - * @param event event to be processed - */ - void event(E event); - -} diff --git a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventSink.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventSink.java deleted file mode 100644 index cbffc9c253..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/EventSink.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 { - - /** - * 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/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerRegistry.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerRegistry.java deleted file mode 100644 index 757288cb9a..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerRegistry.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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> - implements ListenerService, EventSink { - - 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 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/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerService.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerService.java deleted file mode 100644 index 45db98a206..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/ListenerService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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> { - - /** - * 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/third-party/atomix/utils/src/main/java/io/atomix/utils/event/package-info.java b/third-party/atomix/utils/src/main/java/io/atomix/utils/event/package-info.java deleted file mode 100644 index 41952bb175..0000000000 --- a/third-party/atomix/utils/src/main/java/io/atomix/utils/event/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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; -- 2.36.6