@Documented @Retention(value=RUNTIME) @Target(value={METHOD,FIELD}) public @interface GridUserResource
You can inject other resources into your user resource. The following grid resources can be injected:
GridLoggerResourceGridLocalNodeIdResourceGridHomeResourceGridNameResourceGridMBeanServerResourceGridExecutorServiceResourceGridMarshallerResourceGridSpringApplicationContextResourceGridSpringResourceGridInstanceResource
resourceClass() value. If
If resourceClass is not specified, then field type or setter parameter
type will be used to infer the class type of the resource. Set resourceClass()
to a specific value if the class of resource cannot be inferred from field or setter
declaration (for example, if field is an interface).
GridUserResourceOnDeployed and GridUserResourceOnUndeployed
annotation for resource deployment and undeployment callbacks). For this
reason resources should not be sent to remote nodes and should
always be declared as transient just in case.
Note that an instance of user resource will be created for every deployed task.
In case if you need a singleton resource instances on grid nodes (not per-task),
you can use GridSpringApplicationContextResource for injecting per-VM
singleton resources configured in Spring.
public class MyGridJob implements GridComputeJob {
...
@GridUserResource
private transient MyUserResource rsrc;
...
}
or
public class MyGridJob implements GridComputeJob {
...
private transient MyUserResource rsrc;
...
@GridUserResource
public void setMyUserResource(MyUserResource rsrc) {
this.rsrc = rsrc;
}
...
}
where resource class can look like this:
public class MyUserResource {
...
// Inject logger (or any other resource).
@GridLoggerResource
private GridLogger log;
// Inject grid instance (or any other resource).
@GridInstanceResource
private Grid grid;
// Deployment callback.
@GridUserResourceOnDeployed
public void deploy() {
// Some initialization logic.
...
}
// Undeployment callback.
@GridUserResourceOnUndeployed
public void undeploy() {
// Some clean up logic.
...
}
}
| Modifier and Type | Optional Element and Description |
|---|---|
Class<?> |
resourceClass
Optional resource class.
|
String |
resourceName
Optional resource name.
|
public abstract Class<?> resourceClass
public abstract String resourceName
"dfltName" values will be used.Copyright © 2014. All rights reserved.