org.glassfish.pfl.tf.timer.impl.TimerGroupImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-rt Show documentation
Show all versions of webservices-rt Show documentation
This module contains the Metro runtime code.
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.pfl.tf.timer.impl ;
import java.util.Set ;
import java.util.HashSet ;
import java.util.Collections ;
import org.glassfish.pfl.tf.timer.spi.Controllable;
import org.glassfish.pfl.tf.timer.spi.TimerGroup;
/** A TimerGroup is a collection of Controllables, which includes
* Timers and TimerGroups.
*/
public class TimerGroupImpl extends ControllableBase implements TimerGroup {
private Set contents ;
private Set roContents ;
private long contentVersion ;
private Set tcContents ; // the transitive closure for this element
// of the relation created by contents.
private Set roTcContents ;
private long tcContentVersion ;
TimerGroupImpl( int id, TimerFactoryImpl factory, String name, String description ) {
super( id, name, description, factory ) ;
contents = new HashSet() ;
roContents = Collections.unmodifiableSet( contents ) ;
contentVersion = 0 ;
tcContents = new HashSet() ;
roTcContents = Collections.unmodifiableSet( tcContents ) ;
tcContentVersion = -1 ;
}
public Set contents() {
return roContents ;
}
public boolean add( Controllable con ) {
synchronized (factory()) {
boolean result = contents.add( ControllableBase.class.cast( con ) ) ;
if (result)
contentVersion++ ;
return result ;
}
}
public boolean remove( Controllable con ) {
synchronized (factory()) {
boolean result = contents.remove( ControllableBase.class.cast( con ) ) ;
if (result)
contentVersion++ ;
return result ;
}
}
// Get the transitive closure. This is cached, and updated if the
// contents have changed since the last access to tcContents.
Set tcContents() {
if (contentVersion != tcContentVersion) {
tcContents.clear() ;
transitiveClosure( tcContents ) ;
}
return roTcContents ;
}
}