[savara-commits] savara SVN: r588 - in branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor: impl and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 17 14:47:07 EST 2011


Author: objectiser
Date: 2011-01-17 14:47:07 -0500 (Mon, 17 Jan 2011)
New Revision: 588

Added:
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolRepository.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolUnknownException.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/MonitorListener.java
   branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java
Log:
Added protocol repository and more functionality on the monitor 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-16 21:58:53 UTC (rev 587)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Message.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -21,6 +21,6 @@
  * This class represents a message to be monitored.
  *
  */
-public interface Message {
+public interface Message extends org.scribble.protocol.monitor.Message {
 
 }

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-16 21:58:53 UTC (rev 587)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/Monitor.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -17,6 +17,11 @@
  */
 package org.savara.monitor;
 
+/**
+ * This interface represents a behaviour monitor, comparing a stream of messages
+ * against the expected behaviour associated with an endpoint protocol.
+ *
+ */
 public interface Monitor {
 
 	/**
@@ -28,6 +33,14 @@
 	public void setMonitorListener(MonitorListener l);
 	
 	/**
+	 * This method sets the protocol repository to use when
+	 * monitoring.
+	 * 
+	 * @param rep The protocol repository
+	 */
+	public void setProtocolRepository(ProtocolRepository rep);
+	
+	/**
 	 * This method sets the session store to use when
 	 * monitoring.
 	 * 
@@ -44,11 +57,16 @@
 	 * 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 boolean sent(ConversationInstanceId cid, Message mesg);
+	public boolean sent(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+							throws ProtocolUnknownException,
+									java.io.IOException ;
 	
 	/**
 	 * This method is used to indicate that a message has been
@@ -59,10 +77,15 @@
 	 * 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 boolean received(ConversationInstanceId cid, Message mesg);
+	public boolean received(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+							throws ProtocolUnknownException,
+									java.io.IOException ;
 	
 }

Modified: 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-16 21:58:53 UTC (rev 587)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/MonitorListener.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -17,6 +17,55 @@
  */
 package org.savara.monitor;
 
+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);
+	
 }

Added: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolRepository.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolRepository.java	                        (rev 0)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolRepository.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -0,0 +1,39 @@
+/*
+ * 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.scribble.protocol.monitor.model.Description;
+
+/**
+ * This interface represents a repository containing protocol descriptions
+ * used by the monitor.
+ *
+ */
+public interface ProtocolRepository {
+
+	/**
+	 * This method returns the protocol description associated with
+	 * the supplied protocol id (name and role).
+	 * 
+	 * @param pid The protocol id
+	 * @return The monitoring description for the protocol
+	 * @throws ProtocolUnknownException Failed to find protocol with the specified id
+	 */
+	public Description getProtocol(ProtocolId pid) throws ProtocolUnknownException;
+	
+}

Added: branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolUnknownException.java
===================================================================
--- branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolUnknownException.java	                        (rev 0)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/ProtocolUnknownException.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * This exceptions indicates that the protocol name or role is unknown.
+ *
+ */
+public class ProtocolUnknownException extends Exception {
+
+	private static final long serialVersionUID = -229297584119164988L;
+
+	/**
+	 * This constructor initializes the exception message.
+	 * 
+	 * @param mesg The message
+	 */
+	public ProtocolUnknownException(String mesg) {
+		super(mesg);
+	}
+}

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-16 21:58:53 UTC (rev 587)
+++ branches/experimental/2.0.x/bundles/org.savara.monitor/src/main/java/org/savara/monitor/impl/DefaultMonitor.java	2011-01-17 19:47:07 UTC (rev 588)
@@ -18,12 +18,19 @@
 package org.savara.monitor.impl;
 
 import org.savara.monitor.ConversationInstanceId;
+import org.savara.monitor.ProtocolId;
+import org.savara.monitor.ProtocolRepository;
+import org.savara.monitor.ProtocolUnknownException;
 import org.savara.monitor.SessionStore;
 import org.savara.monitor.Message;
 import org.savara.monitor.Monitor;
 import org.savara.monitor.MonitorListener;
 import org.scribble.protocol.monitor.DefaultProtocolMonitor;
+import org.scribble.protocol.monitor.MonitorContext;
 import org.scribble.protocol.monitor.ProtocolMonitor;
+import org.scribble.protocol.monitor.Result;
+import org.scribble.protocol.monitor.Session;
+import org.scribble.protocol.monitor.model.Description;
 
 /**
  * This class provides a default implementation of the
@@ -32,8 +39,9 @@
  */
 public class DefaultMonitor implements Monitor {
 
-	private MonitorListener m_listener=null;
-	private SessionStore m_store=null;
+	private MonitorListener m_monitorListener=null;
+	private ProtocolRepository m_protocolRepository=null;
+	private SessionStore m_sessionStore=null;
 	private ProtocolMonitor m_monitor=new DefaultProtocolMonitor();
 	
 	/**
@@ -52,17 +60,27 @@
 	 * @param l The monitor listener
 	 */
 	public void setMonitorListener(MonitorListener l) {
-		m_listener = l;
+		m_monitorListener = l;
 	}
 	
 	/**
+	 * This method sets the protocol repository to use when
+	 * monitoring.
+	 * 
+	 * @param rep The protocol repository
+	 */
+	public void setProtocolRepository(ProtocolRepository rep) {
+		m_protocolRepository = rep;
+	}
+	
+	/**
 	 * This method sets the session store to use when
 	 * monitoring.
 	 * 
 	 * @param store The session store
 	 */
 	public void setSessionStore(SessionStore store) {
-		m_store = store;
+		m_sessionStore = store;
 	}
 	
 	/**
@@ -74,13 +92,76 @@
 	 * 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 boolean sent(ConversationInstanceId cid, Message mesg) {
+	public boolean sent(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+							throws ProtocolUnknownException,
+									java.io.IOException {
 		boolean ret=false;
 		
+		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");
+		}
+		
+		// Check if conversation instance id should be derived
+		if (cid == null) {
+			// Derive conversation instance id
+			// TODO: Use ex
+		}
+		
+		Description desc=m_protocolRepository.getProtocol(pid);
+		
+		java.io.Serializable session=m_sessionStore.find(pid, cid);
+		
+		MonitorContext context=null;
+		
+		if (session == null) {
+			session = m_sessionStore.create(pid, cid);
+			
+			// 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);
+				}
+			}
+		}
+		
+		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.sendMessage(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);
+				}
+
+				m_sessionStore.remove(pid, cid);
+			} else {
+				m_sessionStore.update(pid, cid, session);
+			}
+		} else {
+			throw new java.io.IOException("Inappropriate session type returned");
+		}
+		
 		// Should instance id be derived from message, or supplied
 		// with message? If simulating, then identity should be
 		// fixed.
@@ -104,11 +185,16 @@
 	 * 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 boolean received(ConversationInstanceId cid, Message mesg) {
+	public boolean received(ProtocolId pid, ConversationInstanceId cid, Message mesg)
+							throws ProtocolUnknownException,
+							java.io.IOException {
 		boolean ret=false;
 		
 		return(ret);



More information about the savara-commits mailing list