Package simtools.data.async

Source Code of simtools.data.async.StreamingTSDataSourceCollection

/* ========================
* 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: StreamingTSDataSourceCollection.java,v 1.11 2007/11/08 14:37:39 ogor Exp $
*
* Changes
* -------
* 11 jan. 2005 : Initial public release (CC);
*
*/
package simtools.data.async;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

import simtools.data.DataException;
import simtools.data.DataInfo;

/**
* A streaming time stamped data source collection to handle a list of streaming
* time stamped data source coming from one data stream
*
* @author Claude Cazenave
*/
public abstract class StreamingTSDataSourceCollection extends TimeStampedDataSourceCollection {
    public static final String ID_MARKER = "StreamingTS:";

    /**
     * The default minimum duration (see StreamingTSDataSource._minDuration)
     */
    protected double _minDuration = 10000;

    /**
     * The default initial buffer size
     */
    protected int _minSize = 256;
   
    /**
     * The max buffer size
     */
    protected int _maxSize = Integer.MAX_VALUE;
   

    /**
     * @param start
     * @param end
     * @throws IOException
     * @throws InvalidFormatException
     */
    public StreamingTSDataSourceCollection(Date start, Date end) throws IOException, InvalidFormatException {
        super(start, end);
        map = new HashMap();
    }

    /**
     * @throws IOException
     * @throws InvalidFormatException
     */
    public StreamingTSDataSourceCollection() throws IOException, InvalidFormatException {
        super();
        map = new HashMap();
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.data.DataSourceCollection#getValue(int, long)
     */
    public Object getValue(int i, long index) throws DataException {
        return ((TimeStampedDataSource) get(i)).getValue(index);
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.data.DataSourceCollection#getDoubleValue(int, long)
     */
    public double getDoubleValue(int i, long index) throws DataException {
        return ((TimeStampedDataSource) get(i)).getDoubleValue(index);
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.data.DataSourceCollection#getInformation()
     */
    public DataInfo getInformation() {
        DataInfo info = new DataInfo("Test", ID_MARKER + "Test");
        return info;
    }

    protected void add(String data, double t, double v) {
        add(data, t, v, t, false);
    }

    protected void add(String data, double t, double v, double t2) {
        add(data, t, v, t2, true);
    }

    protected void add(String data, double t, double v, double t2, boolean isTime2Enabled) {
        // get id accodring to data or create new datasource
        StreamingTSDataSource ds = (StreamingTSDataSource) get(data);
        if (ds == null) {
            try {
                ds = new StreamingTSDataSource(data, data, this, _minSize, _maxSize, _minDuration, isTime2Enabled);
             
                map.put(DataInfo.getId(ds), ds);
                add(ds);
              
                map.put(DataInfo.getId(ds.getTime()), ds.getTime());
                add(ds.getTime());
               
                if (ds.getTime2() != null) {
                    map.put(DataInfo.getId(ds.getTime2()), ds.getTime2());
                    add(ds.getTime2());
                }
            } catch (IOException e) {
            } catch (InvalidFormatException e) {
            }
        }
        if (ds != null) {
            ds.add(t, v, t2);
        }
    }
}
TOP

Related Classes of simtools.data.async.StreamingTSDataSourceCollection

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.