Commit 39670c14 authored by Guillaume Surrel's avatar Guillaume Surrel
Browse files

Create a Helper to ease the creation of well formed messages.

parent a7bc11a0
......@@ -88,6 +88,7 @@ import org.objectweb.joram.shared.admin.UserAdminRequest;
import org.objectweb.joram.shared.excepts.MomException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.messages.Message;
import org.objectweb.joram.shared.messages.MessageHelper;
import org.objectweb.joram.shared.security.Identity;
import org.objectweb.joram.shared.security.SimpleIdentity;
import org.objectweb.util.monolog.api.BasicLevel;
......@@ -1481,11 +1482,7 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
if (to == null) return;
Message message = new Message();
message.id = createMessageId();
message.correlationId = msgId;
message.timestamp = System.currentTimeMillis();
message.setDestination(getId().toString(), Message.TOPIC_TYPE);
Message message = MessageHelper.createMessage(createMessageId(), msgId, getAgentId(), getType());
try {
message.setAdminMessage(reply);
ClientMessages clientMessages = new ClientMessages(-1, -1, message);
......
......@@ -64,6 +64,7 @@ import org.objectweb.joram.shared.excepts.MomException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.messages.ConversionHelper;
import org.objectweb.joram.shared.messages.Message;
import org.objectweb.joram.shared.messages.MessageHelper;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
......@@ -915,11 +916,7 @@ public abstract class Destination extends Agent implements DestinationMBean {
AgentId replyTo,
String requestMsgId,
String replyMsgId) {
Message message = new Message();
message.correlationId = requestMsgId;
message.timestamp = System.currentTimeMillis();
message.setDestination(replyTo.toString(), Message.TOPIC_TYPE);
message.id = replyMsgId;
Message message = MessageHelper.createMessage(replyMsgId, requestMsgId, getAgentId(), getType());
try {
message.setAdminMessage(reply);
ClientMessages clientMessages = new ClientMessages(-1, -1, message);
......
......@@ -132,6 +132,7 @@ import org.objectweb.joram.shared.excepts.DestinationException;
import org.objectweb.joram.shared.excepts.MomException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.excepts.StateException;
import org.objectweb.joram.shared.messages.MessageHelper;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
......@@ -2773,11 +2774,8 @@ public final class UserAgent extends Agent implements UserAgentMBean, BagSeriali
}
private void replyToTopic(AdminReply reply, AgentId replyTo, String requestMsgId, String replyMsgId) {
org.objectweb.joram.shared.messages.Message message = new org.objectweb.joram.shared.messages.Message();
message.correlationId = requestMsgId;
message.timestamp = System.currentTimeMillis();
message.setDestination(replyTo.toString(), org.objectweb.joram.shared.messages.Message.TOPIC_TYPE);
message.id = replyMsgId;
org.objectweb.joram.shared.messages.Message message = MessageHelper.createMessage(replyMsgId,
requestMsgId, replyTo.toString(), DestinationConstants.TOPIC_TYPE);
try {
message.setAdminMessage(reply);
ClientMessages clientMessages = new ClientMessages(-1, -1, message);
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2010 ScalAgent Distributed Technologies
*
* 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 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.objectweb.joram.shared.messages;
import org.objectweb.joram.shared.DestinationConstants;
public class MessageHelper {
// Suppresses default constructor, ensuring non-instantiability.
private MessageHelper() {
}
/**
* Creates a well formed {@link Message}.
*
* @param msgId ID of the new message
* @param correlationId correlation ID of the new message
* @param destId ID of the destination creating the message
* @param destType type of the destination creating the message:
* {@link DestinationConstants#QUEUE_TYPE} or
* {@link DestinationConstants#TOPIC_TYPE}
* @return the new message.
*/
public static Message createMessage(String msgId, String correlationId, String destId, byte destType) {
Message message = new Message();
message.id = msgId;
message.correlationId = correlationId;
message.timestamp = System.currentTimeMillis();
message.setDestination(destId, destType);
return message;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment