001
014
015 package com.liferay.portal.kernel.messaging.proxy;
016
017 import com.liferay.portal.kernel.messaging.Message;
018 import com.liferay.portal.kernel.messaging.sender.SingleDestinationMessageSender;
019 import com.liferay.portal.kernel.messaging.sender.SingleDestinationMessageSenderFactoryUtil;
020 import com.liferay.portal.kernel.messaging.sender.SingleDestinationSynchronousMessageSender;
021 import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
022 import com.liferay.portal.kernel.util.Validator;
023
024
030 public abstract class BaseProxyBean {
031
032 public void afterPropertiesSet() {
033 if ((_singleDestinationSynchronousMessageSender == null) &&
034 Validator.isNotNull(_synchronousDestinationName)) {
035
036 _singleDestinationSynchronousMessageSender =
037 SingleDestinationMessageSenderFactoryUtil.
038 createSingleDestinationSynchronousMessageSender(
039 _synchronousDestinationName,
040 _synchronousMessageSenderMode);
041 }
042
043 if ((_singleDestinationMessageSender == null) &&
044 Validator.isNotNull(_destinationName)) {
045
046 _singleDestinationMessageSender =
047 SingleDestinationMessageSenderFactoryUtil.
048 createSingleDestinationMessageSender(_destinationName);
049 }
050 }
051
052 public void send(ProxyRequest proxyRequest) {
053 _singleDestinationMessageSender.send(buildMessage(proxyRequest));
054 }
055
056 public void setDestinationName(String destinationName) {
057 _destinationName = destinationName;
058 }
059
060
063 @Deprecated
064 public void setSingleDestinationMessageSender(
065 SingleDestinationMessageSender singleDestinationMessageSender) {
066
067 _singleDestinationMessageSender = singleDestinationMessageSender;
068 }
069
070
075 @Deprecated
076 public void setSingleDestinationSynchronousMessageSender(
077 SingleDestinationSynchronousMessageSender
078 singleDestinationSynchronousMessageSender) {
079
080 _singleDestinationSynchronousMessageSender =
081 singleDestinationSynchronousMessageSender;
082 }
083
084 public void setSynchronousDestinationName(
085 String synchronousDestinationName) {
086
087 _synchronousDestinationName = synchronousDestinationName;
088 }
089
090 public void setSynchronousMessageSenderMode(
091 SynchronousMessageSender.Mode synchronousMessageSenderMode) {
092
093 _synchronousMessageSenderMode = synchronousMessageSenderMode;
094 }
095
096 public Object synchronousSend(ProxyRequest proxyRequest) throws Exception {
097 ProxyResponse proxyResponse =
098 (ProxyResponse)_singleDestinationSynchronousMessageSender.send(
099 buildMessage(proxyRequest));
100
101 if (proxyResponse == null) {
102 return proxyRequest.execute(this);
103 }
104 else if (proxyResponse.hasError()) {
105 throw proxyResponse.getException();
106 }
107 else {
108 return proxyResponse.getResult();
109 }
110 }
111
112 protected Message buildMessage(ProxyRequest proxyRequest) {
113 Message message = new Message();
114
115 message.setPayload(proxyRequest);
116
117 MessageValuesThreadLocal.populateMessageFromThreadLocals(message);
118
119 if (proxyRequest.isLocal()) {
120 message.put(MessagingProxy.LOCAL_MESSAGE, Boolean.TRUE);
121 }
122
123 return message;
124 }
125
126 private String _destinationName;
127 private SingleDestinationMessageSender _singleDestinationMessageSender;
128 private SingleDestinationSynchronousMessageSender
129 _singleDestinationSynchronousMessageSender;
130 private String _synchronousDestinationName;
131 private SynchronousMessageSender.Mode _synchronousMessageSenderMode;
132
133 }