[CVS spice] Add monitor for exceptions that happen during message delivery

proyal-yCVjj/[email protected] 12 Mar 2005 17:49:31 -0000
Newsgroups gmane.comp.java.spice.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>spice/components/message/src</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt>java/org/codehaus/spice/message/<a href="#file1"><span id="added">DestinationMonitor.java</span></a></tt></td><td align="right" id="added">+16</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file2"><span id="added">StdoutDestinationMonitor.java</span></a></tt></td><td align="right" id="added">+21</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file3">DestinationEventHandler.java</a></tt></td><td align="right" id="added">+11</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">1.1 -&gt; 1.2</td></tr>
<tr class="alt"><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file4">DestinationEventPipeline.java</a></tt></td><td align="right" id="added">+2</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">1.1 -&gt; 1.2</td></tr>
<tr><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file5">TransactionalMessageRouter.java</a></tt></td><td align="right" id="added">+9</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center">1.1 -&gt; 1.2</td></tr>
<tr class="alt"><td><tt>test/org/codehaus/spice/message/<a href="#file6">TransactionalMessageRouterTestCase.java</a></tt></td><td align="right" id="added">+2</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">1.1 -&gt; 1.2</td></tr>
<tr><td></td><td align="right" id="added">+61</td><td align="right" id="removed">-7</td><td></td></tr>
</table>
<small id="info">2 added + 4 modified, total 6 files</small><br />
<pre class="comment">
Add monitor for exceptions that happen during message delivery
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname" id="added">spice/components/message/src/java/org/codehaus/spice/message<br /></span>
<div class="fileheader" id="added"><big><b>DestinationMonitor.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationMonitor.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ DestinationMonitor.java	12 Mar 2005 17:49:30 -0000	1.1
@@ -0,0 +1,16 @@
</small></pre><pre class="diff" id="added">+/*
+ * Copyright (C) The Spice Group. All rights reserved.
+ *
+ * This software is published under the terms of the Spice
+ * Software License version 1.1, a copy of which has been included
+ * with this distribution in the LICENSE.txt file.
+ */
+package org.codehaus.spice.message;
+
+/**
+ * @author &lt;a href="mailto:[email protected]"&gt;peter royal&lt;/a&gt;
+ */
+public interface DestinationMonitor
+{
+    void deliveryFailed( Object message, Destination destination, Exception e );
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname" id="added">spice/components/message/src/java/org/codehaus/spice/message<br /></span>
<div class="fileheader" id="added"><big><b>StdoutDestinationMonitor.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N StdoutDestinationMonitor.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ StdoutDestinationMonitor.java	12 Mar 2005 17:49:30 -0000	1.1
@@ -0,0 +1,21 @@
</small></pre><pre class="diff" id="added">+/*
+ * Copyright (C) The Spice Group. All rights reserved.
+ *
+ * This software is published under the terms of the Spice
+ * Software License version 1.1, a copy of which has been included
+ * with this distribution in the LICENSE.txt file.
+ */
+package org.codehaus.spice.message;
+
+/**
+ * @author &lt;a href="mailto:[email protected]"&gt;peter royal&lt;/a&gt;
+ */
+public class StdoutDestinationMonitor implements DestinationMonitor
+{
+    public void deliveryFailed( final Object message, final Destination destination, final Exception e )
+    {
+        System.out.println( "Unable to send '" + message + "' to " + destination.getAddress() );
+
+        e.printStackTrace( System.out );
+    }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">spice/components/message/src/java/org/codehaus/spice/message<br /></span>
<div class="fileheader"><big><b>DestinationEventHandler.java</b></big> <small id="info">1.1 -&gt; 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- DestinationEventHandler.java	8 Mar 2005 02:58:48 -0000	1.1
+++ DestinationEventHandler.java	12 Mar 2005 17:49:30 -0000	1.2
@@ -17,15 +17,24 @@
</small></pre><pre class="diff" id="context"> class DestinationEventHandler implements EventHandler
 {
     private final Destination m_destination;
</pre><pre class="diff" id="added">+    private final DestinationMonitor m_monitor;
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">-    public DestinationEventHandler( final Destination destination )
</pre><pre class="diff" id="added">+    public DestinationEventHandler( final Destination destination<span id="addedchars">,&nbsp;final&nbsp;DestinationMonitor&nbsp;monitor</span> )
</pre><pre class="diff" id="context">     {
         m_destination = destination;
</pre><pre class="diff" id="added">+        m_monitor = monitor;
</pre><pre class="diff" id="context">     }
 
     public void handleEvent( final Object element )
     {
</pre><pre class="diff" id="removed">-        m_destination.deliver( element );
</pre><pre class="diff" id="added">+        try
+        {
+            m_destination.deliver( element );
+        }
+        catch( Exception e )
+        {
+            m_monitor.deliveryFailed( element, m_destination, e );
+        }
</pre><pre class="diff" id="context">     }
 
     public void handleEvents( final Object[] elements )
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname">spice/components/message/src/java/org/codehaus/spice/message<br /></span>
<div class="fileheader"><big><b>DestinationEventPipeline.java</b></big> <small id="info">1.1 -&gt; 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- DestinationEventPipeline.java	8 Mar 2005 02:58:48 -0000	1.1
+++ DestinationEventPipeline.java	12 Mar 2005 17:49:30 -0000	1.2
@@ -25,12 +25,12 @@
</small></pre><pre class="diff" id="context">     private final Source[] m_sources;
     private final EventHandler m_eventHandler;
 
</pre><pre class="diff" id="removed">-    public DestinationEventPipeline( final Destination destination )
</pre><pre class="diff" id="added">+    public DestinationEventPipeline( final Destination destination<span id="addedchars">,&nbsp;final&nbsp;DestinationMonitor&nbsp;monitor</span> )
</pre><pre class="diff" id="context">     {
 
         m_pipe = new DefaultPipe( new ValidMessageEnqueuePredicate( destination ) );
         m_sources = new Source[]{m_pipe};
</pre><pre class="diff" id="removed">-        m_eventHandler = new DestinationEventHandler( destination );
</pre><pre class="diff" id="added">+        m_eventHandler = new DestinationEventHandler( destination<span id="addedchars">,&nbsp;monitor</span> );
</pre><pre class="diff" id="context">     }
 
     Sink getSink()
</pre></div>
<hr /><a name="file5" /><div class="file">
<span class="pathname">spice/components/message/src/java/org/codehaus/spice/message<br /></span>
<div class="fileheader"><big><b>TransactionalMessageRouter.java</b></big> <small id="info">1.1 -&gt; 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- TransactionalMessageRouter.java	8 Mar 2005 02:58:48 -0000	1.1
+++ TransactionalMessageRouter.java	12 Mar 2005 17:49:30 -0000	1.2
@@ -34,9 +34,11 @@
</small></pre><pre class="diff" id="context"> 
     private final ThreadManager m_threadManager;
     private final TransactionManager m_transactionManager;
</pre><pre class="diff" id="added">+    private final DestinationMonitor m_monitor;
</pre><pre class="diff" id="context"> 
     public TransactionalMessageRouter( final ThreadManager threadManager,
</pre><pre class="diff" id="removed">-                                       final TransactionManager transactionManager<span id="removedchars">&nbsp;)</span>
</pre><pre class="diff" id="added">+                                       final TransactionManager transactionManager<span id="addedchars">,</span>
+                                       final DestinationMonitor monitor )
</pre><pre class="diff" id="context">     {
         if( null == threadManager )
         {
</pre><pre class="diff"><small id="info">@@ -46,9 +48,14 @@
</small></pre><pre class="diff" id="context">         {
             throw new NullPointerException( "transactionManager" );
         }
</pre><pre class="diff" id="added">+        else if( null == monitor )
+        {
+            throw new NullPointerException( "monitor" );
+        }
</pre><pre class="diff" id="context"> 
         m_threadManager = threadManager;
         m_transactionManager = transactionManager;
</pre><pre class="diff" id="added">+        m_monitor = monitor;
</pre><pre class="diff" id="context">     }
 
     public void register( final Destination destination ) throws DuplicateRegistrationException
</pre><pre class="diff"><small id="info">@@ -65,7 +72,7 @@
</small></pre><pre class="diff" id="context"> 
     private void addDestination( final Destination destination )
     {
</pre><pre class="diff" id="removed">-        final DestinationEventPipeline pipeline = new DestinationEventPipeline( destination );
</pre><pre class="diff" id="added">+        final DestinationEventPipeline pipeline = new DestinationEventPipeline( destination<span id="addedchars">,&nbsp;m_monitor</span> );
</pre><pre class="diff" id="context"> 
         m_threadManager.register( pipeline );
         m_registrations.put( destination.getAddress(), pipeline );
</pre></div>
<hr /><a name="file6" /><div class="file">
<span class="pathname">spice/components/message/src/test/org/codehaus/spice/message<br /></span>
<div class="fileheader"><big><b>TransactionalMessageRouterTestCase.java</b></big> <small id="info">1.1 -&gt; 1.2</small></div>
<pre class="diff"><small id="info">diff -u -r1.1 -r1.2
--- TransactionalMessageRouterTestCase.java	8 Mar 2005 02:58:51 -0000	1.1
+++ TransactionalMessageRouterTestCase.java	12 Mar 2005 17:49:30 -0000	1.2
@@ -28,7 +28,8 @@
</small></pre><pre class="diff" id="context"> 
         m_transactionalMessageRouter
             = new TransactionalMessageRouter( threadManager,
</pre><pre class="diff" id="removed">-                                              (TransactionManager)transactionManager.proxy()<span id="removedchars">&nbsp;);</span>
</pre><pre class="diff" id="added">+                                              (TransactionManager)transactionManager.proxy()<span id="addedchars">,</span>
+                                              new StdoutDestinationMonitor() );
</pre><pre class="diff" id="context">     }
 
     public void testUnregisterUnknownDestination() throws Exception
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.8</small></center>
</body></html>