Package examples.async

Source Code of examples.async.StreamingMSDataPlugin

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2004, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: StreamingMSDataPlugin.java,v 1.5 2008/04/02 13:13:31 ogor Exp $
*
* Changes
* -------
* 11 jan. 2005 : Initial public release (CC);
*
*/
package examples.async;

import java.io.IOException;
import java.util.Collection;

import jsynoptic.base.Plugin;
import simtools.data.DataInfo;
import simtools.data.DataSourcePool;
import simtools.data.async.StreamingMSDataSource;
import simtools.data.async.StreamingTSDataSourceCollection;
import simtools.data.async.TimeStampedDataSourceCollection.InvalidFormatException;

/**
* A test/demo for streaming multi stamped data sources
*
* @author Ronan Ogor
*/
public class StreamingMSDataPlugin extends Plugin {
    static SourceCollection collection;
    static {
        try {
            collection = new SourceCollection();
            DataSourcePool.global.addDataSourceCollection(collection);
        } catch (IOException e) {
        } catch (InvalidFormatException e) {
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see jsynoptic.base.Plugin#getDataSourceIcons()
     */
    public Object[][] getDataSourceIcons() {
        Object[][] ret = new Object[2][2];
        ret[0][0] = StreamingMSDataPlugin.class;
        ret[0][1] = jsynoptic.ui.SourceTree.resources.getIcon("dynamicSourceIcon");
        ret[1][0] = SourceCollection.class;
        ret[1][1] = jsynoptic.ui.SourceTree.resources.getIcon("dynamicSourceCollectionIcon");
        return ret;
    }

    /**
     * Enter your plugin information here. This will appear in the about box.
     * Warning : uses HTML...
     *
     * @see jsynoptic.base.Plugin#about()
     */
    public String about() {
        return "Multi stamped sources, an example plugin provided by the JSynoptic team";
    }

    public static class SourceCollection extends StreamingTSDataSourceCollection {
       
        public static final String ID_MARKER = "TestStreamingMS:";
       
        Container cc;

        /**
         * @throws IOException
         * @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++;
                    }
                }
            };
            t.start();
        }

        /*
         * (non-Javadoc)
         *
         * @see simtools.data.DataSourceCollection#isCompound()
         */
        public boolean isCompound() {
            return true;
        }

       
        /* (non-Javadoc)
         * @see simtools.data.async.StreamingTSDataSourceCollection#getInformation()
         */
        public DataInfo getInformation() {
            DataInfo info = new DataInfo("TestMS", ID_MARKER + "Test");
            return info;
        }
       
        /*
         * (non-Javadoc)
         *
         * @see simtools.data.DataSourceCollection#getCollectionContainers()
         */
        public Collection getCollectionContainers() {
            return cc.getChildren();
        }
    }
}
TOP

Related Classes of examples.async.StreamingMSDataPlugin

TOP
Copyright © 2018 www.massapi.com. 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.