jadex.bridge.nonfunctional.NFRootProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform-bridge Show documentation
Show all versions of jadex-platform-bridge Show documentation
Jadex bridge is a base package for kernels and platforms, i.e., it is used by both and provides commonly used interfaces and classes for active components and their management.
package jadex.bridge.nonfunctional;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
/**
* Injects properties on root component.
*/
public abstract class NFRootProperty extends SimpleValueNFProperty
{
/** The root access. */
protected IExternalAccess root;
/** The flag if the property has been injected to the root component. */
protected boolean injected;
/**
* Create a new property.
*/
public NFRootProperty(final IInternalAccess comp, final NFPropertyMetaInfo mi)
{
this(comp, mi, true);
}
/**
* Create a new property.
*/
public NFRootProperty(final IInternalAccess comp, final NFPropertyMetaInfo mi, boolean inject)
{
super(comp, mi);
if(inject)
injectPropertyToRootComponent();
}
/**
* Inject the property to the root component.
*/
protected IFuture injectPropertyToRootComponent()
{
final Future ret = new Future();
if(!injected)
{
this.injected = true;
// Add property to root component
// IComponentManagementService cms = comp.getFeature(IRequiredServicesFeature.class).getLocalService(new ServiceQuery<>(IComponentManagementService.class));
comp.getExternalAccessAsync(comp.getId().getRoot()).addResultListener(new DefaultResultListener()
{
public void resultAvailable(IExternalAccess root)
{
NFRootProperty.this.root = root;
INFPropertyMetaInfo mi = getMetaInfo();
NFPropertyMetaInfo cmi = new NFPropertyMetaInfo(mi.getName(), mi.getType(), mi.getUnit(), mi.isDynamic(), mi.getUpdateRate(), mi.isRealtime(), Target.Root);
// ((INFPropertyProvider)root.getExternalComponentFeature(INFPropertyComponentFeature.class)).addNFProperty(new NFPropertyRef((INFPropertyProvider)comp.getExternalAccess().getExternalComponentFeature(INFPropertyComponentFeature.class), root, cmi)).addResultListener(new DelegationResultListener(ret));
NFPropertyRef pr = new NFPropertyRef(comp.getExternalAccess(), cmi, null, null);
root.addNFProperty(pr).addResultListener(new DelegationResultListener(ret));
}
});
}
else
{
ret.setResult(null);
}
return ret;
}
/**
* Property was removed and should be disposed.
*/
public IFuture dispose()
{
final Future ret = new Future();
if(root!=null && injected)
{
// ((INFPropertyProvider)root.getExternalComponentFeature(INFPropertyComponentFeature.class)).removeNFProperty(getName());//.addResultListener(new DelegationResultListener(ret));
root.removeNFProperty(getName()).addResultListener(new IResultListener()
{
public void resultAvailable(Void result)
{
NFRootProperty.super.dispose().addResultListener(new DelegationResultListener(ret));
}
public void exceptionOccurred(Exception exception)
{
NFRootProperty.super.dispose().addResultListener(new DelegationResultListener(ret));
}
});
}
else
{
return super.dispose();
}
return ret;
}
/**
* Get the injected.
* @return The injected.
*/
public boolean isInjected()
{
return injected;
}
}