[savara-commits] savara SVN: r634 - in branches/experimental/2.0.x/bundles: org.savara.monitor/src/main/java/org/savara/monitor/impl and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 31 17:16:47 EST 2011


Author: objectiser
Date: 2011-01-31 17:16:46 -0500 (Mon, 31 Jan 2011)
New Revision: 634

Added:
   branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/ProtocolCriteria.java
   branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/SimulationHandler.java
Removed:
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorListener.java
   branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/MessageCriteria.java
Modified:
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Message.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Monitor.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorResult.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/test/java/org/savara/monitor/impl/DefaultMonitorTest.java
   branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/ProtocolRepository.java
   branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/impl/InMemoryProtocolRepository.java
   branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/DefaultScenarioSimulator.java
   branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/ScenarioSimulator.java
Log:
Add more scenario simulation functionality and removed model listener.

Modified: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Message.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Message.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Message.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -17,86 +17,106 @@
  */
 package org.savara.monitor;
 
+import org.savara.protocol.ProtocolCriteria;
+
 /**
  * This class represents a message to be monitored.
  *
  */
-public class Message extends org.scribble.protocol.monitor.DefaultMessage {
-					//implements org.savara.protocol.MessageCriteria  {
+public class Message extends org.scribble.protocol.monitor.DefaultMessage
+					implements ProtocolCriteria  {
 
-	private String m_endpointAddress=null;
-	private String m_endpointType=null;
-	private Style m_style=Style.Request;
-	private Direction m_direction=Direction.Outbound;
+	private String m_destinationEndpointAddress=null;
+	private String m_destinationEndpointType=null;
+	private String m_sourceEndpointAddress=null;
+	private String m_sourceEndpointType=null;
+	private ProtocolCriteria.Direction m_direction=Direction.Outbound;
 	
 	/**
-	 * This method provides the endpoint address of the component that
+	 * This method provides the destination endpoint address of the component that
 	 * is the subject of the interaction.
 	 * 
-	 * If not specified, then the endpoint type must be defined.
+	 * If not specified, then the destination endpoint address must be defined.
 	 * 
-	 * @return The endpoint address, or null if not known
+	 * @return The destination endpoint address, or null if not known
 	 */
-	public String getEndpointAddress() {
-		return(m_endpointAddress);
+	public String getDestinationEndpointAddress() {
+		return(m_destinationEndpointAddress);
 	}
 	
 	/**
-	 * This method sets the endpoint address.
+	 * This method sets the destination endpoint address.
 	 * 
-	 * @param address The endpoint address
+	 * @param address The destination endpoint address
 	 */
-	public void setEndpointAddress(String address) {
-		m_endpointAddress = address;
+	public void setDestinationEndpointAddress(String address) {
+		m_destinationEndpointAddress = address;
 	}
 	
 	/**
-	 * This method returns the endpoint type of the component that is
+	 * This method returns the destination endpoint type of the component that is
 	 * the subject of the interaction.
 	 * 
-	 * If not specified, then the endpoint address must be defined.
+	 * If not specified, then the destination endpoint type must be defined.
 	 * 
-	 * @return The enpdoint type, or null if not known
+	 * @return The destination endpoint type, or null if not known
 	 */
-	public String getEndpointType() {
-		return(m_endpointType);
+	public String getDestinationEndpointType() {
+		return(m_destinationEndpointType);
 	}
 	
 	/**
-	 * This method sets the endpoint type.
+	 * This method sets the destination endpoint type.
 	 * 
-	 * @param type The endpoint type
+	 * @param type The destination endpoint type
 	 */
-	public void setEndpointType(String type) {
-		m_endpointType = type;
+	public void setDestinationEndpointType(String type) {
+		m_destinationEndpointType = type;
 	}
 	
 	/**
-	 * This method indicates whether the message is a request, and therefore
-	 * destined for the endpoint identified by its address or type, or a
-	 * response/fault.
+	 * This method provides the source endpoint address of the component that
+	 * is the subject of the interaction.
 	 * 
-	 * Not all communication infrastructures will support the notion of
-	 * request/response, and therefore by default a message will represent
-	 * a request whose destination is identified by the endpoint address 
-	 * and/or type.
+	 * If not specified, then the source endpoint address must be defined.
 	 * 
-	 * @return The message style
+	 * @return The source endpoint address, or null if not known
 	 */
-	public Style getStyle() {
-		return(m_style);
+	public String getSourceEndpointAddress() {
+		return(m_sourceEndpointAddress);
 	}
 	
 	/**
-	 * This method sets the style of the message.
+	 * This method sets the source endpoint address.
 	 * 
-	 * @param style The style
+	 * @param address The source endpoint address
 	 */
-	public void setStyle(Style style) {
-		m_style = style;
+	public void setSourceEndpointAddress(String address) {
+		m_sourceEndpointAddress = address;
 	}
 	
 	/**
+	 * This method returns the source endpoint type of the component that is
+	 * the subject of the interaction.
+	 * 
+	 * If not specified, then the source endpoint type must be defined.
+	 * 
+	 * @return The source endpoint type, or null if not known
+	 */
+	public String getSourceEndpointType() {
+		return(m_sourceEndpointType);
+	}
+	
+	/**
+	 * This method sets the source endpoint type.
+	 * 
+	 * @param type The source endpoint type
+	 */
+	public void setSourceEndpointType(String type) {
+		m_sourceEndpointType = type;
+	}
+	
+	/**
 	 * This method returns the direction of the message.
 	 * 
 	 * @return The direction
@@ -113,25 +133,4 @@
 	public void setDirection(Direction direction) {
 		m_direction = direction;
 	}
-	
-	/**
-	 * This enumerated class represents the style of message.
-	 *
-	 */
-	public enum Style {
-		Request,
-		Response,
-		Fault
-	}
-	
-	/**
-	 * This enumerated class represents the direction of the message,
-	 * whether it is 'inbound' (i.e. received) or 'outbound' 
-	 * (i.e. sent).
-	 *
-	 */
-	public enum Direction {
-		Inbound,
-		Outbound
-	}
 }

Modified: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Monitor.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Monitor.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Monitor.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -35,14 +35,6 @@
 public interface Monitor {
 
 	/**
-	 * This method sets the monitor listener used to handle
-	 * activity information produced while monitoring.
-	 * 
-	 * @param l The monitor listener
-	 */
-	public void setMonitorListener(MonitorListener l);
-	
-	/**
 	 * This method sets the protocol repository to use when
 	 * monitoring.
 	 * 
@@ -64,37 +56,23 @@
 	 * specified protocol id and optional conversation instance
 	 * id.
 	 * 
+	 * If the protocol id is not specified, then the first
+	 * relevant protocol will be used. If none are found, then
+	 * a null result will be returned.
+	 * 
 	 * If the conversation instance id is not explicitly
 	 * specified, then the protocol monitor will be responsible
 	 * for deriving the appropriate value.
 	 * 
-	 * @param pid The protocol id
+	 * @param pid The optional protocol id
 	 * @param cid The optional conversation instance id
 	 * @param mesg The message
-	 * @return Whether the message was valid
+	 * @return The monitor result, or null if a suitable protocol was not found
 	 * @throws ProtocolUnknownException Unknown protocol name or role
 	 * @throws IOException Failed to create or retrieve session
 	 */
-	public boolean process(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+	public MonitorResult process(ProtocolId pid, ConversationInstanceId cid, Message mesg)
 							throws ProtocolUnknownException,
 									java.io.IOException;
 	
-	/**
-	 * This method is used to indicate that a message has been
-	 * sent or received, and should be monitored against the configured
-	 * behaviour.
-	 * 
-	 * If the conversation instance id is not explicitly
-	 * specified, then the protocol monitor will be responsible
-	 * for deriving the appropriate value.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The optional conversation instance id
-	 * @param mesg The message
-	 * @return Whether the message was valid
-	 * @throws ProtocolUnknownException Unknown protocol name or role
-	 * @throws IOException Failed to create or retrieve session
-	 */
-	public java.util.List<MonitorResult> process(Message mesg) throws java.io.IOException;
-	
 }

Deleted: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorListener.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorListener.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorListener.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- */
-package org.savara.monitor;
-
-import org.savara.protocol.ProtocolId;
-import org.scribble.protocol.monitor.Result;
-
-/**
- * This interface represents a listener for activity information
- * provided by a protocol monitor.
- *
- */
-public interface MonitorListener {
-
-	/**
-	 * This method is called when a new session starts related to the supplied
-	 * protocol and conversation instance ids.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The conversation instance id
-	 */
-	public void sessionStarted(ProtocolId pid, ConversationInstanceId cid);
-	
-	/**
-	 * This method is called when a session finishes related to the supplied
-	 * protocol and conversation instance ids.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The conversation instance id
-	 */
-	public void sessionFinished(ProtocolId pid, ConversationInstanceId cid);
-	
-	/**
-	 * This method is called when a message has been sent, related to the
-	 * supplied protocol and conversation instance id.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The conversation instance id
-	 * @param mesg The message
-	 * @param result The monitoring result
-	 */
-	public void messageSent(ProtocolId pid, ConversationInstanceId cid, Message mesg,
-							Result result);
-	
-	/**
-	 * This method is called when a message has been received, related to the
-	 * supplied protocol and conversation instance id.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The conversation instance id
-	 * @param mesg The message
-	 * @param result The monitoring result
-	 */
-	public void messageReceived(ProtocolId pid, ConversationInstanceId cid, Message mesg,
-							Result result);
-	
-}

Modified: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorResult.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorResult.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorResult.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -30,6 +30,7 @@
 	private ConversationInstanceId m_conversationInstanceId=null;
 	private boolean m_valid=false;
 	private String m_reason=null;
+	private java.util.Map<String,Object> m_properties=null;
 	
 	/**
 	 * This is the result constructor.
@@ -38,13 +39,15 @@
 	 * @param cid The conversation instance id
 	 * @param valid Whether the result was valid
 	 * @param reason Reason for result
+	 * @param props The properties
 	 */
 	public MonitorResult(ProtocolId pid, ConversationInstanceId cid, boolean valid,
-						String reason) {
+						String reason, java.util.Map<String,Object> props) {
 		m_protocolId = pid;
 		m_conversationInstanceId = cid;
 		m_valid = valid;
 		m_reason = reason;
+		m_properties = props;
 	}
 	
 	/**
@@ -82,4 +85,13 @@
 	public String getReason() {
 		return(m_reason);
 	}
+	
+	/**
+	 * This method returns the property map.
+	 * 
+	 * @return The property map
+	 */
+	public java.util.Map<String,Object> getProperties() {
+		return(m_properties);
+	}
 }

Modified: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -25,7 +25,6 @@
 import org.savara.monitor.SessionStore;
 import org.savara.monitor.Message;
 import org.savara.monitor.Monitor;
-import org.savara.monitor.MonitorListener;
 import org.savara.protocol.ProtocolId;
 import org.savara.protocol.repository.ProtocolRepository;
 import org.savara.protocol.ProtocolUnknownException;
@@ -47,7 +46,6 @@
  */
 public class DefaultMonitor implements Monitor {
 
-	private MonitorListener m_monitorListener=null;
 	private ProtocolRepository m_protocolRepository=null;
 	private SessionStore m_sessionStore=null;
 	private ProtocolMonitor m_monitor=new DefaultProtocolMonitor();
@@ -67,16 +65,6 @@
 	}
 	
 	/**
-	 * This method sets the monitor listener used to handle
-	 * activity information produced while monitoring.
-	 * 
-	 * @param l The monitor listener
-	 */
-	public void setMonitorListener(MonitorListener l) {
-		m_monitorListener = l;
-	}
-	
-	/**
 	 * This method sets the protocol repository to use when
 	 * monitoring.
 	 * 
@@ -102,32 +90,73 @@
 	 * specified protocol id and optional conversation instance
 	 * id.
 	 * 
+	 * If the protocol id is not specified, then the first
+	 * relevant protocol will be used. If none are found, then
+	 * a null result will be returned.
+	 * 
 	 * If the conversation instance id is not explicitly
 	 * specified, then the protocol monitor will be responsible
 	 * for deriving the appropriate value.
 	 * 
-	 * @param pid The protocol id
+	 * @param pid The optional protocol id
 	 * @param cid The optional conversation instance id
 	 * @param mesg The message
-	 * @return Whether the message was valid
+	 * @return The monitor result, or null if a suitable protocol was not found
 	 * @throws ProtocolUnknownException Unknown protocol name or role
 	 * @throws IOException Failed to create or retrieve session
 	 */
-	public boolean process(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+	public MonitorResult process(ProtocolId pid, ConversationInstanceId cid, Message mesg)
 							throws ProtocolUnknownException,
 									java.io.IOException {
-		boolean ret=false;
+		MonitorResult ret=null;
 		
-		if (pid == null) {
-			throw new IllegalArgumentException("Protocol id not specified");
-		}
-		
 		if (m_protocolRepository == null) {
 			throw new IllegalStateException("Protocol repository has not been configured");
 		} else if (m_sessionStore == null) {
 			throw new IllegalStateException("Session store has not been configured");
 		}
 		
+		if (pid == null) {
+			// Find the protocol ids relevant for this message
+			java.util.List<ProtocolId> pids=m_protocolRepository.getProtocols(mesg);
+			
+			if (pids != null) {
+				for (ProtocolId pi : pids) {
+					try {
+						Result result=processProtocol(pi, cid, mesg);
+						
+						if (result != null && result != Result.NOT_HANDLED) {
+							ret = new MonitorResult(pid, cid, result.isValid(),
+									result.getReason(), result.getProperties());	
+							break;
+						}
+					} catch(ProtocolUnknownException pue) {
+						logger.severe("Unknown protocol: Failed to process message against protocol id '"+
+										pid+"'");
+					}
+				}
+			}
+		} else {
+			try {
+				Result result=processProtocol(pid, cid, mesg);
+				
+				if (result != null && result != Result.NOT_HANDLED) {
+					ret = new MonitorResult(pid, cid, result.isValid(),
+							result.getReason(), result.getProperties());	
+				}
+			} catch(ProtocolUnknownException pue) {
+				logger.severe("Unknown protocol: Failed to process message against protocol id '"+
+								pid+"'");
+			}
+		}
+		
+		return(ret);
+	}
+	
+	protected Result processProtocol(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+					throws ProtocolUnknownException, java.io.IOException {
+		Result ret=null;
+		
 		// Check if conversation instance id should be derived
 		if (cid == null) {
 			// TODO: Derive conversation instance id
@@ -138,6 +167,7 @@
 		java.io.Serializable session=m_sessionStore.find(pid, cid);
 		
 		MonitorContext context=null;
+		boolean f_created=false;
 		
 		if (session == null) {
 			session = m_sessionStore.create(pid, cid);
@@ -145,32 +175,26 @@
 			// Try to create new session
 			if (session instanceof Session) {
 				m_monitor.initialize(context, desc, (Session)session);
+			}
 			
-				if (m_monitorListener != null) {
-					m_monitorListener.sessionStarted(pid, cid);
-				}
-			}
+			f_created = true;
 		}
 		
 		if (session instanceof Session) {
 			// Won't specify role, as part of protocol description not
 			// generally in the runtime environment - possible future
 			// enhancement
-			Result result=m_monitor.messageSent(context, desc, (Session)session, null, mesg);
+			ret = m_monitor.messageSent(context, desc, (Session)session, null, mesg);
 			
-			if (m_monitorListener != null) {
-				m_monitorListener.messageSent(pid, cid, mesg, result);
-			}
-		
-			if (((Session)session).isFinished()) {
-				if (m_monitorListener != null) {
-					m_monitorListener.sessionFinished(pid, cid);
-				}
-		
+			// If session just created but result not handled, or session finished
+			// then remove
+			if ((f_created && ret == Result.NOT_HANDLED) ||
+						((Session)session).isFinished()) {
 				m_sessionStore.remove(pid, cid);
 			} else {
 				m_sessionStore.update(pid, cid, session);
 			}
+			
 		} else {
 			throw new java.io.IOException("Inappropriate session type returned");
 		}
@@ -179,28 +203,6 @@
 	}
 	
 	/**
-	 * This method is used to indicate that a message has been
-	 * sent or received, and should be monitored against the configured
-	 * behaviour.
-	 * 
-	 * If the conversation instance id is not explicitly
-	 * specified, then the protocol monitor will be responsible
-	 * for deriving the appropriate value.
-	 * 
-	 * @param pid The protocol id
-	 * @param cid The optional conversation instance id
-	 * @param mesg The message
-	 * @return Whether the message was valid
-	 * @throws ProtocolUnknownException Unknown protocol name or role
-	 * @throws IOException Failed to create or retrieve session
-	 */
-	public java.util.List<MonitorResult> process(Message mesg) throws java.io.IOException {
-		java.util.List<MonitorResult> ret=new java.util.Vector<MonitorResult>();
-		
-		return(ret);
-	}
-
-	/**
 	 * This method returns the protocol's monitorable description.
 	 * 
 	 * @param pid The protocol id

Modified: branches/experimental/2.0.x/bundles/org.savara.monitor/src/test/java/org/savara/monitor/impl/DefaultMonitorTest.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/test/java/org/savara/monitor/impl/DefaultMonitorTest.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/test/java/org/savara/monitor/impl/DefaultMonitorTest.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -19,16 +19,19 @@
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+import java.io.Serializable;
+
 import org.junit.Test;
+import org.savara.common.config.Configuration;
 import org.savara.monitor.ConversationInstanceId;
 import org.savara.monitor.Message;
-import org.savara.monitor.MonitorListener;
+import org.savara.monitor.SessionStore;
 import org.savara.protocol.ProtocolId;
 import org.savara.protocol.repository.impl.InMemoryProtocolRepository;
 import org.scribble.protocol.model.ProtocolModel;
 import org.scribble.protocol.monitor.DefaultSession;
 import org.scribble.protocol.monitor.ProtocolMonitorFactory;
-import org.scribble.protocol.monitor.Result;
 
 public class DefaultMonitorTest {
 
@@ -157,27 +160,9 @@
 		InMemoryProtocolRepository rep=new InMemoryProtocolRepository();
 		rep.addProtocol(pid, new ProtocolModel());
 		mon.setProtocolRepository(rep);
-
-		InMemorySessionStore store=new InMemorySessionStore() {
-			public java.io.Serializable create(ProtocolId pid, ConversationInstanceId cid)
-						throws IllegalArgumentException, java.io.IOException {
-			
-				DefaultSession s1=new DefaultSession() {
-					public boolean isFinished() {
-						return(true);
-					}
-				};
-				
-				addSession(pid, cid, s1);
-				
-				return(s1);
-			}
-		};
-				
-		TestMonitorListener tl=new TestMonitorListener();
 		
-		mon.setMonitorListener(tl);
-		
+		TestInMemorySessionStore store=new TestInMemorySessionStore();
+				
 		mon.setSessionStore(store);
 		
 		try {
@@ -186,48 +171,34 @@
 			fail("Unexpected: "+e);
 		}
 		
-		if (tl.hasSessionStarted(pid) == false) {
-			fail("Session not started");
+		if (store.f_removed == false) {
+			fail("Session was not removed after single message");
 		}
-		
-		if (tl.hasSessionFinished(pid) == false) {
-			fail("Session not finished");
-		}
 	}
 	
-	public class TestMonitorListener implements MonitorListener {
+	public class TestInMemorySessionStore extends InMemorySessionStore {
 		
-		private java.util.List<ProtocolId> m_started=new java.util.Vector<ProtocolId>();
-		private java.util.List<ProtocolId> m_finished=new java.util.Vector<ProtocolId>();
-
-		public boolean hasSessionStarted(ProtocolId pid) {
-			return(m_started.contains(pid));
-		}
+		public boolean f_removed=false;
 		
-		public void sessionStarted(ProtocolId pid, ConversationInstanceId cid) {
-			m_started.add(pid);
-		}
-
-		public boolean hasSessionFinished(ProtocolId pid) {
-			return(m_finished.contains(pid));
-		}
+		public java.io.Serializable create(ProtocolId pid, ConversationInstanceId cid)
+					throws IllegalArgumentException, java.io.IOException {
 		
-		public void sessionFinished(ProtocolId pid, ConversationInstanceId cid) {
-			m_finished.add(pid);
-		}
-
-		public void messageSent(ProtocolId pid, ConversationInstanceId cid,
-				Message mesg, Result result) {
-			// TODO Auto-generated method stub
+			DefaultSession s1=new DefaultSession() {
+				public boolean isFinished() {
+					return(true);
+				}
+			};
 			
+			addSession(pid, cid, s1);
+			
+			return(s1);
 		}
 
-		public void messageReceived(ProtocolId pid, ConversationInstanceId cid,
-				Message mesg, Result result) {
-			// TODO Auto-generated method stub
-			
+		public void remove(ProtocolId pid, ConversationInstanceId cid)
+				throws IllegalArgumentException, IOException {
+			f_removed = true;
 		}
-		
-	}
+	};
+			
 }
 

Deleted: branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/MessageCriteria.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/MessageCriteria.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/MessageCriteria.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- */
-package org.savara.protocol;
-
-/**
- * This interface represents the message criteria to be used to identify
- * a protocol model.
- *
- */
-public interface MessageCriteria {
-
-	/**
-	 * This method returns the optional operator name.
-	 * 
-	 * @return The operator, or null if not relevant
-	 */
-	public String getOperator();
-	
-	/**
-	 * This method returns the list of types associated with
-	 * with the message.
-	 * 
-	 * @return The types of the message parameters
-	 */
-	public java.util.List<String> getTypes();
-	
-	/**
-	 * This method provides the endpoint address of the component that
-	 * is the subject of the interaction.
-	 * 
-	 * If not specified, then the endpoint type must be defined.
-	 * 
-	 * @return The endpoint address, or null if not known
-	 */
-	public String getEndpointAddress();
-	
-	/**
-	 * This method returns the endpoint type of the component that is
-	 * the subject of the interaction.
-	 * 
-	 * If not specified, then the endpoint address must be defined.
-	 * 
-	 * @return The enpdoint type, or null if not known
-	 */
-	public String getEndpointType();
-	
-	/**
-	 * This method indicates whether the message is a request, and therefore
-	 * destined for the endpoint identified by its address or type, or a
-	 * response/fault.
-	 * 
-	 * Not all communication infrastructures will support the notion of
-	 * request/response, and therefore by default a message will represent
-	 * a request whose destination is identified by the endpoint address 
-	 * and/or type.
-	 * 
-	 * @return The message style
-	 */
-	public Style getStyle();
-	
-	/**
-	 * This method returns the direction of the message.
-	 * 
-	 * @return The direction
-	 */
-	public Direction getDirection();
-	
-	/**
-	 * This enumerated class represents the style of message.
-	 *
-	 */
-	public enum Style {
-		Request,
-		Response,
-		Fault
-	}
-	
-	/**
-	 * This enumerated class represents the direction of the message,
-	 * whether it is 'inbound' (i.e. received) or 'outbound' 
-	 * (i.e. sent).
-	 *
-	 */
-	public enum Direction {
-		Inbound,
-		Outbound
-	}
-}

Copied: branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/ProtocolCriteria.java (from rev 630, branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/MessageCriteria.java)
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/ProtocolCriteria.java	                        (rev 0)
+++ branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/ProtocolCriteria.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.savara.protocol;
+
+/**
+ * This interface represents the criteria to be used to identify
+ * a protocol and role of interest.
+ *
+ */
+public interface ProtocolCriteria {
+
+	/**
+	 * This method provides the destination endpoint address of the component that
+	 * is the subject of the interaction.
+	 * 
+	 * If not specified, then the destination endpoint address must be defined.
+	 * 
+	 * @return The destination endpoint address, or null if not known
+	 */
+	public String getDestinationEndpointAddress();
+	
+	/**
+	 * This method returns the destinationendpoint type of the component that is
+	 * the subject of the interaction.
+	 * 
+	 * If not specified, then the destination endpoint type must be defined.
+	 * 
+	 * @return The destination enpdoint type, or null if not known
+	 */
+	public String getDestinationEndpointType();
+	
+	/**
+	 * This method provides the endpoint address of the component that
+	 * is the subject of the interaction.
+	 * 
+	 * If not specified, then the endpoint address must be defined.
+	 * 
+	 * @return The source endpoint address, or null if not known
+	 */
+	public String getSourceEndpointAddress();
+	
+	/**
+	 * This method returns the source endpoint type of the component that is
+	 * the subject of the interaction.
+	 * 
+	 * If not specified, then the source endpoint type must be defined.
+	 * 
+	 * @return The source endpoint type, or null if not known
+	 */
+	public String getSourceEndpointType();
+	
+	/**
+	 * This method returns the direction of the message.
+	 * 
+	 * @return The direction
+	 */
+	public Direction getDirection();
+	
+	/**
+	 * This enumerated class represents the direction of the message,
+	 * whether it is 'inbound' (i.e. received) or 'outbound' 
+	 * (i.e. sent).
+	 *
+	 */
+	public enum Direction {
+		Inbound,
+		Outbound
+	}
+}

Modified: branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/ProtocolRepository.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/ProtocolRepository.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/ProtocolRepository.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -17,7 +17,7 @@
  */
 package org.savara.protocol.repository;
 
-import org.savara.protocol.MessageCriteria;
+import org.savara.protocol.ProtocolCriteria;
 import org.savara.protocol.ProtocolId;
 import org.savara.protocol.ProtocolUnknownException;
 import org.scribble.protocol.model.ProtocolModel;
@@ -41,12 +41,11 @@
 	
 	/**
 	 * This method determines which protocols, identified by their protocol ids,
-	 * would be interested in an endpoint address/type, whether or not the message is inbound,
-	 * and finally the message details itself.
+	 * would be interested in the supplied protocol criteria.
 	 * 
-	 * @param message The message
-	 * @return The list of protocol ids interested in the message
+	 * @param criteria The criteria
+	 * @return The list of protocol ids matching the supplied criteria
 	 */
-	public java.util.List<ProtocolId> getProtocols(MessageCriteria message);
+	public java.util.List<ProtocolId> getProtocols(ProtocolCriteria criteria);
 	
 }

Modified: branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/impl/InMemoryProtocolRepository.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/impl/InMemoryProtocolRepository.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.protocol/src/main/java/org/savara/protocol/repository/impl/InMemoryProtocolRepository.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -17,7 +17,7 @@
  */
 package org.savara.protocol.repository.impl;
 
-import org.savara.protocol.MessageCriteria;
+import org.savara.protocol.ProtocolCriteria;
 import org.savara.protocol.ProtocolId;
 import org.savara.protocol.repository.ProtocolRepository;
 import org.savara.protocol.ProtocolUnknownException;
@@ -69,7 +69,7 @@
 	 * @param criteria The message criteria
 	 * @return The list of protocol ids interested in the message criteria
 	 */
-	public java.util.List<ProtocolId> getProtocols(MessageCriteria criteria) {
+	public java.util.List<ProtocolId> getProtocols(ProtocolCriteria criteria) {
 		java.util.List<ProtocolId> ret=new java.util.Vector<ProtocolId>();
 		
 		return(ret);

Modified: branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/DefaultScenarioSimulator.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/DefaultScenarioSimulator.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/DefaultScenarioSimulator.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -17,8 +17,17 @@
  */
 package org.savara.scenario.simulation;
 
+import java.util.UUID;
+
+import org.savara.monitor.ConversationInstanceId;
+import org.savara.monitor.Message;
 import org.savara.monitor.Monitor;
-//import org.savara.monitor.impl.DefaultMonitor;
+import org.savara.scenario.model.Event;
+import org.savara.scenario.model.MessageEvent;
+import org.savara.scenario.model.ReceiveEvent;
+import org.savara.scenario.model.Role;
+import org.savara.scenario.model.Scenario;
+import org.savara.scenario.model.SendEvent;
 
 /**
  * This class provides the default implementation of the Scenario Simulator interface.
@@ -26,27 +35,83 @@
  */
 public class DefaultScenarioSimulator implements ScenarioSimulator {
 
-	//private Monitor m_monitor=new DefaultMonitor();
+	private Monitor m_monitor=null;
 	
-	public void run() {
+	/**
+	 * This method sets the monitor used to simulate the scenario.
+	 * 
+	 * @param monitor The monitor
+	 */
+	public void setMonitor(Monitor monitor) {
+		m_monitor = monitor;
+	}
+	
+	/**
+	 * This method simulates the scenario against the pre-configured
+	 * monitor. Results from the simulation are notified to the
+	 * supplied simulation handler.
+	 * 
+	 * @param scenario The scenario to be simulated
+	 * @param handler The callback to notify of the simulation results
+	 */
+	public void simulate(Scenario scenario, SimulationHandler handler) {
 		
-		/*
-		DefaultConversationContext context=new DefaultConversationContext();
-		monitor.initialize(pd, context);
+		ConversationInstanceId cid=new ConversationInstanceId(UUID.randomUUID().toString());
 		
-		DefaultMessage message=new DefaultMessage();
-		message.setType(ORDER_MESSAGE_TYPE);
+		simulateEvents(cid, scenario.getEvent(), handler);
+	}
+	
+	/**
+	 * This method simulates a list of events, associated with a scenario.
+	 * 
+	 * @param cid The conversation instance id
+	 * @param events The list of events
+	 * @param handler The handler
+	 */
+	protected void simulateEvents(ConversationInstanceId cid,
+					java.util.List<Event> events, SimulationHandler handler) {
 		
-		if (monitor.receiveMessage(pd, context, null, message) == false) {
-			fail("Receive Order failed");
+		for (Event event : events) {
+			if (event instanceof SendEvent) {
+				handleSendEvent(cid, (SendEvent)event, handler);
+			} else if (event instanceof ReceiveEvent) {
+				handleReceiveEvent(cid, (ReceiveEvent)event, handler);
+			} else {
+				handler.unknownEvent(event);
+			}
 		}
-		
-		message=new DefaultMessage();
-		message.setType(CREDIT_CHECK_MESSAGE_TYPE);
-		
-		if (monitor.sendMessage(pd, context, null, message) == false) {
-			fail("Credit check failed");
+	}
+	
+	protected Message getMessageForEvent(MessageEvent event) {
+		Message mesg=new Message();
+		mesg.setOperator(event.getOperationName());
+
+		return(mesg);
+	}
+	
+	protected void handleSendEvent(ConversationInstanceId cid,
+					SendEvent event, SimulationHandler handler) {
+		try {
+			Message mesg=getMessageForEvent(event);
+			
+			mesg.setSourceEndpointType(((Role)event.getRole()).getName());
+
+			m_monitor.process(null, cid, mesg);
+		} catch(Exception e) {
+			handler.exception("Failed when handling send event", event, e);
 		}
-*/
 	}
+	
+	protected void handleReceiveEvent(ConversationInstanceId cid,
+					ReceiveEvent event, SimulationHandler handler) {
+		try {
+			Message mesg=getMessageForEvent(event);
+			
+			mesg.setDestinationEndpointType(((Role)event.getRole()).getName());
+
+			m_monitor.process(null, cid, mesg);
+		} catch(Exception e) {
+			handler.exception("Failed when handling receive event", event, e);
+		}		
+	}
 }

Modified: branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/ScenarioSimulator.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/ScenarioSimulator.java	2011-01-30 22:06:48 UTC (rev 633)
+++ branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/ScenarioSimulator.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -17,6 +17,30 @@
  */
 package org.savara.scenario.simulation;
 
+import org.savara.monitor.Monitor;
+import org.savara.scenario.model.Scenario;
+
+/**
+ * This interface defines the scenario simulator.
+ *
+ */
 public interface ScenarioSimulator {
 
+	/**
+	 * This method sets the monitor used to simulate the scenario.
+	 * 
+	 * @param monitor The monitor
+	 */
+	public void setMonitor(Monitor monitor);
+	
+	/**
+	 * This method simulates the scenario against the pre-configured
+	 * monitor. Results from the simulation are notified to the
+	 * supplied simulation handler.
+	 * 
+	 * @param scenario The scenario to be simulated
+	 * @param handler The callback to notify of the simulation results
+	 */
+	public void simulate(Scenario scenario, SimulationHandler handler);
+	
 }

Added: branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/SimulationHandler.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/SimulationHandler.java	                        (rev 0)
+++ branches/experimental/2.0.x/bundles/org.savara.scenario/src/main/java/org/savara/scenario/simulation/SimulationHandler.java	2011-01-31 22:16:46 UTC (rev 634)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008-11, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.savara.scenario.simulation;
+
+import org.savara.scenario.model.Event;
+
+/**
+ * This interface represents the callback handler for results from
+ * simulating a scenario.
+ *
+ */
+public interface SimulationHandler {
+
+	/**
+	 * This method is called when an unknown event is detected.
+	 * 
+	 * @param event The unknown event
+	 */
+	public void unknownEvent(Event event);
+	
+	/**
+	 * This method is invoked if an exception is thrown while
+	 * simulating an event.
+	 * 
+	 * @param mesg The message
+	 * @param event The event
+	 * @param e The exception
+	 */
+	public void exception(String mesg, Event event, Exception e);
+	
+}



More information about the savara-commits mailing list