18 package network.httppush;
20 import java.util.Scanner;
22 import ca.uqac.lif.cep.Connector;
23 import ca.uqac.lif.cep.ProcessorException;
24 import ca.uqac.lif.cep.functions.ApplyFunction;
25 import ca.uqac.lif.cep.http.HttpDownstreamGateway;
26 import ca.uqac.lif.cep.io.Print;
27 import ca.uqac.lif.cep.serialization.JsonDeserializeString;
28 import ca.uqac.lif.jerrydog.RequestCallback.Method;
44 @SuppressWarnings(
"resource")
47 public static void main(String[] args)
throws ProcessorException, InterruptedException
50 System.out.println(
"Hello, I am Machine B (downstream).");
51 System.out.print(
"Enter the port I should listen to: ");
52 Scanner sc =
new Scanner(System.in);
53 int port = sc.nextInt();
56 HttpDownstreamGateway dn_gateway =
new HttpDownstreamGateway(port,
"/push", Method.POST);
57 ApplyFunction deserialize =
new ApplyFunction(
new JsonDeserializeString<CompoundObject>(CompoundObject.class));
58 Print print =
new Print();
59 Connector.connect(dn_gateway, deserialize);
60 Connector.connect(deserialize, print);
66 System.out.println(
"The received objects will be displayed below. Press q to quit.");
69 String line = sc.nextLine();
70 if (line.startsWith(
"q") || line.startsWith(
"Q"))
81 protected static class CompoundObject
87 protected CompoundObject()
92 public CompoundObject(
int a, String b, CompoundObject c)
101 public boolean equals(Object o)
103 if (o == null || !(o instanceof CompoundObject))
107 CompoundObject co = (CompoundObject) o;
108 if (this.a != co.a ||
this.b.compareTo(co.b) != 0)
112 if ((this.c == null && co.c == null) || (this.c != null && co.c != null && this.c.equals(co.c)))
120 public String toString()
122 return "a = " + a +
", b = " + b +
", c = (" + c +
")";
This is the same example as PushLocalSerialize, but with the "Machine A" and "Machine B" parts of the...