/
GMclient.java
59 lines (55 loc) · 2.27 KB
/
GMclient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chat.gearman.client;
import chat.model.valueobject.MessagePOJO;
import java.io.IOException;
import org.gearman.Gearman;
import org.gearman.GearmanClient;
import org.gearman.GearmanJobEvent;
import org.gearman.GearmanJobEventCallback;
import org.gearman.GearmanJoin;
import org.gearman.GearmanServer;
/**
*
* @author Thanhpv
* Create on 5:47:46 PM Dec 18, 2013
* GMclient of CHAT2-8001
*/
public class GMclient implements GearmanJobEventCallback<String> {
public static void run(byte[] content) throws InterruptedException, IOException, ClassNotFoundException {
// System.out.println("deserialize inside client");
// MessagePOJO message = (MessagePOJO) MessagePOJO.deserialize(content);
// System.out.println("message.Content inside client: " + message.getContent());
//create a gearman instance
Gearman gearman = Gearman.createGearman();
//create gearman GMclient
GearmanClient client = gearman.createGearmanClient();
//create job server
GearmanServer server = gearman.createGearmanServer("fresherchat.zapps.vn", 4730);
//
client.addServer(server);
GearmanJoin<String> join = client.submitJob(
"CHAT2_CHAT1", content,
"CHAT2_CHAT1", new GMclient());
join.join();
gearman.shutdown();
}
@Override
public void onEvent(String a, GearmanJobEvent gje) {
switch (gje.getEventType()) {
case GEARMAN_JOB_SUCCESS: // Job completed successfully
System.out.println("IN CLIENT - " + a);
System.out.println("IN CLIENT - the data received in Client1 from server: " + new String(gje.getData()));
break;
case GEARMAN_SUBMIT_FAIL: // The job submit operation failed
System.out.println("GEARMAN_SUBMIT_FAIL");
case GEARMAN_JOB_FAIL: // The job's execution failed
System.err.println(gje.getEventType() + ": "
+ new String(gje.getData()));
default:
}
}
}