static

in java/com/jetbrains/cef/remote/ThriftTransport.java [41:173]


    static {
        IS_TCP_USED = !Utils.getBoolean("CEF_SERVER_USE_PIPE");

        if (!Utils.getBoolean("DONT_JCEF_USE_UNIQUE_NAMES")) {
            final SimpleDateFormat f = new SimpleDateFormat("hh_mm_ss_SSS");
            SUFFIX = "_" + PID + "_" + f.format(new Date());
        } else
            SUFFIX = "_" + PID;

        if (IS_TCP_USED) {
            final int[] customPort = new int[]{Utils.getInteger("ALT_CEF_SERVER_PORT", -1)};
            if (MANUAL_SERVER_SELECT) {
                JTextField textField = new JTextField("", 10);
                JLabel label = new JLabel("Enter port");
                JPanel portComponent = new JPanel(new BorderLayout());
                portComponent.add(label,BorderLayout.WEST);
                portComponent.add(textField,BorderLayout.EAST);

                JPanel panel = new JPanel(new BorderLayout());
                panel.add(portComponent, BorderLayout.SOUTH);

                List<ProcessLister.RunningServerInfo> runningPorts = ProcessLister.listRunningInstancesPorts();
                if (runningPorts != null && !runningPorts.isEmpty()) {
                    // Fill list
                    String[] runningList = new String[runningPorts.size()];
                    int c = 0;
                    for (ProcessLister.RunningServerInfo s : runningPorts)
                        runningList[c++] = s.transport.myPort + ", parent: " + s.getParentProcessInfo();
                    JList<String> list = new JList<>(runningList);
                    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                    list.setFont(list.getFont().deriveFont(13f));
                    list.setVisibleRowCount(8);

                    list.addListSelectionListener(new ListSelectionListener() {
                        @Override
                        public void valueChanged(ListSelectionEvent e) {
                            final String selected = list.getSelectedValue().trim();
                            customPort[0] = Integer.parseInt(selected.substring(0, selected.indexOf(',')));
                            textField.setText(list.getSelectedValue());
                            CefLog.Debug("MANUAL_SERVER_SELECT: selected port %d", customPort[0]);
                        }
                    });

                    JScrollPane scrollPane = new JScrollPane(list);
                    scrollPane.setPreferredSize(new Dimension(400, 250));

                    panel.add(scrollPane, BorderLayout.CENTER);
                }

                JOptionPane.showMessageDialog(
                        null,
                        panel,
                        "Select running cef_server",
                        JOptionPane.PLAIN_MESSAGE
                );

                try {
                    customPort[0] = Integer.parseInt(textField.getText());
                } catch (NumberFormatException e) {}
            }
            if (customPort[0] == -1) {
                PORT_CEF_SERVER = findFreePort(null);
                if (PORT_CEF_SERVER == -1)
                    CefLog.Error("Can't find free tcp-port for server.");
                else
                    CefLog.Info("Found free tcp-port %d for server.", PORT_CEF_SERVER);
            } else {
                CefLog.Info("Use custom tcp-port %d for server.", customPort[0]);
                PORT_CEF_SERVER = customPort[0];
            }

            customPort[0] = Utils.getInteger("ALT_JAVA_HANDLERS_PORT", -1);
            if (customPort[0] == -1) {
                Set<Integer> exclude = new HashSet<>(); exclude.add(PORT_CEF_SERVER);
                PORT_JAVA_HANDLERS = findFreePort(exclude);
                if (PORT_JAVA_HANDLERS == -1)
                    CefLog.Error("Can't find free tcp-port for java-handlers.");
                else
                    CefLog.Info("Found free tcp-port %d for java-handlers.", PORT_JAVA_HANDLERS);
            } else {
                CefLog.Info("Use custom tcp-port %d for java-handlers.", customPort[0]);
                PORT_JAVA_HANDLERS = customPort[0];
            }

            ourDefaultServer = new ThriftTransport(getServerPort());
            ourDefaultClient = new ThriftTransport(getJavaHandlersPort());

            PIPENAME_JAVA_HANDLERS = "";
            PIPENAME_CEF_SERVER = "";
        } else {
            PORT_CEF_SERVER = 0;
            PORT_JAVA_HANDLERS = 0;

            final String pipeServerDefault = "cef_server_pipe";
            final String pipeServerCustom = Utils.getString("ALT_CEF_SERVER_PIPE");
            final String suffixServer;
            if (pipeServerCustom == null || pipeServerCustom.isEmpty()) {
                PIPENAME_CEF_SERVER = pipeServerDefault;
                suffixServer = SUFFIX;
            } else {
                PIPENAME_CEF_SERVER = pipeServerCustom;
                suffixServer = "";
            }

            String pipeJavaDefault = "client_pipe";
            String pipeJavaCustom = Utils.getString("ALT_JAVA_HANDLERS_PIPE");
            final String suffixJava;
            if (pipeJavaCustom == null || pipeJavaCustom.isEmpty()) {
                PIPENAME_JAVA_HANDLERS = pipeJavaDefault;
                suffixJava = SUFFIX;
            } else {
                PIPENAME_JAVA_HANDLERS = pipeJavaCustom;
                suffixJava = "";
            }

            String pipe;
            if (OS.isWindows())
                pipe = PIPENAME_CEF_SERVER + suffixServer;
            else {
                pipe = PIPE_DIR.resolve(PIPENAME_CEF_SERVER + suffixServer).toString();
                pipe = normalizePipeName(pipe);
            }
            ourDefaultServer = new ThriftTransport(pipe);

            if (OS.isWindows())
                pipe = PIPENAME_JAVA_HANDLERS + suffixJava;
            else {
                pipe = PIPE_DIR.resolve(PIPENAME_JAVA_HANDLERS + suffixJava).toString();
                pipe = normalizePipeName(pipe);
            }
            ourDefaultClient = new ThriftTransport(pipe);
        }
    }