Search in sources :

Example 1 with ReplicatedData

use of com.almightyalpaca.jetbrains.plugins.discord.data.ReplicatedData in project Intellij-Discord-Integration by Almighty-Alpaca.

the class DiscordIntegrationApplicationComponent method initComponent.

@Override
public synchronized void initComponent() {
    try // Fixes problems that crashes JGroups if those two properties aren't properly set
    {
        Locale locale = Locale.getDefault();
        if (System.getProperty("user.language") == null)
            System.setProperty("user.language", locale.getLanguage());
        if (System.getProperty("user.country") == null)
            System.setProperty("user.country", locale.getCountry());
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        String props = "fast.xml";
        LOG.trace("DiscordIntegrationApplicationComponent#initComponent()#props = {}", props);
        JChannel channel = new JChannel(props);
        channel.setReceiver(this);
        this.channel = channel;
        channel.connect("JetbrainsDiscordIntegration v" + JetbrainsDiscordIntegration.PROTOCOL_VERSION);
        ReplicatedData data = new ReplicatedData(channel, this);
        this.data = data;
        this.instanceInfo = new InstanceInfo(channel.getAddressAsString(), ApplicationInfo.getInstance());
        LOG.trace("DiscordIntegrationApplicationComponent#initComponent()#this.instanceInfo = {}", this.instanceInfo);
        data.instanceAdd(System.currentTimeMillis(), this.instanceInfo);
        RPC.updatePresence(2, TimeUnit.SECONDS);
    } catch (Exception e) {
        if (this.channel != null) {
            this.channel.close();
            this.channel = null;
        }
        if (this.data != null) {
            this.data.close();
            this.data = null;
        }
        RPC.dispose();
        throw new RuntimeException(e);
    }
    MessageBus bus = ApplicationManager.getApplication().getMessageBus();
    connection = bus.connect();
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerListener());
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener());
    EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
    multicaster.addDocumentListener(this.documentListener = new DocumentListener());
    multicaster.addEditorMouseListener(this.editorMouseListener = new EditorMouseListener());
    checkExperiementalWindowListener();
    VirtualFileManager.getInstance().addVirtualFileListener(this.virtualFileListener = new VirtualFileListener());
}
Also used : Locale(java.util.Locale) JChannel(org.jgroups.JChannel) ReplicatedData(com.almightyalpaca.jetbrains.plugins.discord.data.ReplicatedData) EditorEventMulticaster(com.intellij.openapi.editor.event.EditorEventMulticaster) InstanceInfo(com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo) MessageBus(com.intellij.util.messages.MessageBus)

Aggregations

InstanceInfo (com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo)1 ReplicatedData (com.almightyalpaca.jetbrains.plugins.discord.data.ReplicatedData)1 EditorEventMulticaster (com.intellij.openapi.editor.event.EditorEventMulticaster)1 MessageBus (com.intellij.util.messages.MessageBus)1 Locale (java.util.Locale)1 JChannel (org.jgroups.JChannel)1