Flink 1.5具有broadcast()
和partitionCustom()
方法,可以将元素发送到所有或只有一个分区。
是否可以将元素发送到两个或更多分区,但不能发送给所有分区?
它是否会在API中得到支持?
答案 0 :(得分:2)
恐怕没有直接支持这种情况。但是,通过为单个输入元素发出多个结果,您可以使用#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/un.h>
#define PATH "/tmp/Server"
int main() {
pid_t proc1, proc2;
proc1 = fork();
if(proc1 == -1) {
printf("Errore nella prima fork\n");
exit(0);
}
if(proc1 != 0) {
//PADRE DOPO IL PRIMO FIGLIO
//Lo stesso procedimento si fa per il secondo figlio
proc2 = fork();
if(proc2 == -1) {
printf("Errore nella prima fork\n");
exit(0);
}
wait(NULL); //Attesa che UN figlio termini
if(proc2 != 0) {
//PADRE DOPO I DUE FIGLI
unlink(PATH);
int father_desc = socket(PF_UNIX, SOCK_STREAM, 0);
int son1_desc;
struct sockaddr_un father_add = {AF_UNIX, PATH};
struct sockaddr_un son1_add;
if(-1 == bind(father_desc, (struct sockaddr*)&father_add, sizeof(struct sockaddr))) {
perror("Errore nel bind");
close(father_desc);
close(son1_desc);
wait(NULL);
exit(0);
}
if(-1 == listen(father_desc, 2)) {
perror("Errore nel listen");
close(father_desc);
close(son1_desc);
wait(NULL);
exit(0);
}
int len = sizeof(son1_add);
son1_desc = accept(father_desc, (struct sockaddr*)&son1_add, &len);
if(-1 == son1_desc) {
perror("Errore nell'accept");
close(father_desc);
close(son1_desc);
wait(NULL);
exit(0);
}
char message[256] = "Ciao";
if(-1 == send(father_desc, message, strlen(message) + 1, 0)) {
perror("Errore nel send"); /* -> ERROR HERE */
close(father_desc);
close(son1_desc);
wait(NULL);
exit(0);
}
close(father_desc);
close(son1_desc);
wait(NULL);
} else {
//SECONDO FIGLIO
}
} else {
//PRIMO FIGLIO
sleep(1);
struct sockaddr_un son1_add = {AF_UNIX, PATH};
int son1_desc = socket(PF_UNIX, SOCK_STREAM, 0);
if(-1 == connect(son1_desc, (struct sockaddr*) &son1_add, sizeof(struct sockaddr))) {
perror("Errore nel connect");
shutdown(son1_desc, SHUT_RDWR);
close(son1_desc);
exit(0);
}
char message[256] = "";
if(-1 == recv(son1_desc, message, strlen(message) + 1, 0)) {
perror("Errore nel rcv");
shutdown(son1_desc, SHUT_RDWR);
close(son1_desc);
wait(NULL);
exit(0);
}
printf("%s\n", message);
shutdown(son1_desc, SHUT_RDWR);
close(son1_desc);
}
return 0;
}
函数轻松实现它。
E.g。
flatMap