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;
public abstract class ControllableBase extends NamedBaseImpl
implements Controllable {
private static final Set<ControllableBase> emptyContent =
Collections.unmodifiableSet( new HashSet<ControllableBase>() ) ;
private int id ;
private String description ;
private boolean isEnabled ;
protected ControllableBase( int id, String name, String description,
TimerFactoryImpl factory ) {
super( factory, name ) ;
this.id = id ;
this.description = description ;
isEnabled = false ;
}
@Override
public int id() {
return id ;
}
@Override
public String description() {
return description ;
}
void description( String description ) {
this.description = description ;
}
@Override
public final boolean isEnabled() {
return isEnabled ;
}
@Override
public Set<ControllableBase> contents() {
return emptyContent ;
}
@Override
public void enable() {
synchronized( factory() ) {
if (!isEnabled()) {
isEnabled = true ;
factory().updateActivation() ;
}
}
}
@Override
public void disable() {
synchronized( factory() ) {
if (isEnabled()) {
isEnabled = false ;
factory().updateActivation() ;
}
}
}
void transitiveClosure( Set<ControllableBase> result ) {
result.add( this ) ;
for (ControllableBase c : contents() ) {
if (!result.contains(c)) {
c.transitiveClosure( result ) ;
}
}
}
}