<commit_before>package org.helioviewer.jhv.plugins.samp;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import org.astrogrid.samp.Message;
import org.astrogrid.samp.Metadata;
import org.astrogrid.samp.client.AbstractMessageHandler;
import org.astrogrid.samp.client.ClientProfile;
import org.astrogrid.samp.client.HubConnection;
import org.astrogrid.samp.client.HubConnector;
import org.astrogrid.samp.hub.Hub;
import org.astrogrid.samp.hub.HubServiceMode;
import org.helioviewer.jhv.JHVGlobals;
import org.helioviewer.jhv.io.LoadURITask;
import org.helioviewer.jhv.layers.ImageLayer;
import org.helioviewer.jhv.layers.Layers;

class SampClient extends HubConnector {

    private final static String MTYPE_VIEW_DATA = "jhv.vso.load";

    SampClient(ClientProfile _profile) {
        super(_profile);

        Hub[] runningHubs = Hub.getRunningHubs();
        if (runningHubs.length == 0) {
            try {
                Hub.checkExternalHubAvailability();
                Hub.runExternalHub(HubServiceMode.CLIENT_GUI);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        Metadata meta = new Metadata();
        // TODO: name / description
        meta.setName("JHelioviewer");
        meta.setDescriptionText(JHVGlobals.userAgent);
        declareMetadata(meta);

        addMessageHandler(new AbstractMessageHandler("image.load.fits") {
            public Map<?,?> processCall(HubConnection c, String senderId, Message msg) {
                try {
                    URI uri = new URI(msg.getParam("url").toString());
                    JHVGlobals.getExecutorService().execute(new LoadURITask(ImageLayer.createImageLayer(null), uri));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
        declareSubscriptions(computeSubscriptions());

        setAutoconnect(10);
    }

    void notifyRequestData() {
        Message msg = new Message(MTYPE_VIEW_DATA);
        // Layers.getSAMPMessage(msg);
        try {
            getConnection().notifyAll(msg);
        } catch (Exception e) {
            e.printStackTrace();<commit_msg>Get SSA to send us FITS<commit_after>package org.helioviewer.jhv.plugins.samp;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import org.astrogrid.samp.Message;
import org.astrogrid.samp.Metadata;
import org.astrogrid.samp.client.AbstractMessageHandler;
import org.astrogrid.samp.client.ClientProfile;
import org.astrogrid.samp.client.HubConnection;
import org.astrogrid.samp.client.HubConnector;
import org.astrogrid.samp.hub.Hub;
import org.astrogrid.samp.hub.HubServiceMode;
import org.helioviewer.jhv.JHVGlobals;
import org.helioviewer.jhv.io.LoadURITask;
import org.helioviewer.jhv.layers.ImageLayer;
import org.helioviewer.jhv.layers.Layers;

class SampClient extends HubConnector {

    private final static String MTYPE_VIEW_DATA = "jhv.vso.load";

    SampClient(ClientProfile _profile) {
        super(_profile);

        Hub[] runningHubs = Hub.getRunningHubs();
        if (runningHubs.length == 0) {
            try {
                Hub.checkExternalHubAvailability();
                Hub.runExternalHub(HubServiceMode.CLIENT_GUI);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        Metadata meta = new Metadata();
        // TODO: name / description
        meta.setName("JHelioviewer");
        meta.setDescriptionText(JHVGlobals.userAgent);
        declareMetadata(meta);

        addMessageHandler(new AbstractMessageHandler("image.load.fits") {
            @Override
            public Map<?,?> processCall(HubConnection c, String senderId, Message msg) {
                try {
                    openURI(msg.getParam("url").toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
        // lie about support for FITS tables to get SSA to send us FITS
        addMessageHandler(new AbstractMessageHandler("table.load.fits") {
            @Override
            public Map<?,?> processCall(HubConnection c, String senderId, Message msg) {
                try {
                    if ("SSA".equals(c.getMetadata(senderId).getName()))
                        openURI(msg.getParam("url").toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
        declareSubscriptions(computeSubscriptions());

        setAutoconnect(10);
    }

    private void openURI(String _uri) throws Exception {
        URI uri = new URI(_uri);
        JHVGlobals.getExecutorService().execute(new LoadURITask(ImageLayer.createImageLayer(null), uri));
    }

    void notifyRequestData() {
        Message msg = new Message(MTYPE_VIEW_DATA);
        // Layers.getSAMPMessage(msg);
        try {
            getConnection().notifyAll(msg);
        } catch (Exception e) {
            e.printStackTrace();
{'fraction_non_alphanumeric': 0.10569422776911076, 'fraction_numerical': 0.001170046801872075, 'mean_word_length': 2.317593790426908, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '8631', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1436, 'n_words': 260}