com.liferay.portal.kernel.messaging.Message Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-service Show documentation
Show all versions of portal-service Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.messaging;
import com.liferay.portal.kernel.io.Deserializer;
import com.liferay.portal.kernel.io.Serializer;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.TransientValue;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
/**
* @author Brian Wing Shun Chan
* @author Michael C. Han
*/
public class Message implements Cloneable, Serializable {
public static Message fromByteArray(byte[] bytes)
throws ClassNotFoundException {
Deserializer deserializer = new Deserializer(ByteBuffer.wrap(bytes));
return deserializer.readObject();
}
@Override
public Message clone() {
Message message = new Message();
message._destinationName = _destinationName;
message._payload = _payload;
message._response = _response;
message._responseDestinationName = _responseDestinationName;
message._responseId = _responseId;
if (_values != null) {
message._values = new HashMap(_values);
}
return message;
}
public boolean contains(String key) {
if (_values == null) {
return false;
}
else {
return _values.containsKey(key);
}
}
public void copyFrom(Message message) {
_destinationName = message._destinationName;
_payload = message._payload;
_response = message._response;
_responseDestinationName = message._responseDestinationName;
_responseId = message._responseId;
if (message._values != null) {
_values = new HashMap(message._values);
}
}
public void copyTo(Message message) {
message._destinationName = _destinationName;
message._payload = _payload;
message._response = _response;
message._responseDestinationName = _responseDestinationName;
message._responseId = _responseId;
if (_values != null) {
message._values = new HashMap(_values);
}
}
public Object get(String key) {
if (_values == null) {
return null;
}
Object value = _values.get(key);
if (value instanceof TransientValue) {
TransientValue