Search in sources :

Example 1 with JsonDataNode

use of com.ge.predix.solsvc.workshop.config.JsonDataNode 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();
    }
}
Also used : PDataNode(com.ge.dspmicro.machinegateway.types.PDataNode) JsonDataNode(com.ge.predix.solsvc.workshop.config.JsonDataNode) WorkshopDataSubscription(com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription) TypeReference(org.codehaus.jackson.type.TypeReference) MachineAdapterInfo(com.ge.dspmicro.machinegateway.api.adapter.MachineAdapterInfo) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Activate(aQute.bnd.annotation.component.Activate)

Example 2 with JsonDataNode

use of com.ge.predix.solsvc.workshop.config.JsonDataNode in project predix-machine-template-adapter-edison by PredixDev.

the class IntelBoardSubscriptionMachineAdapter method createNodes.

/*
	 * ##################################### # Private methods #
	 * #####################################
	 */
/**
	 * Generates random nodes
	 * 
	 * @param count
	 *            of nodes
	 */
private void createNodes(List<JsonDataNode> nodes) {
    for (JsonDataNode jsonNode : nodes) {
        _logger.info("Creating Node : " + jsonNode.getNodeName() + " Pin : " + jsonNode.getNodePin());
        WorkshopDataNodeIntel node = new WorkshopDataNodeIntel(this.uuid, jsonNode);
        // Create a new node and put it in the cache.
        this.dataNodes.put(node.getNodeId(), node);
    }
}
Also used : JsonDataNode(com.ge.predix.solsvc.workshop.config.JsonDataNode) WorkshopDataNodeIntel(com.ge.predix.solsvc.workshop.types.WorkshopDataNodeIntel)

Aggregations

JsonDataNode (com.ge.predix.solsvc.workshop.config.JsonDataNode)2 Activate (aQute.bnd.annotation.component.Activate)1 MachineAdapterInfo (com.ge.dspmicro.machinegateway.api.adapter.MachineAdapterInfo)1 PDataNode (com.ge.dspmicro.machinegateway.types.PDataNode)1 WorkshopDataNodeIntel (com.ge.predix.solsvc.workshop.types.WorkshopDataNodeIntel)1 WorkshopDataSubscription (com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription)1 File (java.io.File)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 TypeReference (org.codehaus.jackson.type.TypeReference)1