001 /****************************************************************************** 002 * Copyright (C) MActor Developers. All rights reserved. * 003 * ---------------------------------------------------------------------------* 004 * This file is part of MActor. * 005 * * 006 * MActor is free software; you can redistribute it and/or modify * 007 * it under the terms of the GNU General Public License as published by * 008 * the Free Software Foundation; either version 2 of the License, or * 009 * (at your option) any later version. * 010 * * 011 * MActor is distributed in the hope that it will be useful, * 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 014 * GNU General Public License for more details. * 015 * * 016 * You should have received a copy of the GNU General Public License * 017 * along with MActor; if not, write to the Free Software * 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 019 ******************************************************************************/ 020 package org.mactor.framework.spec; 021 022 import org.dom4j.Element; 023 import org.mactor.framework.MactorException; 024 import org.mactor.framework.ParseUtil; 025 026 public class MessageReceiveSpec extends ContainerSpec { 027 @Override 028 public String getType() { 029 return "message_receive"; 030 } 031 private int maxMessageCount; 032 private int minMessageCount; 033 private int maxTimeoutSeconds; 034 private boolean blockUntilTimeout; 035 private String messageSubscribeNodeName; 036 private boolean hasResponseNode = false; 037 public boolean hasResponseNode() { 038 return hasResponseNode; 039 } 040 public String getMessageSubscribeNodeName() { 041 return messageSubscribeNodeName; 042 } 043 public int getMaxTimeoutSeconds() { 044 return maxTimeoutSeconds; 045 } 046 public int getMaxMessageCount() { 047 return maxMessageCount; 048 } 049 public int getMinMessageCount() { 050 return minMessageCount; 051 } 052 public boolean isBlockUntilTimeout() { 053 return blockUntilTimeout; 054 } 055 public static MessageReceiveSpec loadSpec(Element element) throws MactorException { 056 if (element == null) 057 return null; 058 MessageReceiveSpec s = new MessageReceiveSpec(); 059 s.name = element.attributeValue("name"); 060 s.messageSubscribeNodeName = element.attributeValue("message_subscribe_node_name"); 061 s.minMessageCount = ParseUtil.tryParseIntVal(element.attributeValue("min_message_count")); 062 s.maxMessageCount = ParseUtil.tryParseIntVal(element.attributeValue("max_message_count")); 063 s.maxTimeoutSeconds = ParseUtil.tryParseIntVal(element.attributeValue("max_timeout_seconds")); 064 s.blockUntilTimeout = Boolean.parseBoolean(element.attributeValue("block_until_timeout")); 065 s.loadContainedNodes(element); 066 for (SpecNode n : s.getSpecNodes()) { 067 if (n instanceof MessageRespondSpec) { 068 s.hasResponseNode = true; 069 break; 070 } 071 } 072 return s; 073 } 074 public Element addToElement(Element parent) { 075 Element e = parent.addElement(getType()); 076 e.addAttribute("name", name); 077 e.addAttribute("message_subscribe_node_name", messageSubscribeNodeName); 078 e.addAttribute("min_message_count", minMessageCount + ""); 079 e.addAttribute("max_message_count", maxMessageCount + ""); 080 e.addAttribute("max_timeout_seconds", maxTimeoutSeconds + ""); 081 e.addAttribute("block_until_timeout", blockUntilTimeout + ""); 082 super.writeContainedNodesToElement(e); 083 return e; 084 } 085 public String getShortDescription() { 086 return "Receiver node - '" + name + "'"; 087 } 088 public String getDescription() { 089 return "Refered subscriber node:" + messageSubscribeNodeName + ". Max message count:" + maxMessageCount + ". Min message count" + minMessageCount + ". Max timeout (seconds):" 090 + maxTimeoutSeconds + ". Block until timeout:" + blockUntilTimeout; 091 } 092 public void setBlockUntilTimeout(boolean blockUntilTimeout) { 093 this.blockUntilTimeout = blockUntilTimeout; 094 } 095 public void setMaxMessageCount(int maxMessageCount) { 096 this.maxMessageCount = maxMessageCount; 097 } 098 public void setMaxTimeoutSeconds(int maxTimeoutSeconds) { 099 this.maxTimeoutSeconds = maxTimeoutSeconds; 100 } 101 public void setMessageSubscribeNodeName(String messageSubscribeNodeName) { 102 this.messageSubscribeNodeName = messageSubscribeNodeName; 103 } 104 public void setMinMessageCount(int minMessageCount) { 105 this.minMessageCount = minMessageCount; 106 } 107 }