Package simtools.data.async

Examples of simtools.data.async.StreamingMSDataSource


         * @throws InvalidFormatException
         */
        public SourceCollection() throws IOException, InvalidFormatException {
            super();
            cc = new Container("root");
            StreamingMSDataSource ds1 = new StreamingMSDataSource("ds1", this, 200,_maxSize, 20000, 10,
                    20000, true, false, true, false);
            cc.addDataSource(ds1);
           
            map.put(DataInfo.getId(ds1), ds1);
            add(ds1);
           
            map.put(DataInfo.getId(ds1.getTime()), ds1.getTime());
            add(ds1.getTime());
         
            if (ds1.getTime2() != null) {
                map.put(DataInfo.getId(ds1.getTime2()), ds1.getTime2());
                add(ds1.getTime2());
            }
         
            if (ds1.getLabel() != null) {
                map.put(DataInfo.getId(ds1.getLabel()), ds1.getLabel());
                add(ds1.getLabel());
            }
        
            if (ds1.getStatus() != null) {
                map.put(DataInfo.getId(ds1.getStatus()), ds1.getStatus());
                add(ds1.getStatus());
            }
        
            if (ds1.getRaw() != null) {
                map.put(DataInfo.getId(ds1.getRaw()), ds1.getRaw());
                add(ds1.getRaw());
            }
           
           
            StreamingMSDataSource ds2 = new StreamingMSDataSource("ds2", this, 200,_maxSize,  20000, 10,
                    20000, true, false, true, false);
            cc.addDataSource(ds2);
         
            map.put(DataInfo.getId(ds2), ds2);
            add(ds2);
        
            map.put(DataInfo.getId(ds2.getTime()), ds2.getTime());
            add(ds2.getTime());
         
            if (ds2.getTime2() != null) {
                map.put(DataInfo.getId(ds2.getTime2()), ds2.getTime2());
                add(ds2.getTime2());
            }
         
            if (ds2.getLabel() != null) {
                map.put(DataInfo.getId(ds2.getLabel()), ds2.getLabel());
                add(ds2.getLabel());
            }
        
            if (ds2.getStatus() != null) {
                map.put(DataInfo.getId(ds2.getStatus()), ds2.getStatus());
                add(ds2.getStatus());
            }
         
            if (ds2.getRaw() != null) {
                map.put(DataInfo.getId(ds2.getRaw()), ds2.getRaw());
                add(ds2.getRaw());
            }
            Thread t = new Thread("StreamingMSDataPlugin") {
                public void run() {
                    int cpt = 0;
                    while (true) {
                        try {
                            Thread.sleep(400);
                            double t = System.currentTimeMillis();
                        
                            // update ds1
                            String label = "P";
                            if ((cpt % 4) == 0) {
                                label += "1";
                            }
                            if ((cpt % 4) == 1) {
                                label += "2";
                            }
                            if ((cpt % 4) == 2) {
                                label += "3";
                            }
                            if ((cpt % 4) == 3) {
                                label += "4";
                            }
                           
                            StreamingMSDataSource ds1 = (StreamingMSDataSource) get("ds1");
                            ds1.add(t, Math.sin(cpt / 100.), label, 0, (long) (Math.sin(cpt) * 4), 0);
                            // update ds2
                            String onOffError = "";
                            if ((cpt % 4) == 1) {
                                onOffError = "ON";
                            } else if ((cpt % 4) == 2) {
                                onOffError = "OFF";
                            } else {
                                onOffError = "ERROR";
                            }
                            if ((cpt % 4) == 3) {
                                label += "4";
                            }
                            StreamingMSDataSource ds2 = (StreamingMSDataSource) get("ds2");
                            ds2.add(t, Math.sin(cpt / 100.), onOffError, 0, (long) (Math.sin(cpt) * 4), 0);
                        } catch (InterruptedException ie) {
                        }
                        cpt++;
                    }
                }
View Full Code Here


    }

    protected void updateSMSvalues() {
        try {
            if (dataSource instanceof StreamingMSDataSource) {
                StreamingMSDataSource jds = (StreamingMSDataSource) dataSource;
                if (jds.getTime() != null) {
                    Number time = (Number) jds.getTime().getValue(jds.getLastIndex());
                    tfTime1.setText(TimeStampedDataSourceInformation.dateTimeFormatter
                            .format(new Date(time.longValue())));
                }
                if (jds.getTime2() != null) {
                    double time2 = jds.getTime2().getDoubleValue(jds.getLastIndex());
                    tfTime2.setText(String.valueOf(time2));
                }
                if (jds.getRaw() != null) {
                    Long raw = new Long(jds.getRaw().getLongValue(jds.getLastIndex()));
                    tfRaw.setText(String.valueOf(raw));
                }
                Object value = jds.getValue(jds.getLastIndex());
                tfPhysical.setText(value.toString());
                if (jds.getLabel() != null) {
                    String label = (String) jds.getLabel().getValue(jds.getLastIndex());
                    tfLabel.setText(String.valueOf(label));
                }
                if (jds.getStatus() != null) {
                    Integer valueNumber = new Integer(((Long) jds.getStatus().getValue(jds.getLastIndex())).intValue());
                    tfStatus.setText(valueNumber.toString());
                }
            }
        } catch (DataException e) {
        }
View Full Code Here

TOP

Related Classes of simtools.data.async.StreamingMSDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.