Search in sources :

Example 1 with PDataNode

use of com.ge.dspmicro.machinegateway.types.PDataNode 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 PDataNode

use of com.ge.dspmicro.machinegateway.types.PDataNode 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;
}
Also used : PDataNode(com.ge.dspmicro.machinegateway.types.PDataNode) WorkshopDataSubscription(com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription) ArrayList(java.util.ArrayList) MachineAdapterException(com.ge.dspmicro.machinegateway.api.adapter.MachineAdapterException)

Example 3 with PDataNode

use of com.ge.dspmicro.machinegateway.types.PDataNode in project predix-machine-template-adapter-edison by PredixDev.

the class WorkshopDataSubscription method run.

/**
	 * Thread to generate random data for the nodes in this subscription.
	 */
@Override
public void run() {
    if (!this.threadRunning.get() && this.adapter.getNodes().size() > 0) {
        this.threadRunning.set(true);
        while (this.threadRunning.get()) {
            // Generate random data for each node and push data update.
            List<ITransferable> dataList = new ArrayList<ITransferable>();
            for (PDataNode node : this.adapter.getNodes()) {
                WorkshopDataNodeIntel wNode = (WorkshopDataNodeIntel) node;
                if ("IN".equals(wNode.getNodePinDir())) {
                    //$NON-NLS-1$
                    dataList.add(this.adapter.readData(node.getNodeId()));
                }
            }
            spillway.processAndTransferData(dataList);
            try {
                // Wait for an updateInterval period before pushing next
                // data update.
                Thread.sleep(this.updateInterval);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : PDataNode(com.ge.dspmicro.machinegateway.types.PDataNode) ITransferable(com.ge.dspmicro.machinegateway.types.ITransferable) ArrayList(java.util.ArrayList)

Aggregations

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