1
22
23 package com.liferay.portal.kernel.cluster;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.messaging.Message;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
37 public class ClusterLinkUtil {
38
39 public static Address getAddress(Message message) {
40 return (Address)message.get(_ADDRESS);
41 }
42
43 public static List<Address> getAddresses() {
44 if (_clusterLink == null) {
45 if (_log.isWarnEnabled()) {
46 _log.warn("ClusterLinkUtil has not been initialized");
47 }
48
49 return new ArrayList<Address>();
50 }
51
52 return _clusterLink.getAddresses();
53 }
54
55 public static ClusterLink getClusterLink() {
56 if (_clusterLink == null) {
57 if (_log.isWarnEnabled()) {
58 _log.warn("ClusterLinkUtil has not been initialized");
59 }
60
61 return null;
62 }
63
64 return _clusterLink;
65 }
66
67 public static boolean isForwardMessage(Message message) {
68 return message.getBoolean(_CLUSTER_FORWARD_MESSAGE);
69 }
70
71 public static void sendMulticastMessage(
72 Message message, Priority priority) {
73
74 if (_clusterLink == null) {
75 if (_log.isWarnEnabled()) {
76 _log.warn("ClusterLinkUtil has not been initialized");
77 }
78
79 return;
80 }
81
82 _clusterLink.sendMulticastMessage(message, priority);
83 }
84
85 public static void sendMulticastMessage(
86 Object payload, Priority priority) {
87
88 Message message = new Message();
89
90 message.setPayload(payload);
91
92 sendMulticastMessage(message, priority);
93 }
94
95 public static void sendUnicastMessage(
96 Address address, Message message, Priority priority) {
97
98 if (_clusterLink == null) {
99 if (_log.isWarnEnabled()) {
100 _log.warn("ClusterLinkUtil has not been initialized");
101 }
102
103 return;
104 }
105
106 _clusterLink.sendUnicastMessage(address, message, priority);
107 }
108
109 public static Message setAddress(Message message, Address address) {
110 message.put(_ADDRESS, address);
111
112 return message;
113 }
114
115 public static void setForwardMessage(Message message) {
116 message.put(_CLUSTER_FORWARD_MESSAGE, true);
117 }
118
119 public void setClusterLink(ClusterLink clusterLink) {
120 _clusterLink = clusterLink;
121 }
122
123 private static final String _ADDRESS = "CLUSTER_ADDRESS";
124
125 private static final String _CLUSTER_FORWARD_MESSAGE =
126 "CLUSTER_FORWARD_MESSAGE";
127
128 private static final Log _log =
129 LogFactoryUtil.getLog(ClusterLinkUtil.class);
130
131 private static ClusterLink _clusterLink;
132
133 }