Stardust provides the interface IArtifactHandler, which can be implemented to handle artifacts of a specific artifact type.
..
import org.eclipse.stardust.common.annotations.SPI;
import org.eclipse.stardust.common.annotations.Status;
import org.eclipse.stardust.common.annotations.UseRestriction;
import org.eclipse.stardust.engine.api.runtime.ArtifactType;
import org.eclipse.stardust.engine.api.runtime.DeployedRuntimeArtifact;
import org.eclipse.stardust.engine.api.runtime.RuntimeArtifact;
@SPI(status=Status.Stable, useRestriction=UseRestriction.Public)
public interface IArtifactHandler
{
public interface Factory
{
IArtifactHandler getInstance();
}
ArtifactType getArtifactType();
String getArtifactContentType(RuntimeArtifact runtimeArtifact);
RuntimeArtifact preProcess(RuntimeArtifact runtimeArtifact);
void afterOverwrite(DeployedRuntimeArtifact deployedRuntimeArtifact);
void beforeDelete(DeployedRuntimeArtifact deployedRuntimeArtifact);
void afterDelete(long oid);
}
The artifact handler provides implementation methods for the following purposes:
To retrieve the ArtifactType of the artifact, implement the following method:
ArtifactType getArtifactType();
For example:
public static final ArtifactType ARTIFACT_TYPE = new BenchmarkDefinitionArtifactType();
public ArtifactType getArtifactType()
{
return ARTIFACT_TYPE;
}
The following method returns the MIME-type of the artifact.
String getArtifactContentType(RuntimeArtifact runtimeArtifact);
For example:
public static final String MIME_TYPE = "application/json";
public String getArtifactContentType(RuntimeArtifact runtimeArtifact)
{
return MIME_TYPE;
}
The following method is called before deploy and overwrite:
RuntimeArtifact preProcess(RuntimeArtifact runtimeArtifact);
Parameter is the input artifact. The handler can pre-process this artifact before it is deployed, for example compile, convert or validate it. It is possible to change all fields of the RuntimeArtifact prior to deployment, e.g. the artifactId to change the file ending for a compiled or processed artifact. The pre-processed artifact is returned.
public RuntimeArtifact preProcess(RuntimeArtifact runtimeArtifact)
{
return runtimeArtifact;
}
Implement the following method to notify after a runtime artifact is overwritten:
void afterOverwrite(DeployedRuntimeArtifact deployedRuntimeArtifact);
For example:
public void afterOverwrite(DeployedRuntimeArtifact deployedRuntimeArtifact)
{
BenchmarkUtils.removeBenchmarkFromCache(deployedRuntimeArtifact.getOid());
}
With method beforeDelete, the artifact handler can e.g. check referential
integrity and prevent a deletion if the artifact is still being required.
void beforeDelete(DeployedRuntimeArtifact deployedRuntimeArtifact);
Using method afterDelete the artifact handler can purge caches after the
artifact was deleted.
void afterDelete(long oid);
The BenchmarkDefinitionArtifactHandler is an implementation of the IArtifactHandler, which handles artifacts of type BenchmarkDefinitionArtifactType.
...
import org.eclipse.stardust.engine.api.runtime.ArtifactType;
import org.eclipse.stardust.engine.api.runtime.DeployedRuntimeArtifact;
import org.eclipse.stardust.engine.api.runtime.RuntimeArtifact;
import org.eclipse.stardust.engine.core.benchmark.BenchmarkUtils;
import org.eclipse.stardust.engine.core.spi.artifact.IArtifactHandler;
/**
* This {@link IArtifactHandler} handles artifacts of type
* {@link BenchmarkDefinitionArtifactType}.
* <p>
* The handled artifacts are all of content type
* {@link BenchmarkDefinitionArtifactHandler#MIME_TYPE}.<br>
* Internal caches for benchmark definitions are flushed if a benchmark definition runtime
* artifact is overwritten or deleted.
*
* @author Roland.Stamm
*/
public class BenchmarkDefinitionArtifactHandler
implements IArtifactHandler, IArtifactHandler.Factory
{
public static final ArtifactType ARTIFACT_TYPE = new BenchmarkDefinitionArtifactType();
public static final String MIME_TYPE = "application/json";
@Override
public IArtifactHandler getInstance()
{
return new BenchmarkDefinitionArtifactHandler();
}
@Override
public ArtifactType getArtifactType()
{
return ARTIFACT_TYPE;
}
@Override
public String getArtifactContentType(RuntimeArtifact runtimeArtifact)
{
// all benchmarks are in json format.
return MIME_TYPE;
}
@Override
public RuntimeArtifact preProcess(RuntimeArtifact runtimeArtifact)
{
return runtimeArtifact;
}
@Override
public void afterOverwrite(DeployedRuntimeArtifact deployedRuntimeArtifact)
{
BenchmarkUtils.removeBenchmarkFromCache(deployedRuntimeArtifact.getOid());
}
@Override
public void beforeDelete(DeployedRuntimeArtifact deployedRuntimeArtifact)
{
ProcessInstanceQuery query = ProcessInstanceQuery.findAlive();
query.where(ProcessInstanceQuery.BENCHMARK_OID.greaterThan(0L));
ResultIterator rawResult = new ProcessInstanceQueryEvaluator(query, QueryServiceUtils.getDefaultEvaluationContext()).executeFetch();
if (rawResult.hasNext())
{
throw new IllegalOperationException(BpmRuntimeError.ATDB_RUNTIME_ARTIFACT_IN_USE.raise(deployedRuntimeArtifact.getOid()));
}
}
@Override
public void afterDelete(long oid)
{
BenchmarkUtils.removeBenchmarkFromCache(oid);
}
}