<commit_before>/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.pods.web;

import org.diirt.web.pods.common.MessageValueEvent;
import org.diirt.web.pods.common.MessageConnectionEvent;
import org.diirt.web.pods.common.Message;
import org.diirt.web.pods.common.MessageWriteCompletedEvent;
import org.diirt.web.pods.common.MessageWrite;
import org.diirt.web.pods.common.MessageSubscribe;
import org.diirt.web.pods.common.MessageDecoder;
import org.diirt.web.pods.common.MessageErrorEvent;
import org.diirt.web.pods.common.MessageUnsubscribe;
import org.diirt.web.pods.common.MessageEncoder;
import org.diirt.web.pods.common.MessageResume;
import org.diirt.web.pods.common.MessagePause;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.CloseReason;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.diirt.pods.common.ChannelTranslation;
import org.diirt.pods.common.ChannelTranslator;
import org.epics.util.config.Configuration;
import org.epics.pvmanager.CompositeDataSource;
import org.epics.pvmanager.PVManager;
import org.epics.pvmanager.PVReader;
import org.epics.pvmanager.PV;
import org.epics.pvmanager.PVReaderEvent;
import org.epics.pvmanager.PVReaderListener;
import org.epics.pvmanager.PVWriter;
import org.epics.pvmanager.PVWriterEvent;
import org.epics.pvmanager.PVWriterListener;
import static org.epics.pvmanager.formula.ExpressionLanguage.*;
import org.epics.pvmanager.loc.LocalDataSource;
import org.epics.pvmanager.sim.SimulationDataSource;
import org.epics.util.time.TimeDuration;

/**
 *
 * @author carcassi
 */
@ServerEndpoint(value = "/socket", encoders = {MessageEncoder.class}, decoders = {MessageDecoder.class})
public class WSEndpoint {
    
    // TODO: understand lifecycle of whole web application and put
    // configuration there, including closing datasources.
    static {
        CompositeDataSource datasource = new CompositeDataSource();
        datasource.putDataSource("sim", new SimulationDataSource());
        datasource.putDataSource("loc", new LocalDataSource());
        PVManager.setDefaultDataSource(datasource);
        
        ChannelTranslator temp = null;
        try (InputStream input = Configuration.getFileAsStream("pods/web/mappings.xml", new WSEndpoint(), "mappings.default.xml")) {
            temp = ChannelTranslator.loadTranslator(input);
        } catch (Exception ex) {
            Logger.getLogger(WSEndpoint.class.getName()).log(Level.SEVERE, "Couldn't load DIIRT_HOME/pods/web/mappings", ex);
        }
        channelTranslator = temp;
    }
    
    private static Logger log = Logger.getLogger(WSEndpoint.class.getName());<commit_msg>web-pods-datasource: adding file datasource<commit_after>/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.pods.web;

import org.diirt.web.pods.common.MessageValueEvent;
import org.diirt.web.pods.common.MessageConnectionEvent;
import org.diirt.web.pods.common.Message;
import org.diirt.web.pods.common.MessageWriteCompletedEvent;
import org.diirt.web.pods.common.MessageWrite;
import org.diirt.web.pods.common.MessageSubscribe;
import org.diirt.web.pods.common.MessageDecoder;
import org.diirt.web.pods.common.MessageErrorEvent;
import org.diirt.web.pods.common.MessageUnsubscribe;
import org.diirt.web.pods.common.MessageEncoder;
import org.diirt.web.pods.common.MessageResume;
import org.diirt.web.pods.common.MessagePause;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.CloseReason;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.diirt.pods.common.ChannelTranslation;
import org.diirt.pods.common.ChannelTranslator;
import org.epics.util.config.Configuration;
import org.epics.pvmanager.CompositeDataSource;
import org.epics.pvmanager.PVManager;
import org.epics.pvmanager.PVReader;
import org.epics.pvmanager.PV;
import org.epics.pvmanager.PVReaderEvent;
import org.epics.pvmanager.PVReaderListener;
import org.epics.pvmanager.PVWriter;
import org.epics.pvmanager.PVWriterEvent;
import org.epics.pvmanager.PVWriterListener;
import org.epics.pvmanager.file.FileDataSource;
import static org.epics.pvmanager.formula.ExpressionLanguage.*;
import org.epics.pvmanager.loc.LocalDataSource;
import org.epics.pvmanager.sim.SimulationDataSource;
import org.epics.util.time.TimeDuration;

/**
 *
 * @author carcassi
 */
@ServerEndpoint(value = "/socket", encoders = {MessageEncoder.class}, decoders = {MessageDecoder.class})
public class WSEndpoint {
    
    // TODO: understand lifecycle of whole web application and put
    // configuration there, including closing datasources.
    static {
        CompositeDataSource datasource = new CompositeDataSource();
        datasource.putDataSource("sim", new SimulationDataSource());
        datasource.putDataSource("loc", new LocalDataSource());
        datasource.putDataSource("file", new FileDataSource());
        PVManager.setDefaultDataSource(datasource);
        
        ChannelTranslator temp = null;
        try (InputStream input = Configuration.getFileAsStream("pods/web/mappings.xml", new WSEndpoint(), "mappings.default.xml")) {
            temp = ChannelTranslator.loadTranslator(input);
        } catch (Exception ex) {
            Logger.getLogger(WSEndpoint.class.getName()).log(Level.SEVERE, "Couldn't load DIIRT_HOME/pods/web/mappings", ex);
        }
        channelTranslator = temp;
    }
    
    private static Logger log = Logger.getLogger(WSEndpoint.class.getName());
{'fraction_non_alphanumeric': 0.1096, 'fraction_numerical': 0.00192, 'mean_word_length': 4.842056074766355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825163', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1890, 'n_words': 343}