Information Technology Reference
In-Depth Information
public class KNN {
private int k;
private FileDataset dataset;
public KNN( int k){
this.k = k;
this.dataset = new
FileDataset();
}
public double
classifyInstance(Instance
instance) {...}
public double []classifyInstances
(Instance[] instances) {...}
public boolean
sameClass(Instance instA,
Instance instB) {...}
}
public class FileDataset {
public Instance[] readItems( int
rowStart, int rowEnd) {...}
public int size() {...}
public int dimensions() {...}
}
public KNN( int k) { this.k = k; }
public void
setdataset(DatasetService
injectedDataset) { this.dataset =
injectedDataset };
public DatasetService getdataset() {
return dataset; }
/** Classification methods */
...
}
Note that JGRIM added proper getter/setters for
interacting with the dataset. Besides, the resulting
source code is very clean, since it was not neces-
sary to use any JGRIM API class for gridification
purposes. Moreover, JGRIM generates an XML
configuration file:
<beans>
<bean id=”knnComponent” class=”KNN”>
<property name=”dataset”
ref=”datasetMetaService”/>
</bean>
<bean id=”datasetMetaService”
class=”jgrimapi.JGRIMServiceDiscov-
erer”>
<property name=”requiredInterface”
value=”DatasetService”/>
</bean>
</beans>
First, we must determine which classes ( KNN )
and interactions between components ( KNN
needs a data resource - the KNN - FileDataset
interaction) to gridify. Then, we have to separate
the implementation of the data resource from its
interface, and replace all accesses to dataset by
getDataset() . In the example, the valid operations
of dataset were defined in DatasetService . Finally,
we process the code with JGRIM, resulting in:
The XML file links application components
and JGRIM metaservices together through DI.
Here, KNN is decoupled from the dataset imple-
mentation by linking it --via the dataset property--
with a component that provides runtime Web
Service discovery. Currently, service discovery
is based on the inspection of UDDI registries
(Curbera et al., 2002). Consequently, KNN can use
any external dataset service of the Grid provided
it implements the DatasetService interface and is
published to a UDDI registry.
So far we have decoupled the storage mecha-
nism of the dataset from the KNN class. When the
public interface DatasetService {
public Instance[] readItems( int
rowStart, int rowEnd);
public int size();
public int dimensions();
}
public class KNN extends jgrimapi.
MGS {
private int k;
private DatasetService dataset;
Search WWH ::




Custom Search