use of com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription in project predix-machine-template-adapter-edison by PredixDev.
the class IntelBoardSubscriptionMachineAdapter method activate.
/*
* ############################################### # OSGi service lifecycle
* management # ###############################################
*/
/**
* OSGi component lifecycle activation method
*
* @param ctx
* component context
* @throws IOException
* on fail to load/set configuration properties
*/
@Activate
public void activate(ComponentContext ctx) throws IOException {
//$NON-NLS-1$
_logger.info("Starting sample " + ctx.getBundleContext().getBundle().getSymbolicName());
ObjectMapper mapper = new ObjectMapper();
File configFile = new File(MACHINE_HOME + File.separator + this.config.getNodeConfigFile());
this.configNodes = mapper.readValue(configFile, new TypeReference<List<JsonDataNode>>() {
});
createNodes(this.configNodes);
this.adapterInfo = new MachineAdapterInfo(this.config.getAdapterName(), IntelBoardSubscriptionMachineAdapter.SERVICE_PID, this.config.getAdapterDescription(), ctx.getBundleContext().getBundle().getVersion().toString());
List<String> subs = Arrays.asList(parseDataSubscriptions());
// Start data subscription and sign up for data updates.
for (String sub : subs) {
WorkshopDataSubscription dataSubscription = new WorkshopDataSubscription(this, sub, this.config.getUpdateInterval(), new ArrayList<PDataNode>(this.dataNodes.values()), spillway);
this.dataSubscriptions.put(dataSubscription.getId(), dataSubscription);
// Using internal listener, but these subscriptions can be used with
// Spillway listener also
dataSubscription.addDataSubscriptionListener(this.dataUpdateHandler);
new Thread(dataSubscription).start();
}
}
use of com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription in project predix-machine-template-adapter-edison by PredixDev.
the class IntelBoardSubscriptionMachineAdapter method addDataSubscription.
/*
* Adds new data subscription into the list.
*/
@Override
public synchronized UUID addDataSubscription(IDataSubscription subscription) throws MachineAdapterException {
if (subscription == null) {
//$NON-NLS-1$
throw new IllegalArgumentException("Subscription is null");
}
List<PDataNode> subscriptionNodes = new ArrayList<PDataNode>();
// Add new data subscription.
if (!this.dataSubscriptions.containsKey(subscription.getId())) {
// Make sure that new subscription contains valid nodes.
for (PDataNode node : subscription.getSubscriptionNodes()) {
if (!this.dataNodes.containsKey(node.getNodeId())) {
//$NON-NLS-1$
throw new MachineAdapterException("Node doesn't exist for this adapter");
}
subscriptionNodes.add(this.dataNodes.get(node.getNodeId()));
}
// Create new subscription.
WorkshopDataSubscription newSubscription = new WorkshopDataSubscription(this, subscription.getName(), subscription.getUpdateInterval(), subscriptionNodes, spillway);
this.dataSubscriptions.put(newSubscription.getId(), newSubscription);
new Thread(newSubscription).start();
return newSubscription.getId();
}
return null;
}
use of com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription in project predix-machine-template-adapter-edison by PredixDev.
the class IntelBoardSubscriptionMachineAdapter method deactivate.
/**
* OSGi component lifecycle deactivation method
*
* @param ctx
* component context
*/
@Deactivate
public void deactivate(ComponentContext ctx) {
// Put your clean up code here when container is shutting down
if (_logger.isDebugEnabled()) {
//$NON-NLS-1$
_logger.debug("Stopped sample for " + ctx.getBundleContext().getBundle().getSymbolicName());
}
Collection<WorkshopDataSubscription> values = this.dataSubscriptions.values();
// Stop random data generation thread.
for (WorkshopDataSubscription sub : values) {
sub.stop();
}
this.adapterState = MachineAdapterState.Stopped;
}
Aggregations