[CVS spice] don't be a dufus and use the proper package name
proyal-yCVjj/[email protected] 8 Mar 2005 02:58:53 -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</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt>event/src/java/org/codehaus/spice/event/<a href="#file1"><span id="added">DefaultEventManager.java</span></a></tt></td><td align="right" id="added">+227</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file2"><span id="added">EventManagerRuntimeException.java</span></a></tt></td><td align="right" id="added">+24</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file3"><span id="added">EventPublisher.java</span></a></tt></td><td align="right" id="added">+18</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file4"><span id="added">EventRegister.java</span></a></tt></td><td align="right" id="added">+19</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file5"><span id="added">NoSuchSubscriberException.java</span></a></tt></td><td align="right" id="added">+18</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file6"><span id="added">PublicationException.java</span></a></tt></td><td align="right" id="added">+32</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file7"><span id="added">Subscriber.java</span></a></tt></td><td align="right" id="added">+25</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file8"><span id="added">TupleMemberNotNullCondition.java</span></a></tt></td><td align="right" id="added">+41</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt>event/src/java/org/spice/event/<a href="#file9"><span id="removed">ClassObjectType.java</span></a></tt></td><td></td><td align="right" id="removed">-55</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file10"><span id="removed">DefaultEventManager.java</span></a></tt></td><td></td><td align="right" id="removed">-227</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file11"><span id="removed">EventManagerRuntimeException.java</span></a></tt></td><td></td><td align="right" id="removed">-24</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file12"><span id="removed">EventPublisher.java</span></a></tt></td><td></td><td align="right" id="removed">-18</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file13"><span id="removed">EventRegister.java</span></a></tt></td><td></td><td align="right" id="removed">-19</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file14"><span id="removed">NoSuchSubscriberException.java</span></a></tt></td><td></td><td align="right" id="removed">-18</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file15"><span id="removed">PublicationException.java</span></a></tt></td><td></td><td align="right" id="removed">-32</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file16"><span id="removed">Subscriber.java</span></a></tt></td><td></td><td align="right" id="removed">-25</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file17"><span id="removed">TupleMemberNotNullCondition.java</span></a></tt></td><td></td><td align="right" id="removed">-41</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt>event/src/test/org/codehaus/spice/event/<a href="#file18"><span id="added">DefaultEventManagerTestCase.java</span></a></tt></td><td align="right" id="added">+94</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt>event/src/test/org/spice/event/<a href="#file19"><span id="removed">DefaultEventManagerTestCase.java</span></a></tt></td><td></td><td align="right" id="removed">-94</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt>message/src/java/org/codehaus/spice/message/<a href="#file20"><span id="added">Destination.java</span></a></tt></td><td align="right" id="added">+43</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file21"><span id="added">DestinationEventHandler.java</span></a></tt></td><td align="right" id="added">+38</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file22"><span id="added">DestinationEventPipeline.java</span></a></tt></td><td align="right" id="added">+50</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file23"><span id="added">DestinationRegistrar.java</span></a></tt></td><td align="right" id="added">+34</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file24"><span id="added">Dispatcher.java</span></a></tt></td><td align="right" id="added">+30</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file25"><span id="added">DuplicateRegistrationException.java</span></a></tt></td><td align="right" id="added">+27</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file26"><span id="added">InvalidMessageException.java</span></a></tt></td><td align="right" id="added">+35</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file27"><span id="added">MessageException.java</span></a></tt></td><td align="right" id="added">+19</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file28"><span id="added">MessageTransactionSynchronization.java</span></a></tt></td><td align="right" id="added">+69</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file29"><span id="added">NoSuchDestinationException.java</span></a></tt></td><td align="right" id="added">+27</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt> /<a href="#file30"><span id="added">TransactionalMessageRouter.java</span></a></tt></td><td align="right" id="added">+168</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt> /<a href="#file31"><span id="added">ValidMessageEnqueuePredicate.java</span></a></tt></td><td align="right" id="added">+44</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr class="alt"><td><tt>message/src/java/org/spice/message/<a href="#file32"><span id="removed">Destination.java</span></a></tt></td><td></td><td align="right" id="removed">-43</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file33"><span id="removed">DestinationEventHandler.java</span></a></tt></td><td></td><td align="right" id="removed">-38</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file34"><span id="removed">DestinationEventPipeline.java</span></a></tt></td><td></td><td align="right" id="removed">-50</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file35"><span id="removed">DestinationRegistrar.java</span></a></tt></td><td></td><td align="right" id="removed">-34</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file36"><span id="removed">Dispatcher.java</span></a></tt></td><td></td><td align="right" id="removed">-30</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file37"><span id="removed">DuplicateRegistrationException.java</span></a></tt></td><td></td><td align="right" id="removed">-27</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file38"><span id="removed">InvalidMessageException.java</span></a></tt></td><td></td><td align="right" id="removed">-35</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file39"><span id="removed">MessageException.java</span></a></tt></td><td></td><td align="right" id="removed">-19</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file40"><span id="removed">MessageTransactionSynchronization.java</span></a></tt></td><td></td><td align="right" id="removed">-69</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file41"><span id="removed">NoSuchDestinationException.java</span></a></tt></td><td></td><td align="right" id="removed">-27</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt> /<a href="#file42"><span id="removed">TransactionalMessageRouter.java</span></a></tt></td><td></td><td align="right" id="removed">-168</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td><tt> /<a href="#file43"><span id="removed">ValidMessageEnqueuePredicate.java</span></a></tt></td><td></td><td align="right" id="removed">-44</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr class="alt"><td><tt>message/src/test/org/codehaus/spice/message/<a href="#file44"><span id="added">TransactionalMessageRouterTestCase.java</span></a></tt></td><td align="right" id="added">+86</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
<tr><td><tt>message/src/test/org/spice/message/<a href="#file45"><span id="removed">TransactionalMessageRouterTestCase.java</span></a></tt></td><td></td><td align="right" id="removed">-86</td><td nowrap="nowrap">1.1 removed</td></tr>
<tr><td></td><td align="right" id="added">+1168</td><td align="right" id="removed">-1223</td><td></td></tr>
</table>
<small id="info">22 added + 23 removed, total 45 files</small><br />
<pre class="comment">
don't be a dufus and use the proper package name
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>DefaultEventManager.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DefaultEventManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultEventManager.java 8 Mar 2005 02:58:25 -0000 1.1
@@ -0,0 +1,227 @@
</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.event;
+
+import java.util.EventObject;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.apache.avalon.framework.logger.Logger;
+
+import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
+import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
+import EDU.oswego.cs.dl.util.concurrent.ReaderPreferenceReadWriteLock;
+import EDU.oswego.cs.dl.util.concurrent.SyncMap;
+import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+import org.drools.FactException;
+import org.drools.RuleBase;
+import org.drools.RuleBaseBuilder;
+import org.drools.RuleIntegrationException;
+import org.drools.RuleSetIntegrationException;
+import org.drools.WorkingMemory;
+import org.drools.rule.RuleSet;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class DefaultEventManager implements EventPublisher, EventRegister
+{
+ private final Set m_subscribers = new CopyOnWriteArraySet();
+ private final ReadWriteLock m_lock = new WriterPreferenceReadWriteLock();
+ private final Map m_workingMemories = new SyncMap( new WeakHashMap(), new ReaderPreferenceReadWriteLock() );
+
+ private final Logger m_logger;
+ private final TransactionManager m_transactionManager;
+
+ private RuleBase m_ruleBase;
+
+ public DefaultEventManager( final TransactionManager transactionManager,
+ final Logger logger )
+ throws RuleIntegrationException, RuleSetIntegrationException
+ {
+ m_transactionManager = transactionManager;
+ m_logger = logger;
+
+ rebuildRuleBase();
+ }
+
+ public void publish( final EventObject event )
+ {
+ try
+ {
+ m_lock.readLock().acquire();
+ }
+ catch( InterruptedException e )
+ {
+ throw new RuntimeException( "Unable to aquire read lock on RuleBase", e );
+ }
+
+ try
+ {
+ final WorkingMemory workingMemory = getWorkingMemory();
+
+ workingMemory.assertObject( event );
+ workingMemory.fireAllRules();
+ }
+ catch( FactException e )
+ {
+ throw new PublicationException( event, e );
+ }
+ catch( SystemException e )
+ {
+ throw new RuntimeException( "Transaction failure when processing event '" + event + "'", e );
+ }
+ finally
+ {
+ m_lock.readLock().release();
+ }
+ }
+
+ /**
+ * Get the <code>WorkingMemory</code> for the in-progress transaction. If there is no transaction in progress, a new
+ * <code>WorkingMemory</code> is returned.
+ *
+ * We are only checking against the current Transaction instance, and not registering an XAResource since we don't
+ * care about doing anything on commit/rollback.
+ *
+ * @return <code>WorkingMemory</code> instance
+ *
+ * @throws SystemException on failure to get current <code>Transaction</code>
+ */
+ private WorkingMemory getWorkingMemory() throws SystemException
+ {
+ final Transaction transaction = m_transactionManager.getTransaction();
+
+ if( null == transaction )
+ {
+ return m_ruleBase.newWorkingMemory();
+ }
+ else
+ {
+ WorkingMemory workingMemory = (WorkingMemory)m_workingMemories.get( transaction );
+
+ if( null == workingMemory )
+ {
+ workingMemory = m_ruleBase.newWorkingMemory();
+
+ m_workingMemories.put( transaction, workingMemory );
+ }
+
+ return workingMemory;
+ }
+ }
+
+ public void subscribe( final Subscriber subscriber )
+ {
+ if( null == subscriber )
+ {
+ throw new NullPointerException( "subscriber" );
+ }
+
+ if( getLogger().isDebugEnabled() ) getLogger().debug( "Adding subscriber: " + subscriber );
+
+ m_subscribers.add( subscriber );
+
+ try
+ {
+ rebuildRuleBase();
+ }
+ catch( RuleIntegrationException e )
+ {
+ final String msg = "Unable to rebuild RuleBase after adding Subscriber. "
+ + "Reported '" + e.getMessage() + "' on rule: " + e.getRule();
+
+ throw new EventManagerRuntimeException( msg, e );
+ }
+ catch( RuleSetIntegrationException e )
+ {
+ final String msg = "Unable to rebuild RuleBase after adding Subscriber. "
+ + "Reported '" + e.getMessage() + "' on ruleset: " + e.getRuleSet().getName();
+
+ throw new EventManagerRuntimeException( msg, e );
+ }
+ }
+
+ public void unsubscribe( final Subscriber subscriber ) throws NoSuchSubscriberException
+ {
+ if( m_subscribers.remove( subscriber ) )
+ {
+ try
+ {
+ rebuildRuleBase();
+ }
+ catch( RuleIntegrationException e )
+ {
+ final String msg = "Unable to rebuild RuleBase after removing Subscriber. Subscriber modified rules "
+ + "after initial subscription or internal drools error. "
+ + "Reported '" + e.getMessage() + "' on rule: " + e.getRule();
+
+ throw new EventManagerRuntimeException( msg, e );
+ }
+ catch( RuleSetIntegrationException e )
+ {
+ final String msg = "Unable to rebuild RuleBase after removing Subscriber. Subscriber modified rules "
+ + "after initial subscription or internal drools error. "
+ + "Reported '" + e.getMessage() + "' on ruleset: " + e.getRuleSet().getName();
+
+ throw new EventManagerRuntimeException( msg, e );
+ }
+ }
+ else
+ {
+ throw new NoSuchSubscriberException();
+ }
+ }
+
+ private void rebuildRuleBase() throws RuleIntegrationException, RuleSetIntegrationException
+ {
+ try
+ {
+ m_lock.writeLock().acquire();
+ }
+ catch( InterruptedException e )
+ {
+ throw new RuntimeException( "Unable to aquire write lock on RuleBase", e );
+ }
+
+ try
+ {
+ final RuleBaseBuilder builder = new RuleBaseBuilder();
+ final Iterator i = m_subscribers.iterator();
+
+ while( i.hasNext() )
+ {
+ final Subscriber subscriber = (Subscriber)i.next();
+ final RuleSet ruleSet = subscriber.getRuleSet();
+
+ if( null == ruleSet )
+ {
+ throw new EventManagerRuntimeException( "Subscriber had null RuleSet" );
+ }
+
+ builder.addRuleSet( ruleSet );
+ }
+
+ m_ruleBase = builder.build();
+ }
+ finally
+ {
+ m_lock.writeLock().release();
+ }
+ }
+
+ private Logger getLogger()
+ {
+ return m_logger;
+ }
+}
</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/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>EventManagerRuntimeException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventManagerRuntimeException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EventManagerRuntimeException.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,24 @@
</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.event;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class EventManagerRuntimeException extends RuntimeException
+{
+ public EventManagerRuntimeException( final String message, final Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public EventManagerRuntimeException( final String message )
+ {
+ super( message );
+ }
+}
</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" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>EventPublisher.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventPublisher.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EventPublisher.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,18 @@
</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.event;
+
+import java.util.EventObject;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface EventPublisher
+{
+ void publish( EventObject event );
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>EventRegister.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventRegister.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ EventRegister.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,19 @@
</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.event;
+
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface EventRegister
+{
+ void subscribe( Subscriber subscriber );
+
+ void unsubscribe( Subscriber subscriber ) throws NoSuchSubscriberException;
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file5" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>NoSuchSubscriberException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N NoSuchSubscriberException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NoSuchSubscriberException.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,18 @@
</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.event;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class NoSuchSubscriberException extends Exception
+{
+ public NoSuchSubscriberException()
+ {
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file6" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>PublicationException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N PublicationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PublicationException.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,32 @@
</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.event;
+
+import java.util.EventObject;
+
+import org.drools.FactException;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class PublicationException extends RuntimeException
+{
+ private final EventObject m_event;
+
+ public PublicationException( final EventObject event, final FactException e )
+ {
+ super( "Unable to publish event '" + event + "' due to " + e.getMessage(), e );
+
+ m_event = event;
+ }
+
+ public EventObject getEvent()
+ {
+ return m_event;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file7" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>Subscriber.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N Subscriber.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Subscriber.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,25 @@
</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.event;
+
+import java.util.EventListener;
+
+import org.drools.rule.RuleSet;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface Subscriber extends EventListener
+{
+ /**
+ * Get the {@link RuleSet} that will drive the events that this Subscriber gets notified of.
+ *
+ * @return RuleSet instance. Must never be null.
+ */
+ RuleSet getRuleSet();
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file8" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/java/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>TupleMemberNotNullCondition.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N TupleMemberNotNullCondition.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TupleMemberNotNullCondition.java 8 Mar 2005 02:58:26 -0000 1.1
@@ -0,0 +1,41 @@
</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.event;
+
+import org.drools.rule.Declaration;
+import org.drools.spi.Condition;
+import org.drools.spi.ConditionException;
+import org.drools.spi.Tuple;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class TupleMemberNotNullCondition implements Condition
+{
+ private final Declaration m_declaration;
+
+ public TupleMemberNotNullCondition( final Declaration declaration )
+ {
+ if( null == declaration )
+ {
+ throw new NullPointerException( "declaration" );
+ }
+
+ m_declaration = declaration;
+ }
+
+ public Declaration[] getRequiredTupleMembers()
+ {
+ return new Declaration[]{m_declaration};
+ }
+
+ public boolean isAllowed( final Tuple tuple ) throws ConditionException
+ {
+ return null != tuple.get( m_declaration );
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file9" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>ClassObjectType.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N ClassObjectType.java
--- ClassObjectType.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,55 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import org.drools.spi.ObjectType;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class ClassObjectType implements ObjectType
-{
- private final Class m_clazz;
-
- public ClassObjectType( final Class clazz )
- {
- if( null == clazz )
- {
- throw new NullPointerException( "clazz" );
- }
-
- m_clazz = clazz;
- }
-
- public Class getType()
- {
- return m_clazz;
- }
-
- public boolean matches( final Object object )
- {
- return getType().isInstance( object );
- }
-
- public boolean equals( final Object o )
- {
- if( this == o ) return true;
- if( !( o instanceof ClassObjectType ) ) return false;
-
- final ClassObjectType classObjectType = (ClassObjectType)o;
-
- if( !getType().equals( classObjectType.getType() ) ) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- return m_clazz.hashCode();
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file10" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>DefaultEventManager.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DefaultEventManager.java
--- DefaultEventManager.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,227 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import java.util.EventObject;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.apache.avalon.framework.logger.Logger;
-
-import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
-import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
-import EDU.oswego.cs.dl.util.concurrent.ReaderPreferenceReadWriteLock;
-import EDU.oswego.cs.dl.util.concurrent.SyncMap;
-import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
-import org.drools.FactException;
-import org.drools.RuleBase;
-import org.drools.RuleBaseBuilder;
-import org.drools.RuleIntegrationException;
-import org.drools.RuleSetIntegrationException;
-import org.drools.WorkingMemory;
-import org.drools.rule.RuleSet;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class DefaultEventManager implements EventPublisher, EventRegister
-{
- private final Set m_subscribers = new CopyOnWriteArraySet();
- private final ReadWriteLock m_lock = new WriterPreferenceReadWriteLock();
- private final Map m_workingMemories = new SyncMap( new WeakHashMap(), new ReaderPreferenceReadWriteLock() );
-
- private final Logger m_logger;
- private final TransactionManager m_transactionManager;
-
- private RuleBase m_ruleBase;
-
- public DefaultEventManager( final TransactionManager transactionManager,
- final Logger logger )
- throws RuleIntegrationException, RuleSetIntegrationException
- {
- m_transactionManager = transactionManager;
- m_logger = logger;
-
- rebuildRuleBase();
- }
-
- public void publish( final EventObject event )
- {
- try
- {
- m_lock.readLock().acquire();
- }
- catch( InterruptedException e )
- {
- throw new RuntimeException( "Unable to aquire read lock on RuleBase", e );
- }
-
- try
- {
- final WorkingMemory workingMemory = getWorkingMemory();
-
- workingMemory.assertObject( event );
- workingMemory.fireAllRules();
- }
- catch( FactException e )
- {
- throw new PublicationException( event, e );
- }
- catch( SystemException e )
- {
- throw new RuntimeException( "Transaction failure when processing event '" + event + "'", e );
- }
- finally
- {
- m_lock.readLock().release();
- }
- }
-
- /**
- * Get the <code>WorkingMemory</code> for the in-progress transaction. If there is no transaction in progress, a new
- * <code>WorkingMemory</code> is returned.
- *
- * We are only checking against the current Transaction instance, and not registering an XAResource since we don't
- * care about doing anything on commit/rollback.
- *
- * @return <code>WorkingMemory</code> instance
- *
- * @throws SystemException on failure to get current <code>Transaction</code>
- */
- private WorkingMemory getWorkingMemory() throws SystemException
- {
- final Transaction transaction = m_transactionManager.getTransaction();
-
- if( null == transaction )
- {
- return m_ruleBase.newWorkingMemory();
- }
- else
- {
- WorkingMemory workingMemory = (WorkingMemory)m_workingMemories.get( transaction );
-
- if( null == workingMemory )
- {
- workingMemory = m_ruleBase.newWorkingMemory();
-
- m_workingMemories.put( transaction, workingMemory );
- }
-
- return workingMemory;
- }
- }
-
- public void subscribe( final Subscriber subscriber )
- {
- if( null == subscriber )
- {
- throw new NullPointerException( "subscriber" );
- }
-
- if( getLogger().isDebugEnabled() ) getLogger().debug( "Adding subscriber: " + subscriber );
-
- m_subscribers.add( subscriber );
-
- try
- {
- rebuildRuleBase();
- }
- catch( RuleIntegrationException e )
- {
- final String msg = "Unable to rebuild RuleBase after adding Subscriber. "
- + "Reported '" + e.getMessage() + "' on rule: " + e.getRule();
-
- throw new EventManagerRuntimeException( msg, e );
- }
- catch( RuleSetIntegrationException e )
- {
- final String msg = "Unable to rebuild RuleBase after adding Subscriber. "
- + "Reported '" + e.getMessage() + "' on ruleset: " + e.getRuleSet().getName();
-
- throw new EventManagerRuntimeException( msg, e );
- }
- }
-
- public void unsubscribe( final Subscriber subscriber ) throws NoSuchSubscriberException
- {
- if( m_subscribers.remove( subscriber ) )
- {
- try
- {
- rebuildRuleBase();
- }
- catch( RuleIntegrationException e )
- {
- final String msg = "Unable to rebuild RuleBase after removing Subscriber. Subscriber modified rules "
- + "after initial subscription or internal drools error. "
- + "Reported '" + e.getMessage() + "' on rule: " + e.getRule();
-
- throw new EventManagerRuntimeException( msg, e );
- }
- catch( RuleSetIntegrationException e )
- {
- final String msg = "Unable to rebuild RuleBase after removing Subscriber. Subscriber modified rules "
- + "after initial subscription or internal drools error. "
- + "Reported '" + e.getMessage() + "' on ruleset: " + e.getRuleSet().getName();
-
- throw new EventManagerRuntimeException( msg, e );
- }
- }
- else
- {
- throw new NoSuchSubscriberException();
- }
- }
-
- private void rebuildRuleBase() throws RuleIntegrationException, RuleSetIntegrationException
- {
- try
- {
- m_lock.writeLock().acquire();
- }
- catch( InterruptedException e )
- {
- throw new RuntimeException( "Unable to aquire write lock on RuleBase", e );
- }
-
- try
- {
- final RuleBaseBuilder builder = new RuleBaseBuilder();
- final Iterator i = m_subscribers.iterator();
-
- while( i.hasNext() )
- {
- final Subscriber subscriber = (Subscriber)i.next();
- final RuleSet ruleSet = subscriber.getRuleSet();
-
- if( null == ruleSet )
- {
- throw new EventManagerRuntimeException( "Subscriber had null RuleSet" );
- }
-
- builder.addRuleSet( ruleSet );
- }
-
- m_ruleBase = builder.build();
- }
- finally
- {
- m_lock.writeLock().release();
- }
- }
-
- private Logger getLogger()
- {
- return m_logger;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file11" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>EventManagerRuntimeException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventManagerRuntimeException.java
--- EventManagerRuntimeException.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,24 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class EventManagerRuntimeException extends RuntimeException
-{
- public EventManagerRuntimeException( final String message, final Throwable cause )
- {
- super( message, cause );
- }
-
- public EventManagerRuntimeException( final String message )
- {
- super( message );
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file12" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>EventPublisher.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventPublisher.java
--- EventPublisher.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,18 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import java.util.EventObject;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface EventPublisher
-{
- void publish( EventObject event );
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file13" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>EventRegister.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N EventRegister.java
--- EventRegister.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,19 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface EventRegister
-{
- void subscribe( Subscriber subscriber );
-
- void unsubscribe( Subscriber subscriber ) throws NoSuchSubscriberException;
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file14" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>NoSuchSubscriberException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N NoSuchSubscriberException.java
--- NoSuchSubscriberException.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,18 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class NoSuchSubscriberException extends Exception
-{
- public NoSuchSubscriberException()
- {
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file15" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>PublicationException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N PublicationException.java
--- PublicationException.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import java.util.EventObject;
-
-import org.drools.FactException;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class PublicationException extends RuntimeException
-{
- private final EventObject m_event;
-
- public PublicationException( final EventObject event, final FactException e )
- {
- super( "Unable to publish event '" + event + "' due to " + e.getMessage(), e );
-
- m_event = event;
- }
-
- public EventObject getEvent()
- {
- return m_event;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file16" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>Subscriber.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N Subscriber.java
--- Subscriber.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,25 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import java.util.EventListener;
-
-import org.drools.rule.RuleSet;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface Subscriber extends EventListener
-{
- /**
- * Get the {@link RuleSet} that will drive the events that this Subscriber gets notified of.
- *
- * @return RuleSet instance. Must never be null.
- */
- RuleSet getRuleSet();
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file17" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/java/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>TupleMemberNotNullCondition.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N TupleMemberNotNullCondition.java
--- TupleMemberNotNullCondition.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,41 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import org.drools.rule.Declaration;
-import org.drools.spi.Condition;
-import org.drools.spi.ConditionException;
-import org.drools.spi.Tuple;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class TupleMemberNotNullCondition implements Condition
-{
- private final Declaration m_declaration;
-
- public TupleMemberNotNullCondition( final Declaration declaration )
- {
- if( null == declaration )
- {
- throw new NullPointerException( "declaration" );
- }
-
- m_declaration = declaration;
- }
-
- public Declaration[] getRequiredTupleMembers()
- {
- return new Declaration[]{m_declaration};
- }
-
- public boolean isAllowed( final Tuple tuple ) throws ConditionException
- {
- return null != tuple.get( m_declaration );
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file18" /><div class="file">
<span class="pathname" id="added">spice/components/event/src/test/org/codehaus/spice/event<br /></span>
<div class="fileheader" id="added"><big><b>DefaultEventManagerTestCase.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DefaultEventManagerTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultEventManagerTestCase.java 8 Mar 2005 02:58:47 -0000 1.1
@@ -0,0 +1,94 @@
</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.event;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+
+import junit.framework.TestCase;
+import org.drools.RuleIntegrationException;
+import org.drools.rule.RuleSet;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class DefaultEventManagerTestCase extends TestCase
+{
+ private DefaultEventManager m_eventManager;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ m_eventManager = new DefaultEventManager( null, new ConsoleLogger() );
+ }
+
+ public void testRegisterUnregister() throws Exception
+ {
+ final MockSubscriber subscriber = new MockSubscriber( new RuleSet( "test" ) );
+
+ m_eventManager.subscribe( subscriber );
+ m_eventManager.unsubscribe( subscriber );
+ }
+
+ public void testUnregisterWithoutRegister() throws Exception
+ {
+ try
+ {
+ m_eventManager.unsubscribe( new MockSubscriber( null ) );
+
+ fail( "Do not allow unsubscribe without subscribe" );
+ }
+ catch( NoSuchSubscriberException e )
+ {
+ assertTrue( "nothing registered", true );
+ }
+ }
+
+ public void testRegisterNull() throws RuleIntegrationException
+ {
+ try
+ {
+ m_eventManager.subscribe( null );
+
+ fail( "Did not throw NPE upon registering null" );
+ }
+ catch( NullPointerException e )
+ {
+ assertEquals( "subscriber", e.getMessage() );
+ }
+ }
+
+ public void testRegisterWithNullRuleset() throws RuleIntegrationException
+ {
+ try
+ {
+ m_eventManager.subscribe( new MockSubscriber( null ) );
+
+ fail( "Cannot register null ruleset" );
+ }
+ catch( EventManagerRuntimeException e )
+ {
+ assertEquals( "Subscriber had null RuleSet", e.getMessage() );
+ }
+ }
+
+ private static class MockSubscriber implements Subscriber
+ {
+ private final RuleSet m_ruleSet;
+
+ public MockSubscriber( final RuleSet ruleSet )
+ {
+ m_ruleSet = ruleSet;
+ }
+
+ public RuleSet getRuleSet()
+ {
+ return m_ruleSet;
+ }
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file19" /><div class="file">
<span class="pathname" id="removed">spice/components/event/src/test/org/spice/event<br /></span>
<div class="fileheader" id="removed"><big><b>DefaultEventManagerTestCase.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DefaultEventManagerTestCase.java
--- DefaultEventManagerTestCase.java 2 Mar 2005 19:33:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,94 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.event;
-
-import org.apache.avalon.framework.logger.ConsoleLogger;
-
-import junit.framework.TestCase;
-import org.drools.RuleIntegrationException;
-import org.drools.rule.RuleSet;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class DefaultEventManagerTestCase extends TestCase
-{
- private DefaultEventManager m_eventManager;
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- m_eventManager = new DefaultEventManager( null, new ConsoleLogger() );
- }
-
- public void testRegisterUnregister() throws Exception
- {
- final MockSubscriber subscriber = new MockSubscriber( new RuleSet( "test" ) );
-
- m_eventManager.subscribe( subscriber );
- m_eventManager.unsubscribe( subscriber );
- }
-
- public void testUnregisterWithoutRegister() throws Exception
- {
- try
- {
- m_eventManager.unsubscribe( new MockSubscriber( null ) );
-
- fail( "Do not allow unsubscribe without subscribe" );
- }
- catch( NoSuchSubscriberException e )
- {
- assertTrue( "nothing registered", true );
- }
- }
-
- public void testRegisterNull() throws RuleIntegrationException
- {
- try
- {
- m_eventManager.subscribe( null );
-
- fail( "Did not throw NPE upon registering null" );
- }
- catch( NullPointerException e )
- {
- assertEquals( "subscriber", e.getMessage() );
- }
- }
-
- public void testRegisterWithNullRuleset() throws RuleIntegrationException
- {
- try
- {
- m_eventManager.subscribe( new MockSubscriber( null ) );
-
- fail( "Cannot register null ruleset" );
- }
- catch( EventManagerRuntimeException e )
- {
- assertEquals( "Subscriber had null RuleSet", e.getMessage() );
- }
- }
-
- private static class MockSubscriber implements Subscriber
- {
- private final RuleSet m_ruleSet;
-
- public MockSubscriber( final RuleSet ruleSet )
- {
- m_ruleSet = ruleSet;
- }
-
- public RuleSet getRuleSet()
- {
- return m_ruleSet;
- }
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file20" /><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>Destination.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N Destination.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Destination.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,43 @@
</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;
+
+/**
+ * A Message Destination receives messages for a named destination.
+ *
+ * Message objects will be specific to the destination implementation. Please consult destination documentation on what
+ * constitutes valid messages.
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface Destination
+{
+ /**
+ * Get the address of this destination.
+ *
+ * @return Address of destination. Required.
+ */
+ String getAddress();
+
+ /**
+ * Is the specified message a valid message for this destination? This method is just to check message validity. All
+ * valid messages must be delivered without throwing any exceptions.
+ *
+ * @param message Message object to validate. Required.
+ *
+ * @return True if the message is valid for this destination.
+ */
+ boolean isValidMessage( Object message );
+
+ /**
+ * Deliver a message. Messages should first be tested for validity with {@link #isValidMessage(Object)}.
+ *
+ * @param message Message to deliver.
+ */
+ void deliver( Object message );
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file21" /><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>DestinationEventHandler.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationEventHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DestinationEventHandler.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,38 @@
</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;
+
+import org.d_haven.event.EventHandler;
+
+/**
+ * EventHandler that passes messages on to a Destination
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+class DestinationEventHandler implements EventHandler
+{
+ private final Destination m_destination;
+
+ public DestinationEventHandler( final Destination destination )
+ {
+ m_destination = destination;
+ }
+
+ public void handleEvent( final Object element )
+ {
+ m_destination.deliver( element );
+ }
+
+ public void handleEvents( final Object[] elements )
+ {
+ for( int i = 0; i < elements.length; i++ )
+ {
+ handleEvent( elements[i] );
+ }
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file22" /><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>DestinationEventPipeline.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationEventPipeline.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DestinationEventPipeline.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,50 @@
</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;
+
+import org.d_haven.event.EventHandler;
+import org.d_haven.event.Pipe;
+import org.d_haven.event.Sink;
+import org.d_haven.event.Source;
+import org.d_haven.event.command.EventPipeline;
+import org.d_haven.event.impl.DefaultPipe;
+
+/**
+ * EventPipeline that manages a Destination, only allowing value messages to be enqueued.
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+class DestinationEventPipeline implements EventPipeline
+{
+ private final Pipe m_pipe;
+ private final Source[] m_sources;
+ private final EventHandler m_eventHandler;
+
+ public DestinationEventPipeline( final Destination destination )
+ {
+
+ m_pipe = new DefaultPipe( new ValidMessageEnqueuePredicate( destination ) );
+ m_sources = new Source[]{m_pipe};
+ m_eventHandler = new DestinationEventHandler( destination );
+ }
+
+ Sink getSink()
+ {
+ return m_pipe;
+ }
+
+ public EventHandler getEventHandler()
+ {
+ return m_eventHandler;
+ }
+
+ public Source[] getSources()
+ {
+ return m_sources;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file23" /><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>DestinationRegistrar.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationRegistrar.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DestinationRegistrar.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,34 @@
</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;
+
+/**
+ * Registrar that deals with {@link Destination}s.
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface DestinationRegistrar
+{
+ /**
+ * Register a destination
+ *
+ * @param destination Destination to register. required.
+ *
+ * @throws DuplicateRegistrationException If this destination has already been registered
+ */
+ void register( Destination destination ) throws DuplicateRegistrationException;
+
+ /**
+ * Unregister a destination
+ *
+ * @param destination Destination to unregister. required.
+ *
+ * @throws NoSuchDestinationException If this destination has never been registered
+ */
+ void unregister( Destination destination ) throws NoSuchDestinationException;
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file24" /><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>Dispatcher.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N Dispatcher.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Dispatcher.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,30 @@
</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;
+
+/**
+ * A Messenger allows clients to send messages to specific named addresses.
+ *
+ * If a message is sent to an unknown address, it will merely end up in the discarded message box. The sender will not
+ * be informed.
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public interface Dispatcher
+{
+ /**
+ * Send a message to an address. Delivery is guaranteed if the destintion exists. If the destination does not exist,
+ * no notification will occur.
+ *
+ * @param address Address to send message to. Required.
+ * @param message Message to send. Required.
+ *
+ * @throws InvalidMessageException if a message is invalid
+ */
+ void send( String address, Object message );
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file25" /><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>DuplicateRegistrationException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N DuplicateRegistrationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DuplicateRegistrationException.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,27 @@
</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 <a href="mailto:[email protected]">peter royal</a>
+ */
+public class DuplicateRegistrationException extends MessageException
+{
+ private final Destination m_destination;
+
+ public DuplicateRegistrationException( final Destination destination )
+ {
+ super( "Destination with address '" + destination.getAddress() + "' already registered" );
+ m_destination = destination;
+ }
+
+ public Destination getDestination()
+ {
+ return m_destination;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file26" /><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>InvalidMessageException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N InvalidMessageException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ InvalidMessageException.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,35 @@
</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 <a href="mailto:[email protected]">peter royal</a>
+ */
+public class InvalidMessageException extends RuntimeException
+{
+ private final String m_address;
+ private final Object m_invalidMessage;
+
+ public InvalidMessageException( final String address, final Object invalidMessage )
+ {
+ super( "Invalid invalidMessage '" + invalidMessage + "' for destination '" + address + "'" );
+
+ m_address = address;
+ m_invalidMessage = invalidMessage;
+ }
+
+ public String getAddress()
+ {
+ return m_address;
+ }
+
+ public Object getInvalidMessage()
+ {
+ return m_invalidMessage;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file27" /><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>MessageException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N MessageException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MessageException.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,19 @@
</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 <a href="mailto:[email protected]">peter royal</a>
+ */
+public class MessageException extends Exception
+{
+ public MessageException( final String message )
+ {
+ super( message );
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file28" /><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>MessageTransactionSynchronization.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N MessageTransactionSynchronization.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MessageTransactionSynchronization.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,69 @@
</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;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.d_haven.event.PreparedEnqueue;
+
+/**
+ * <code>Synchronization</code> That deals with PreparedEnqueue objects
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+class MessageTransactionSynchronization implements Synchronization
+{
+ private final List m_enqueues = new ArrayList();
+
+ public void commit()
+ {
+ final Iterator i = m_enqueues.iterator();
+
+ while( i.hasNext() )
+ {
+ ( (PreparedEnqueue)i.next() ).commit();
+ }
+ }
+
+ public void rollback()
+ {
+ final Iterator i = m_enqueues.iterator();
+
+ while( i.hasNext() )
+ {
+ ( (PreparedEnqueue)i.next() ).abort();
+ }
+ }
+
+ void addEnqueue( final PreparedEnqueue enqueue )
+ {
+ m_enqueues.add( enqueue );
+ }
+
+ public void afterCompletion( final int status )
+ {
+ switch( status )
+ {
+ case Status.STATUS_COMMITTED:
+ commit();
+ break;
+ default:
+ rollback();
+ ;
+ break;
+ }
+ }
+
+ public void beforeCompletion()
+ {
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file29" /><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>NoSuchDestinationException.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N NoSuchDestinationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NoSuchDestinationException.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,27 @@
</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 <a href="mailto:[email protected]">peter royal</a>
+ */
+public class NoSuchDestinationException extends MessageException
+{
+ private final Destination m_destination;
+
+ public NoSuchDestinationException( final Destination destination )
+ {
+ super( "Unknown destination address '" + destination.getAddress() + "'" );
+ m_destination = destination;
+ }
+
+ public Destination getDestination()
+ {
+ return m_destination;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file30" /><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>TransactionalMessageRouter.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N TransactionalMessageRouter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TransactionalMessageRouter.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,168 @@
</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;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+import EDU.oswego.cs.dl.util.concurrent.ReaderPreferenceReadWriteLock;
+import EDU.oswego.cs.dl.util.concurrent.SyncMap;
+import org.d_haven.event.EnqueuePredicateFailedException;
+import org.d_haven.event.Sink;
+import org.d_haven.event.SinkException;
+import org.d_haven.event.command.ThreadManager;
+
+/**
+ * Default implementation of a {@link DestinationRegistrar} and {@link Dispatcher}
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class TransactionalMessageRouter implements DestinationRegistrar, Dispatcher
+{
+ private final Map m_registrations = new ConcurrentHashMap();
+ private final Map m_transactionResources = new SyncMap( new WeakHashMap(), new ReaderPreferenceReadWriteLock() );
+
+ private final ThreadManager m_threadManager;
+ private final TransactionManager m_transactionManager;
+
+ public TransactionalMessageRouter( final ThreadManager threadManager,
+ final TransactionManager transactionManager )
+ {
+ if( null == threadManager )
+ {
+ throw new NullPointerException( "threadManager" );
+ }
+ else if( null == transactionManager )
+ {
+ throw new NullPointerException( "transactionManager" );
+ }
+
+ m_threadManager = threadManager;
+ m_transactionManager = transactionManager;
+ }
+
+ public void register( final Destination destination ) throws DuplicateRegistrationException
+ {
+ if( m_registrations.containsKey( destination.getAddress() ) )
+ {
+ throw new DuplicateRegistrationException( destination );
+ }
+ else
+ {
+ addDestination( destination );
+ }
+ }
+
+ private void addDestination( final Destination destination )
+ {
+ final DestinationEventPipeline pipeline = new DestinationEventPipeline( destination );
+
+ m_threadManager.register( pipeline );
+ m_registrations.put( destination.getAddress(), pipeline );
+ }
+
+ public void unregister( final Destination destination ) throws NoSuchDestinationException
+ {
+ if( !m_registrations.containsKey( destination.getAddress() ) )
+ {
+ throw new NoSuchDestinationException( destination );
+ }
+ else
+ {
+ removeDestination( destination );
+ }
+ }
+
+ private void removeDestination( final Destination destination )
+ {
+ final String address = destination.getAddress();
+ final DestinationEventPipeline pipeline = getDestinationEventPipeline( address );
+
+ m_threadManager.unregister( pipeline );
+ m_registrations.remove( address );
+ }
+
+ public void send( final String address, final Object message )
+ {
+ final DestinationEventPipeline pipeline = getDestinationEventPipeline( address );
+
+ if( null != pipeline )
+ {
+ try
+ {
+ final MessageTransactionSynchronization synchronization = getMessageTransactionResource();
+ final Sink sink = pipeline.getSink();
+
+ if( null == synchronization )
+ {
+ sink.enqueue( message );
+ }
+ else
+ {
+ synchronization.addEnqueue( sink.prepareEnqueue( new Object[]{message} ) );
+ }
+ }
+ catch( EnqueuePredicateFailedException e )
+ {
+ throw new InvalidMessageException( address, message );
+ }
+ catch( SinkException e )
+ {
+ final String msg = "Unable to send message '" + message + "' to destination '" + address + "'";
+ throw new RuntimeException( msg, e );
+ }
+ catch( SystemException e )
+ {
+ final String msg = "Transaction failure when sending message '" + message
+ + "' to destination '" + address + "'";
+ throw new RuntimeException( msg, e );
+ }
+ catch( RollbackException e )
+ {
+ final String msg = "Attempted to send message during rolled back transaction '" + message
+ + "' to destination '" + address + "'";
+ throw new RuntimeException( msg, e );
+ }
+ }
+ }
+
+ private MessageTransactionSynchronization getMessageTransactionResource() throws SystemException,
+ RollbackException
+ {
+ final Transaction transaction = m_transactionManager.getTransaction();
+
+ if( null == transaction )
+ {
+ return null;
+ }
+ else
+ {
+ MessageTransactionSynchronization synchronization =
+ (MessageTransactionSynchronization)m_transactionResources.get( transaction );
+
+ if( null == synchronization )
+ {
+ synchronization = new MessageTransactionSynchronization();
+ transaction.registerSynchronization( synchronization );
+ m_transactionResources.put( transaction, synchronization );
+ }
+
+ return synchronization;
+ }
+ }
+
+ private DestinationEventPipeline getDestinationEventPipeline( final String address )
+ {
+ return (DestinationEventPipeline)m_registrations.get( address );
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file31" /><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>ValidMessageEnqueuePredicate.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N ValidMessageEnqueuePredicate.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ValidMessageEnqueuePredicate.java 8 Mar 2005 02:58:48 -0000 1.1
@@ -0,0 +1,44 @@
</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;
+
+import org.d_haven.event.EnqueuePredicate;
+import org.d_haven.event.Sink;
+
+/**
+ * EnqueuePredicate that only accepts valid messages
+ *
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+class ValidMessageEnqueuePredicate implements EnqueuePredicate
+{
+ private final Destination m_destination;
+
+ public ValidMessageEnqueuePredicate( final Destination destination )
+ {
+ m_destination = destination;
+ }
+
+ public boolean accept( final Object element, final Sink modifyingSink )
+ {
+ return m_destination.isValidMessage( element );
+ }
+
+ public boolean accept( final Object[] elements, final Sink modifyingSink )
+ {
+ for( int i = 0; i < elements.length; i++ )
+ {
+ if( !accept( elements[i], modifyingSink ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file32" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>Destination.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N Destination.java
--- Destination.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,43 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * A Message Destination receives messages for a named destination.
- *
- * Message objects will be specific to the destination implementation. Please consult destination documentation on what
- * constitutes valid messages.
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface Destination
-{
- /**
- * Get the address of this destination.
- *
- * @return Address of destination. Required.
- */
- String getAddress();
-
- /**
- * Is the specified message a valid message for this destination? This method is just to check message validity. All
- * valid messages must be delivered without throwing any exceptions.
- *
- * @param message Message object to validate. Required.
- *
- * @return True if the message is valid for this destination.
- */
- boolean isValidMessage( Object message );
-
- /**
- * Deliver a message. Messages should first be tested for validity with {@link #isValidMessage(Object)}.
- *
- * @param message Message to deliver.
- */
- void deliver( Object message );
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file33" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>DestinationEventHandler.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationEventHandler.java
--- DestinationEventHandler.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import org.d_haven.event.EventHandler;
-
-/**
- * EventHandler that passes messages on to a Destination
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-class DestinationEventHandler implements EventHandler
-{
- private final Destination m_destination;
-
- public DestinationEventHandler( final Destination destination )
- {
- m_destination = destination;
- }
-
- public void handleEvent( final Object element )
- {
- m_destination.deliver( element );
- }
-
- public void handleEvents( final Object[] elements )
- {
- for( int i = 0; i < elements.length; i++ )
- {
- handleEvent( elements[i] );
- }
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file34" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>DestinationEventPipeline.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationEventPipeline.java
--- DestinationEventPipeline.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,50 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import org.d_haven.event.EventHandler;
-import org.d_haven.event.Pipe;
-import org.d_haven.event.Sink;
-import org.d_haven.event.Source;
-import org.d_haven.event.command.EventPipeline;
-import org.d_haven.event.impl.DefaultPipe;
-
-/**
- * EventPipeline that manages a Destination, only allowing value messages to be enqueued.
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-class DestinationEventPipeline implements EventPipeline
-{
- private final Pipe m_pipe;
- private final Source[] m_sources;
- private final EventHandler m_eventHandler;
-
- public DestinationEventPipeline( final Destination destination )
- {
-
- m_pipe = new DefaultPipe( new ValidMessageEnqueuePredicate( destination ) );
- m_sources = new Source[]{m_pipe};
- m_eventHandler = new DestinationEventHandler( destination );
- }
-
- Sink getSink()
- {
- return m_pipe;
- }
-
- public EventHandler getEventHandler()
- {
- return m_eventHandler;
- }
-
- public Source[] getSources()
- {
- return m_sources;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file35" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>DestinationRegistrar.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DestinationRegistrar.java
--- DestinationRegistrar.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,34 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * Registrar that deals with {@link Destination}s.
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface DestinationRegistrar
-{
- /**
- * Register a destination
- *
- * @param destination Destination to register. required.
- *
- * @throws DuplicateRegistrationException If this destination has already been registered
- */
- void register( Destination destination ) throws DuplicateRegistrationException;
-
- /**
- * Unregister a destination
- *
- * @param destination Destination to unregister. required.
- *
- * @throws NoSuchDestinationException If this destination has never been registered
- */
- void unregister( Destination destination ) throws NoSuchDestinationException;
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file36" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>Dispatcher.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N Dispatcher.java
--- Dispatcher.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,30 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * A Messenger allows clients to send messages to specific named addresses.
- *
- * If a message is sent to an unknown address, it will merely end up in the discarded message box. The sender will not
- * be informed.
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public interface Dispatcher
-{
- /**
- * Send a message to an address. Delivery is guaranteed if the destintion exists. If the destination does not exist,
- * no notification will occur.
- *
- * @param address Address to send message to. Required.
- * @param message Message to send. Required.
- *
- * @throws InvalidMessageException if a message is invalid
- */
- void send( String address, Object message );
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file37" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>DuplicateRegistrationException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N DuplicateRegistrationException.java
--- DuplicateRegistrationException.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class DuplicateRegistrationException extends MessageException
-{
- private final Destination m_destination;
-
- public DuplicateRegistrationException( final Destination destination )
- {
- super( "Destination with address '" + destination.getAddress() + "' already registered" );
- m_destination = destination;
- }
-
- public Destination getDestination()
- {
- return m_destination;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file38" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>InvalidMessageException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N InvalidMessageException.java
--- InvalidMessageException.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class InvalidMessageException extends RuntimeException
-{
- private final String m_address;
- private final Object m_invalidMessage;
-
- public InvalidMessageException( final String address, final Object invalidMessage )
- {
- super( "Invalid invalidMessage '" + invalidMessage + "' for destination '" + address + "'" );
-
- m_address = address;
- m_invalidMessage = invalidMessage;
- }
-
- public String getAddress()
- {
- return m_address;
- }
-
- public Object getInvalidMessage()
- {
- return m_invalidMessage;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file39" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>MessageException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N MessageException.java
--- MessageException.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,19 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class MessageException extends Exception
-{
- public MessageException( final String message )
- {
- super( message );
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file40" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>MessageTransactionSynchronization.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N MessageTransactionSynchronization.java
--- MessageTransactionSynchronization.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,69 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-
-import org.d_haven.event.PreparedEnqueue;
-
-/**
- * <code>Synchronization</code> That deals with PreparedEnqueue objects
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-class MessageTransactionSynchronization implements Synchronization
-{
- private final List m_enqueues = new ArrayList();
-
- public void commit()
- {
- final Iterator i = m_enqueues.iterator();
-
- while( i.hasNext() )
- {
- ( (PreparedEnqueue)i.next() ).commit();
- }
- }
-
- public void rollback()
- {
- final Iterator i = m_enqueues.iterator();
-
- while( i.hasNext() )
- {
- ( (PreparedEnqueue)i.next() ).abort();
- }
- }
-
- void addEnqueue( final PreparedEnqueue enqueue )
- {
- m_enqueues.add( enqueue );
- }
-
- public void afterCompletion( final int status )
- {
- switch( status )
- {
- case Status.STATUS_COMMITTED:
- commit();
- break;
- default:
- rollback();
- ;
- break;
- }
- }
-
- public void beforeCompletion()
- {
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file41" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>NoSuchDestinationException.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N NoSuchDestinationException.java
--- NoSuchDestinationException.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,27 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class NoSuchDestinationException extends MessageException
-{
- private final Destination m_destination;
-
- public NoSuchDestinationException( final Destination destination )
- {
- super( "Unknown destination address '" + destination.getAddress() + "'" );
- m_destination = destination;
- }
-
- public Destination getDestination()
- {
- return m_destination;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file42" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>TransactionalMessageRouter.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N TransactionalMessageRouter.java
--- TransactionalMessageRouter.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,168 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
-import EDU.oswego.cs.dl.util.concurrent.ReaderPreferenceReadWriteLock;
-import EDU.oswego.cs.dl.util.concurrent.SyncMap;
-import org.d_haven.event.EnqueuePredicateFailedException;
-import org.d_haven.event.Sink;
-import org.d_haven.event.SinkException;
-import org.d_haven.event.command.ThreadManager;
-
-/**
- * Default implementation of a {@link DestinationRegistrar} and {@link Dispatcher}
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class TransactionalMessageRouter implements DestinationRegistrar, Dispatcher
-{
- private final Map m_registrations = new ConcurrentHashMap();
- private final Map m_transactionResources = new SyncMap( new WeakHashMap(), new ReaderPreferenceReadWriteLock() );
-
- private final ThreadManager m_threadManager;
- private final TransactionManager m_transactionManager;
-
- public TransactionalMessageRouter( final ThreadManager threadManager,
- final TransactionManager transactionManager )
- {
- if( null == threadManager )
- {
- throw new NullPointerException( "threadManager" );
- }
- else if( null == transactionManager )
- {
- throw new NullPointerException( "transactionManager" );
- }
-
- m_threadManager = threadManager;
- m_transactionManager = transactionManager;
- }
-
- public void register( final Destination destination ) throws DuplicateRegistrationException
- {
- if( m_registrations.containsKey( destination.getAddress() ) )
- {
- throw new DuplicateRegistrationException( destination );
- }
- else
- {
- addDestination( destination );
- }
- }
-
- private void addDestination( final Destination destination )
- {
- final DestinationEventPipeline pipeline = new DestinationEventPipeline( destination );
-
- m_threadManager.register( pipeline );
- m_registrations.put( destination.getAddress(), pipeline );
- }
-
- public void unregister( final Destination destination ) throws NoSuchDestinationException
- {
- if( !m_registrations.containsKey( destination.getAddress() ) )
- {
- throw new NoSuchDestinationException( destination );
- }
- else
- {
- removeDestination( destination );
- }
- }
-
- private void removeDestination( final Destination destination )
- {
- final String address = destination.getAddress();
- final DestinationEventPipeline pipeline = getDestinationEventPipeline( address );
-
- m_threadManager.unregister( pipeline );
- m_registrations.remove( address );
- }
-
- public void send( final String address, final Object message )
- {
- final DestinationEventPipeline pipeline = getDestinationEventPipeline( address );
-
- if( null != pipeline )
- {
- try
- {
- final MessageTransactionSynchronization synchronization = getMessageTransactionResource();
- final Sink sink = pipeline.getSink();
-
- if( null == synchronization )
- {
- sink.enqueue( message );
- }
- else
- {
- synchronization.addEnqueue( sink.prepareEnqueue( new Object[]{message} ) );
- }
- }
- catch( EnqueuePredicateFailedException e )
- {
- throw new InvalidMessageException( address, message );
- }
- catch( SinkException e )
- {
- final String msg = "Unable to send message '" + message + "' to destination '" + address + "'";
- throw new RuntimeException( msg, e );
- }
- catch( SystemException e )
- {
- final String msg = "Transaction failure when sending message '" + message
- + "' to destination '" + address + "'";
- throw new RuntimeException( msg, e );
- }
- catch( RollbackException e )
- {
- final String msg = "Attempted to send message during rolled back transaction '" + message
- + "' to destination '" + address + "'";
- throw new RuntimeException( msg, e );
- }
- }
- }
-
- private MessageTransactionSynchronization getMessageTransactionResource() throws SystemException,
- RollbackException
- {
- final Transaction transaction = m_transactionManager.getTransaction();
-
- if( null == transaction )
- {
- return null;
- }
- else
- {
- MessageTransactionSynchronization synchronization =
- (MessageTransactionSynchronization)m_transactionResources.get( transaction );
-
- if( null == synchronization )
- {
- synchronization = new MessageTransactionSynchronization();
- transaction.registerSynchronization( synchronization );
- m_transactionResources.put( transaction, synchronization );
- }
-
- return synchronization;
- }
- }
-
- private DestinationEventPipeline getDestinationEventPipeline( final String address )
- {
- return (DestinationEventPipeline)m_registrations.get( address );
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file43" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/java/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>ValidMessageEnqueuePredicate.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N ValidMessageEnqueuePredicate.java
--- ValidMessageEnqueuePredicate.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,44 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import org.d_haven.event.EnqueuePredicate;
-import org.d_haven.event.Sink;
-
-/**
- * EnqueuePredicate that only accepts valid messages
- *
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-class ValidMessageEnqueuePredicate implements EnqueuePredicate
-{
- private final Destination m_destination;
-
- public ValidMessageEnqueuePredicate( final Destination destination )
- {
- m_destination = destination;
- }
-
- public boolean accept( final Object element, final Sink modifyingSink )
- {
- return m_destination.isValidMessage( element );
- }
-
- public boolean accept( final Object[] elements, final Sink modifyingSink )
- {
- for( int i = 0; i < elements.length; i++ )
- {
- if( !accept( elements[i], modifyingSink ) )
- {
- return false;
- }
- }
-
- return true;
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file44" /><div class="file">
<span class="pathname" id="added">spice/components/message/src/test/org/codehaus/spice/message<br /></span>
<div class="fileheader" id="added"><big><b>TransactionalMessageRouterTestCase.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N TransactionalMessageRouterTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TransactionalMessageRouterTestCase.java 8 Mar 2005 02:58:51 -0000 1.1
@@ -0,0 +1,86 @@
</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;
+
+import javax.transaction.TransactionManager;
+
+import junit.framework.TestCase;
+import org.d_haven.event.command.DefaultThreadManager;
+import org.d_haven.event.command.ThreadManager;
+import org.jmock.Mock;
+
+/**
+ * @author <a href="mailto:[email protected]">peter royal</a>
+ */
+public class TransactionalMessageRouterTestCase extends TestCase
+{
+ private TransactionalMessageRouter m_transactionalMessageRouter;
+
+ protected void setUp() throws Exception
+ {
+ final ThreadManager threadManager = new DefaultThreadManager();
+ final Mock transactionManager = new Mock( TransactionManager.class );
+
+ m_transactionalMessageRouter
+ = new TransactionalMessageRouter( threadManager,
+ (TransactionManager)transactionManager.proxy() );
+ }
+
+ public void testUnregisterUnknownDestination() throws Exception
+ {
+ final DestinationRegistrar registrar = m_transactionalMessageRouter;
+ final MockDestination destination = new MockDestination();
+
+ try
+ {
+ registrar.unregister( destination );
+
+ fail( "cannot unregister non-registered destination" );
+ }
+ catch( NoSuchDestinationException e )
+ {
+ assertEquals( destination, e.getDestination() );
+ }
+ }
+
+ public void testDuplicateRegistration() throws Exception
+ {
+ final DestinationRegistrar registrar = m_transactionalMessageRouter;
+ final MockDestination destination = new MockDestination();
+
+ registrar.register( destination );
+
+ try
+ {
+ registrar.register( destination );
+
+ fail( "allowed duplication registration" );
+ }
+ catch( DuplicateRegistrationException e )
+ {
+ assertEquals( destination, e.getDestination() );
+ }
+ }
+
+ private static class MockDestination implements Destination
+ {
+ public String getAddress()
+ {
+ return "test";
+ }
+
+ public boolean isValidMessage( final Object message )
+ {
+ return false;
+ }
+
+ public void deliver( final Object message )
+ {
+ }
+ }
+}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file45" /><div class="file">
<span class="pathname" id="removed">spice/components/message/src/test/org/spice/message<br /></span>
<div class="fileheader" id="removed"><big><b>TransactionalMessageRouterTestCase.java</b></big> <small id="info">removed after 1.1</small></div>
<pre class="diff"><small id="info">diff -N TransactionalMessageRouterTestCase.java
--- TransactionalMessageRouterTestCase.java 2 Mar 2005 19:32:08 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,86 +0,0 @@
</small></pre><pre class="diff" id="removed">-/*
- * 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.spice.message;
-
-import javax.transaction.TransactionManager;
-
-import junit.framework.TestCase;
-import org.d_haven.event.command.DefaultThreadManager;
-import org.d_haven.event.command.ThreadManager;
-import org.jmock.Mock;
-
-/**
- * @author <a href="mailto:[email protected]">peter royal</a>
- */
-public class TransactionalMessageRouterTestCase extends TestCase
-{
- private TransactionalMessageRouter m_transactionalMessageRouter;
-
- protected void setUp() throws Exception
- {
- final ThreadManager threadManager = new DefaultThreadManager();
- final Mock transactionManager = new Mock( TransactionManager.class );
-
- m_transactionalMessageRouter
- = new TransactionalMessageRouter( threadManager,
- (TransactionManager)transactionManager.proxy() );
- }
-
- public void testUnregisterUnknownDestination() throws Exception
- {
- final DestinationRegistrar registrar = m_transactionalMessageRouter;
- final MockDestination destination = new MockDestination();
-
- try
- {
- registrar.unregister( destination );
-
- fail( "cannot unregister non-registered destination" );
- }
- catch( NoSuchDestinationException e )
- {
- assertEquals( destination, e.getDestination() );
- }
- }
-
- public void testDuplicateRegistration() throws Exception
- {
- final DestinationRegistrar registrar = m_transactionalMessageRouter;
- final MockDestination destination = new MockDestination();
-
- registrar.register( destination );
-
- try
- {
- registrar.register( destination );
-
- fail( "allowed duplication registration" );
- }
- catch( DuplicateRegistrationException e )
- {
- assertEquals( destination, e.getDestination() );
- }
- }
-
- private static class MockDestination implements Destination
- {
- public String getAddress()
- {
- return "test";
- }
-
- public boolean isValidMessage( final Object message )
- {
- return false;
- }
-
- public void deliver( final Object message )
- {
- }
- }
-}
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.8</small></center>
</body></html>