-
Notifications
You must be signed in to change notification settings - Fork 25
HPCC4J-370 Remove Observable pattern from codebase #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: candidate-9.8.x
Are you sure you want to change the base?
Changes from 3 commits
6ee9e3c
2c21bc2
575e66b
7a05c21
6900c24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /******************************************************************************* | ||
|
||
| * Copyright (c) 2025 HPCC Systems. All rights reserved. This program and the accompanying materials are made available | ||
| * under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: HPCC Systems - initial API and implementation | ||
| ******************************************************************************/ | ||
| package org.hpccsystems.ws.client.utils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A simple observable pattern implementation to replace the deprecated java.util.Observable. | ||
| * This class allows observers to be notified when the state of an object changes. | ||
| */ | ||
| public class Observable | ||
| { | ||
| private final List<Observer> observers = new ArrayList<>(); | ||
| private boolean changed = false; | ||
|
|
||
| /** | ||
| * Adds an observer to the set of observers for this object. | ||
| * | ||
| * @param o the observer to be added | ||
| * @throws NullPointerException if the parameter o is null | ||
| */ | ||
| public synchronized void addObserver(Observer o) | ||
| { | ||
| if (o == null) | ||
| { | ||
| throw new NullPointerException(); | ||
| } | ||
| if (!observers.contains(o)) | ||
| { | ||
| observers.add(o); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Deletes an observer from the set of observers of this object. | ||
| * | ||
| * @param o the observer to be deleted | ||
| */ | ||
| public synchronized void deleteObserver(Observer o) | ||
| { | ||
| observers.remove(o); | ||
| } | ||
|
|
||
| /** | ||
| * Notifies all observers if this object has been marked as changed. | ||
| */ | ||
| public void notifyObservers() | ||
| { | ||
| notifyObservers(null); | ||
| } | ||
|
|
||
| /** | ||
| * Notifies all observers if this object has been marked as changed. | ||
| * | ||
| * @param arg an argument to pass to observers | ||
| */ | ||
| public void notifyObservers(Object arg) | ||
| { | ||
| Object[] arrLocal; | ||
|
|
||
| synchronized (this) | ||
| { | ||
| if (!changed) | ||
| { | ||
| return; | ||
| } | ||
| arrLocal = observers.toArray(); | ||
| clearChanged(); | ||
| } | ||
|
|
||
| for (int i = arrLocal.length - 1; i >= 0; i--) | ||
| { | ||
| ((Observer) arrLocal[i]).update(this, arg); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Deletes all observers from the set of observers of this object. | ||
| */ | ||
| public synchronized void deleteObservers() | ||
| { | ||
| observers.clear(); | ||
| } | ||
|
|
||
| /** | ||
| * Marks this Observable object as having been changed. | ||
| */ | ||
| protected synchronized void setChanged() | ||
| { | ||
| changed = true; | ||
| } | ||
|
|
||
| /** | ||
| * Clears the changed state of this object. | ||
| */ | ||
| protected synchronized void clearChanged() | ||
| { | ||
| changed = false; | ||
| } | ||
|
|
||
| /** | ||
| * Tests if this object has changed. | ||
| * | ||
| * @return true if this object has been marked as changed, false otherwise | ||
| */ | ||
| public synchronized boolean hasChanged() | ||
| { | ||
| return changed; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of observers of this Observable object. | ||
| * | ||
| * @return the number of observers | ||
| */ | ||
| public synchronized int countObservers() | ||
| { | ||
| return observers.size(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /******************************************************************************* | ||
|
||
| * Copyright (c) 2025 HPCC Systems. All rights reserved. This program and the accompanying materials are made available | ||
| * under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: HPCC Systems - initial API and implementation | ||
| ******************************************************************************/ | ||
| package org.hpccsystems.ws.client.utils; | ||
|
|
||
| /** | ||
| * A simple observer interface to replace the deprecated java.util.Observer. | ||
| * An object that implements this interface can observe changes in Observable objects. | ||
| */ | ||
| public interface Observer | ||
| { | ||
| /** | ||
| * This method is called whenever the observed object is changed. | ||
| * | ||
| * @param o the observable object | ||
| * @param arg an argument passed to the notifyObservers method | ||
| */ | ||
| void update(Observable o, Object arg); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Lets remove the dependency on the Observable pattern here entirely, the functionality is no longer needed. All locations in the code base the depend on the pattern should be updated to remove the observer functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the Observable pattern entirely. Deleted Observable.java and Observer.java files, removed extends Observable from DataSingleton and DataSingletonCollection, and removed all setChanged() and notifyObservers() calls from all platform classes (commit 7a05c21)