multithreading – What is the best way to decouple and define the orchestration (coordination) of concurrent tasks?

I have a data synchronisation concurrent algorithm. It does the following: get data and files from server, send data and files to server, save them to database / filesystem. Imagine the system like this:

  1. You have 1000 functions. Each one does some atomic operation. For instance, fetch latest objects of type X and insert them into DB; upload this file of type Y and so on. Each function is independent and can act on its own, it does not communicate with or affect other functions. On the other hand, none of them is a pure function, because they all use theese common resources (fetching data from the server, puting data on DB, saving files on filesystem)
  2. You have a single entry point for the sychronization mechanism. The outside of the sync system can start the sync, say, by doing a Sync.start() call. Also, the sync has a single exit point. The sync can finish with either success, either failure (if any of those functions from (1) fail, the whole sync will fail). The ouside of the sync system can subscribe to onSyncSuccess / onSyncError events.
  3. You have this black box in the middle of the system. This could be, for instance, a single threaded algorithm calling those 1000 functions from (1). But I made it concurrent.

Now consider this. This concurrent algorithm right now is rigid because the way in which the functions are called is hardcoded. If I want to take a bunch of functions from (1) that right now are executing sequentially, and if I want to make them execute parallel, it would be impossible without refactoring the whole class hierarchy.

I was thinking about the concept of direct acyclic graphs, and I made my own domain-specific language in Kotlin to define such task graphs. Now I could write the whole orchestration declaratively like this:

notifySyncWasStarted()
runSequentialy {
    task { doTask1() }
    runInParallel {
        task { doTask2() }
        task { doTask3() }
    }
    task { doTask4() }
}
notifySyncWasStopped()

So first task1 gets executed, then task2 and 3 in the same time, then task4. By keeping this graph in a single file, I could easily modify the way tasks are executed. For instance, I could easily swap tasks:

notifySyncWasStarted()
runSequentialy {
    runInParallel {
        task { doTask4() }
        task { doTask2() }
    }
    task { doTask3() }
    task { doTask1() }
}
notifySyncWasStopped()

Here, (task 4 and 2) gets executed, then 3, then 1. This works by using the fork-join paradigm, I create threads then join them into the parent thread.

In contrast, right now, the algorithm is spread around multiple classes, each of them was designed to run the tasks in a specific manner. Changing how tasks are ran would mean to refactor the classes and how they communicate to each other.

The question is: What is the best way to decouple and define the orchestration (coordination) of concurrent tasks? So that this orchestration could be easily changed in the future? Is my solution optimal or the way to go (direct acyclic graphs, fork-join, plus a domain specific language)? Or maybe there are some other design patterns that do the same thing?

Buying Bitcoins: Does Tether Decouple Demand From Price?

So I don't understand how Tether (USDT) works. I hear two contradictory things about it. First, it is pegged to the dollar, plus or minus a few cents here and there. Second, that you can freely buy or sell from other cryptos.

BUT, generally, when many people buy a crypto, its price will increase. But the tie seems to somehow decouple the demand from the price. I thought that was impossible?

design patterns: how can I decouple my container API from its underlying SOAP implementation?

In our current architecture, a user has multiple ways in which he can change an address (as an example). They can do it through an online portal, through our central processor directly or through a series of applications that communicate with the central processor. I want to design a solution that has a place for all those users to channel, and a place for business logic, instead of half a dozen. I am writing a container API (RESTful) that abstracts the SOAP API from our core processor for ease of use. The reason for the abstraction is because we use a primitive proprietary programming language that does not generate XML as easily as you can simply call a URL.

I am evaluating third-party proxy layers like Mulesoft for this, but I am also investigating solutions that allow business logic to be placed in the RESTful API before I call the core processor. We also want to plan the possibility of the central processor eventually changing, and the SOAP API could be replaced by something else. What design pattern (if any) would you use to decouple the API interface of the underlying SOAP API and the core processor so that if we need to change the backup API to a completely different API that provides similar data and maybe use a mechanism different transport, the external API would not have to change?

I think it would be the adapter pattern or the bridge pattern, but I don't have much experience in SOLID or design patterns and I'm not sure which one would apply (if applicable). I know that the bridge pattern is for an initial design, while the adapter pattern is later. They seem to me both.

Or is it just a control investment at work?

java – How can I refactor this code and decouple the method?

I have a set of entities (templates)

enter the description of the image here

I need to clone this complete set and create the same set with new IDs.

I have 3 methods like this (Entity One is User):

private Map createUsers() {
            Map userIds = new HashMap<>();
            Iterator users = userService.findAllUsers();
            while (users.hasNext()) {
                User user = users.next();
                String oldId = user.getId();
                user.setId(generateNewId());
                user.setName(generateNewName());
                userService.saveUser(user);
                userIds.put(oldId, user.getId());
            }
            return userIds;
        }

And two similar methods (entity two is the person and entity three is the book). In each method, I create a new entity and store old and new IDS. After that, I clone the Orders and re-link the old and the new identification. I do it like this:

       if (userIds.containsKey(order.getUserId())) {
            order.setUserId(userIds.get(order.getUserId()));
        }

        if (personIds.containsKey(order.getPersonId())) {
            order.setPersonId(personIds.get(order.getPersonId()));
        }

This structure is ugly and I want to refactor it. But I have no ideas.

nautilus – How to decouple an application from a file type icon

Some softwares associate a specific icon with a file type (for example, when installing Mathematica, all * .nb files have a new icon). Sometimes, this can cause minor inconvenience for generic file types such as * .dat, since a program can associate its icon with the dat file type, even if most dat files don't really have anything to do with the program. There also seems to be some precedence problems in which some applications override the default icon of a theme but some applications do not, which I do not understand.

I tried to reset the default application in vain. I am also aware of the question: How do I change the icon of a particular file type? but I'm not sure how the answers there help with my problem. Any suggestions?

Object-oriented: use of friend functions to decouple / ensure encapsulation

For my project, I have a configuration class that will contain all the global settings for the project. This class is constantly subject to change (adding more configuration parameters) and I did not want to expose all its member variables, so I decided to make the member variables private. Since member variables are private to access them, you would need to provide procurement functions for all member variables or provide friend functions that will be responsible for obtaining class data for different class types. I have written and an example of how I would think the latter would be.

// configuration.h
#ifndef CONFIGUATION_H
#define CONFIGUATION_H

class A;
class B;

class Configuration {
    Configuration(){};
    static const int a_config_x;
    static const int a_config_y;
    static const int a_config_z;
    static const int b_config_x;
    static const int b_config_y;
    static const int b_config_z;
public: 
    friend void load(Configuration&, A&);
    friend void load(Configuration&, B&);
    static Configuration& get_instance() {
        static Configuration inst;
        return inst;
    }
};
#endif


// configuration.cpp
#include "configuration.h"
const int Configuration::a_config_x = 0;
const int Configuration::a_config_y = 1;
const int Configuration::a_config_z = 2;
const int Configuration::b_config_x = 3;
const int Configuration::b_config_y = 4;
const int Configuration::b_config_z = 5;

As you can see for the configuration class, I made a friendly function, load, which will take a reference from a configuration class and for each type that wants to have its data members set

// example classes with private data members 
#ifndef CLASS_A_B_H
#define CLASS_A_B_H
class Configuration;

class A {
    int x;
    int y;
    int z;
    friend void load(Configuration&, A&);

public:
    A(): x(0), y(0), z(0) {};
};

class B {
    int x;
    int y;
    int z;
    friend void load(Configuration&, B&);

public:
    B(): x(0), y(0), z(0) {};
};

#endif
// load_function.h
#ifndef LOAD_FUNCTIONS_H
#define LOAD_FUNCTIONS_H
class A;
class B;
class Configuration;
void load(A& a);
void load(B& b);
void load(Configuration& c, A& a);
void load(Configuration& c, B& b);

#endif


// load_function.cpp
#include "load_functions.h"
#include "configuration.h"
#include "class_a_b.h"
#include 


void load(A& a) {
    load(Configuration::get_instance(), a);
};

void load(B& b) {
    load(Configuration::get_instance(), b);
};

void load(Configuration& c, A& a) {
    a.x = c.a_config_x;
    a.y = c.a_config_y;
    a.z = c.a_config_z;
};

void load(Configuration& c, B& b) {
    b.x = c.b_config_x;
    b.y = c.b_config_y;
    b.z = c.b_config_z;
};

An example of a use case would be:

#include "class_a_b.h"
#include "load_functions.h"
#include "configuration.h"

int main()
{
    A a_inst;
    B b_inst;
    load(a_inst);
    load(b_inst);

    return 0;
}

Essentially I didn't want to load classes A and B with having to know how to interact with the Configuration class and vice versa. I hope to receive some constructive criticism about these design options.
What are the best approaches to something like this? Is this an applicable case to use friend functions? Should I simply move the implementation of friend functions to class A, B … ect?