Skip to content

Commit

Permalink
avoid relaying changes if theres no one listening to the passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Jul 5, 2021
1 parent b6eef99 commit d48c24a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public interface IMEMonitorHandlerReceiver<T extends IAEStack<T>>
* called when the list updates its contents, this is mostly for handling power events.
*/
void onListUpdate();

default boolean hasListeners()
{
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/appeng/me/cache/NetworkMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void notifyListenersOfChange( final Iterable<T> diff, final IActionSourc
{
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
if( receiver.isValid( o.getValue() ) )
if( receiver.isValid( o.getValue() ) && receiver.hasListeners() )
{
receiver.postChange( this, diff, src );
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/appeng/me/storage/MEMonitorPassThrough.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public IItemList<T> getAvailableItems( final IItemList out )
@Override
public void addListener( final IMEMonitorHandlerReceiver<T> l, final Object verificationToken )
{
if( this.listeners.size() == 0 )
{
if( this.monitor != null )
{
this.monitor.addListener( this, this.monitor );
}
}
this.listeners.put( l, verificationToken );
}

Expand Down Expand Up @@ -117,6 +124,12 @@ public boolean isValid( final Object verificationToken )
return verificationToken == this.monitor;
}

@Override
public boolean hasListeners()
{
return this.listeners.size() > 0;
}

@Override
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final IActionSource source )
{
Expand Down

0 comments on commit d48c24a

Please sign in to comment.