event listener is now used by the xml router and the publish method of the gateway is
authorErik Brakkee <erik@brakkee.org>
Sun, 24 Jul 2011 19:50:03 +0000 (21:50 +0200)
committerErik Brakkee <erik@brakkee.org>
Sun, 24 Jul 2011 19:50:03 +0000 (21:50 +0200)
now a void method (fire and forget).

common/src/main/java/org/wamblee/xmlrouter/common/Id.java
impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java
impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java
impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationsTest.java
impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java
listener/src/main/java/org/wamblee/xmlrouter/listener/CompositeEventListener.java
listener/src/main/java/org/wamblee/xmlrouter/listener/EventInfo.java
listener/src/main/java/org/wamblee/xmlrouter/listener/EventListener.java
listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java
listener/src/test/java/org/wamblee/xmlrouter/listener/CompositeEventListenerTest.java
publish/src/main/java/org/wamblee/xmlrouter/publish/Gateway.java

index bc2399985649c2028fb82c218b14dcda642f966c..704aac937c12fb20bc9d8c8ca35a6a14b6230365 100644 (file)
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.xmlrouter.common;
 
 public class Id<T> {
 
-    private int id;
+    private long id;
 
-    public Id(int aId) {
+    public Id(long aId) {
         id = aId;
     }
 
-    public int getId() {
+    public long getId() {
         return id;
     }
 
     @Override
     public int hashCode() {
-        return id;
+        return ((Long) id).hashCode();
     }
 
     @Override
index 212d36b2ef6c560d74c41f0adcf69a60b897e4e1..20455e8a5e2b8633d4d783a5e1e26fed46e2c602 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.xmlrouter.impl;
 
 import java.util.ArrayList;
@@ -23,29 +23,29 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
 public class Transformations {
 
-    private AtomicInteger sequenceNumber;
-    private Map<Integer, Transformation> transformations;
+    private AtomicLong sequenceNumber;
+    private Map<Long, Transformation> transformations;
     private List<String> vertices;
     private TransformationPath[][] matrix;
 
     private Map<String, List<TransformationPath>> sequences;
 
     public Transformations() {
-        sequenceNumber = new AtomicInteger(1);
-        transformations = new LinkedHashMap<Integer, Transformation>();
+        sequenceNumber = new AtomicLong(1);
+        transformations = new LinkedHashMap<Long, Transformation>();
         vertices = new ArrayList<String>();
         matrix = new TransformationPath[0][0];
     }
 
     public Id<Transformation> addTransformation(Transformation aTransformation) {
-        int seqno = sequenceNumber.getAndIncrement();
+        long seqno = sequenceNumber.getAndIncrement();
         Id<Transformation> id = new Id<Transformation>(seqno);
         transformations.put(seqno,
             new RobustTransformation(id, aTransformation));
@@ -80,7 +80,7 @@ public class Transformations {
      */
     public TransformationPath getPath(String aFrom, String aTo) {
         int i = vertices.indexOf(aFrom);
-        if (i == -1) {
+        if (i < 0) {
             if (aFrom.equals(aTo)) {
                 return new TransformationPath();
             }
@@ -88,6 +88,9 @@ public class Transformations {
         }
 
         int j = vertices.indexOf(aTo);
+        if (j < 0) {
+            return null;
+        }
         return matrix[i][j];
     }
 
index e166d75d74880926b86459ab60971862dec0d0e8..6b460d1dea203495d7ef258afec33c75e86c71ab 100644 (file)
@@ -23,18 +23,20 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.transform.dom.DOMSource;
 
+import org.wamblee.general.Clock;
 import org.wamblee.xml.XMLDocument;
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Config;
 import org.wamblee.xmlrouter.config.DocumentType;
 import org.wamblee.xmlrouter.config.Filter;
 import org.wamblee.xmlrouter.config.Transformation;
+import org.wamblee.xmlrouter.listener.EventInfo;
 import org.wamblee.xmlrouter.listener.EventListener;
 import org.wamblee.xmlrouter.publish.Gateway;
 import org.wamblee.xmlrouter.subscribe.Destination;
@@ -48,24 +50,28 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
         .getName());
 
     private EventListener listener;
-    private AtomicInteger sequenceNumbers;
-    private Map<Integer, DocumentType> documentTypes;
+    private Clock clock;
+    private AtomicLong nextEventId;
+    private AtomicLong sequenceNumbers;
+    private Map<Long, DocumentType> documentTypes;
     private Transformations transformations;
-    private Map<Integer, Filter> filters;
-    private Map<Integer, Destination> destinations;
+    private Map<Long, Filter> filters;
+    private Map<Long, Destination> destinations;
 
-    public XMLRouter(EventListener aListener) {
+    public XMLRouter(Clock aClock, EventListener aListener) {
         listener = aListener;
-        sequenceNumbers = new AtomicInteger(1);
-        documentTypes = new LinkedHashMap<Integer, DocumentType>();
+        clock = aClock;
+        nextEventId = new AtomicLong(clock.currentTimeMillis());
+        sequenceNumbers = new AtomicLong(1);
+        documentTypes = new LinkedHashMap<Long, DocumentType>();
         transformations = new Transformations();
-        filters = new LinkedHashMap<Integer, Filter>();
-        destinations = new LinkedHashMap<Integer, Destination>();
+        filters = new LinkedHashMap<Long, Filter>();
+        destinations = new LinkedHashMap<Long, Destination>();
     }
 
     @Override
     public Id<DocumentType> addDocumentType(DocumentType aType) {
-        int seqno = sequenceNumbers.getAndIncrement();
+        long seqno = sequenceNumbers.getAndIncrement();
         documentTypes.put(seqno, aType);
         return new Id<DocumentType>(seqno);
     }
@@ -97,7 +103,7 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
 
     @Override
     public Id<Filter> addFilter(Filter aFilter) {
-        int seqno = sequenceNumbers.getAndIncrement();
+        long seqno = sequenceNumbers.getAndIncrement();
         filters.put(seqno, aFilter);
         return new Id<Filter>(seqno);
     }
@@ -113,12 +119,18 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
     }
 
     @Override
-    public boolean publish(String aSource, DOMSource aEvent) {
+    public void publish(String aSource, DOMSource aEvent) {
+
+        long time = clock.currentTimeMillis();
+        Id<DOMSource> id = new Id<DOMSource>(nextEventId.getAndIncrement());
+        List<String> types = determineDocumentTypes(aEvent);
+        EventInfo info = new EventInfo(time, aSource, id, types, aEvent);
 
         boolean delivered = false;
         try {
 
-            List<String> filteredInputTypes = determineFilteredInputTypes(aEvent);
+            List<String> filteredInputTypes = determineFilteredInputTypes(
+                types, aEvent);
             if (filteredInputTypes.isEmpty()) {
                 if (LOGGER.isLoggable(Level.FINE)) {
                     String doc = new XMLDocument(aEvent).print(true);
@@ -128,7 +140,6 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
                             "Event ''0}'' from source {1} removed because of filters.",
                             new Object[] { doc, aSource });
                 }
-                return delivered;
             }
 
             // get the reachable target types through transformations.
@@ -138,19 +149,18 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
             // This is however certainly not the main case.
 
             for (String inputType : filteredInputTypes) {
-                boolean result = deliverEvent(aSource, aEvent, inputType);
+                boolean result = deliverEvent(info, inputType);
                 delivered = delivered || result;
             }
         } finally {
             if (!delivered) {
                 destinationNotFound(aSource, aEvent);
+                listener.notDelivered(info);
             }
-            return delivered;
         }
     }
 
-    private boolean deliverEvent(String aSource, DOMSource aEvent,
-        String aInputType) {
+    private boolean deliverEvent(EventInfo aInfo, String aInputType) {
 
         boolean delivered = false;
         Set<String> possibleTargetTypes = new HashSet<String>();
@@ -158,7 +168,9 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
             .getPossibleTargetTypes(aInputType));
 
         // ask each destination what target types, if any they want to have.
-        for (Destination destination : destinations.values()) {
+        for (Map.Entry<Long, Destination> entry : destinations.entrySet()) {
+            long destinationId = entry.getKey();
+            Destination destination = entry.getValue();
             Collection<String> requested = destination
                 .chooseFromTargetTypes(possibleTargetTypes);
             if (!requested.isEmpty()) {
@@ -169,14 +181,14 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
                     List<Transformation> ts = path.getTransformations();
                     int i = 0;
                     boolean allowed = true;
-                    DOMSource transformed = aEvent;
+                    DOMSource transformed = aInfo.getEvent();
                     while (i < ts.size() && allowed && transformed != null) {
                         Transformation t = ts.get(i);
                         DOMSource orig = transformed;
                         transformed = t.transform(transformed);
                         if (transformed == null) {
-                            transformationReturnedNull(aSource, aEvent,
-                                aInputType, t, orig);
+                            transformationReturnedNull(aInfo.getSource(),
+                                aInfo.getEvent(), aInputType, t, orig);
                         }
 
                         if (!isAllowedByFilters(t.getToType(), transformed)) {
@@ -188,6 +200,8 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
                         // all transformations done and all filters still
                         // allow the event.
                         boolean result = destination.receive(transformed);
+                        listener.delivered(aInfo, ts, destinationId,
+                            destination.getName(), result);
                         delivered = delivered || result;
 
                     }
@@ -197,11 +211,12 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
         return delivered;
     }
 
-    private List<String> determineFilteredInputTypes(DOMSource aEvent) {
-        List<String> types = determineDocumentTypes(aEvent);
+    private List<String> determineFilteredInputTypes(List<String> aTypes,
+        DOMSource aEvent) {
+
         // apply filters to the input
         List<String> filteredTypes = new ArrayList<String>();
-        for (String type : types) {
+        for (String type : aTypes) {
             boolean allowed = isAllowedByFilters(type, aEvent);
             if (allowed) {
                 filteredTypes.add(type);
@@ -263,7 +278,7 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry {
     @Override
     public Id<Destination> registerDestination(Destination aDestination) {
         notNull("destination", aDestination);
-        int seqno = sequenceNumbers.getAndIncrement();
+        long seqno = sequenceNumbers.getAndIncrement();
         Id<Destination> id = new Id<Destination>(seqno);
         destinations.put(seqno, new RobustDestination(id, aDestination));
         return id;
index 9da9c3524abff1a0ecf579336f517525b6b63581..230cd03d73c2e90e3c77fd00abd9c8c3b1579dd0 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.xmlrouter.impl;
 
 import static junit.framework.Assert.*;
@@ -37,7 +37,7 @@ public class TransformationsTest {
             from = aFrom;
             to = aTo;
         }
-        
+
         @Override
         public String getName() {
             return "myname";
@@ -108,6 +108,12 @@ public class TransformationsTest {
         assertNull(transformations.getPath("C", "B"));
     }
 
+    @Test
+    public void testUnknownDestination() {
+        transformations.addTransformation(new MyTransformation("A", "B"));
+        assertNull(transformations.getPath("A", "D"));
+    }
+
     @Test
     public void testWithoutTransformations() {
         Collection<String> res = transformations.getPossibleTargetTypes("a");
index 2d73fad15694e652e9fae870b5edc45458e48b23..47eb21a9d7226708946e0f0da4b4cb5a62f33a31 100644 (file)
@@ -15,7 +15,6 @@
  */
 package org.wamblee.xmlrouter.impl;
 
-import static junit.framework.Assert.*;
 import static org.mockito.Matchers.*;
 import static org.mockito.Mockito.*;
 
@@ -27,9 +26,11 @@ import javax.xml.transform.dom.DOMSource;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.wamblee.general.SystemClock;
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.DocumentType;
 import org.wamblee.xmlrouter.config.Transformation;
+import org.wamblee.xmlrouter.listener.EventInfo;
 import org.wamblee.xmlrouter.listener.EventListener;
 import org.wamblee.xmlrouter.listener.LoggingEventListener;
 import org.wamblee.xmlrouter.subscribe.Destination;
@@ -76,7 +77,7 @@ public class XMLRouterTest {
     public void setUp() {
         EventListener logListener = new LoggingEventListener(Level.INFO);
         listener = spy(logListener);
-        router = new XMLRouter(listener);
+        router = new XMLRouter(new SystemClock(), listener);
         source1 = mock(DOMSource.class);
         source2 = mock(DOMSource.class);
         source3 = mock(DOMSource.class);
@@ -88,7 +89,8 @@ public class XMLRouterTest {
         destinationSpy = spy(destination);
 
         destinationId = router.registerDestination(destinationSpy);
-        assertFalse(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
     }
 
     @Test
@@ -96,16 +98,24 @@ public class XMLRouterTest {
         destinationSpy = registerDestination(true, "any");
         registerDocumentType("any");
 
-        assertTrue(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
         verify(destinationSpy).receive(same(source1));
 
         // Unregister the destination.
         router.unregisterDestination(destinationId);
-        reset(destinationSpy);
-        assertFalse(router.publish("any", source2));
+        resetMocks();
+        router.publish("any", source2);
+        verify(listener).notDelivered(any(EventInfo.class));
         verifyNoMoreInteractions(destinationSpy);
     }
 
+    private void resetMocks() {
+        reset(destinationSpy);
+        reset(listener);
+    }
+
     private void registerDocumentType(String aType) {
         DocumentType type = mock(DocumentType.class);
         when(type.isInstance(any(DOMSource.class))).thenReturn(true);
@@ -133,7 +143,8 @@ public class XMLRouterTest {
         destinationSpy = registerDestination(true);
         registerDocumentType("any");
 
-        assertFalse(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
         verify(destinationSpy, never()).receive(any(DOMSource.class));
     }
 
@@ -145,7 +156,8 @@ public class XMLRouterTest {
         doThrow(new RuntimeException()).when(destinationSpy).receive(
             any(DOMSource.class));
 
-        assertFalse(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
         verify(destinationSpy).receive(same(source1));
     }
 
@@ -157,8 +169,12 @@ public class XMLRouterTest {
         Id<Destination> destinationId2 = router
             .registerDestination(destinationSpy2);
 
-        assertTrue(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+
         verify(destinationSpy2).receive(same(source1));
+
     }
 
     @Test
@@ -169,7 +185,8 @@ public class XMLRouterTest {
         doThrow(new RuntimeException()).when(destinationSpy)
             .chooseFromTargetTypes((Collection<String>) anyObject());
 
-        assertFalse(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
         verify(destinationSpy, never()).receive(same(source1));
     }
 
@@ -181,7 +198,10 @@ public class XMLRouterTest {
         Destination destinationSpy2 = spy(destination2);
         Id<Destination> destinationId2 = router
             .registerDestination(destinationSpy2);
-        assertTrue(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+
         verify(destinationSpy, never()).receive(same(source1));
         verify(destinationSpy2).receive(same(source1));
     }
@@ -196,7 +216,8 @@ public class XMLRouterTest {
                 .chooseFromTargetTypes((Collection<String>) anyObject()))
             .thenReturn(null);
 
-        assertFalse(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
         verify(destinationSpy, never()).receive(same(source1));
     }
 
@@ -208,7 +229,10 @@ public class XMLRouterTest {
         Destination destinationSpy2 = spy(destination2);
         Id<Destination> destinationId2 = router
             .registerDestination(destinationSpy2);
-        assertTrue(router.publish("any", source1));
+        router.publish("any", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
+
         verify(destinationSpy, never()).receive(same(source1));
         verify(destinationSpy2).receive(same(source1));
     }
@@ -217,6 +241,7 @@ public class XMLRouterTest {
     public void testOneTransformationOneDestination() {
         registerDocumentType("any");
         Transformation transformation = mock(Transformation.class);
+        when(transformation.getName()).thenReturn("trans");
         when(transformation.getFromType()).thenReturn("any");
         when(transformation.getToType()).thenReturn("bla");
         when(transformation.transform(same(source1))).thenReturn(source2);
@@ -230,19 +255,23 @@ public class XMLRouterTest {
         router.registerDestination(destination);
 
         when(destination.receive(any(DOMSource.class))).thenReturn(true);
-        assertTrue(router.publish("bla", source1));
+        router.publish("bla", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
 
         verify(transformation).transform(source1);
         verify(destination).receive(same(source2));
 
         // now the same when the destination rejects the event.
         when(destination.receive(any(DOMSource.class))).thenReturn(false);
-        assertFalse(router.publish("bla", source1));
+        router.publish("bla", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
     }
 
     private Transformation createTransformation(String aFrom, String aTo,
         DOMSource aSource, DOMSource aTarget) {
         Transformation transformation = mock(Transformation.class);
+        when(transformation.getName()).thenReturn("trans");
         when(transformation.getFromType()).thenReturn(aFrom);
         when(transformation.getToType()).thenReturn(aTo);
         when(transformation.transform(same(aSource))).thenReturn(aTarget);
@@ -263,7 +292,8 @@ public class XMLRouterTest {
             .thenReturn(Arrays.asList("bla"));
         router.registerDestination(destination);
 
-        assertFalse(router.publish("bla", source1));
+        router.publish("bla", source1);
+        verify(listener).notDelivered(any(EventInfo.class));
 
         verify(transformation).transform(source1);
         verify(destination, never()).receive(any(DOMSource.class));
@@ -278,12 +308,15 @@ public class XMLRouterTest {
             .thenReturn(Arrays.asList("bla", "bla2"));
 
         reset(transformation);
+        when(transformation.getName()).thenReturn("trans");
         when(transformation.getFromType()).thenReturn("any");
         when(transformation.getToType()).thenReturn("bla");
         when(transformation.transform(same(source1))).thenReturn(null);
 
         when(destination.receive(any(DOMSource.class))).thenReturn(true);
-        assertTrue(router.publish("bla", source1));
+        router.publish("bla", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
 
         verify(transformation).transform(source1);
         verify(transformation2).transform(source1);
@@ -298,7 +331,9 @@ public class XMLRouterTest {
         Destination dest2 = registerDestination(true, "any");
         registerDocumentType("any");
 
-        assertTrue(router.publish("source", source1));
+        router.publish("source", source1);
+        verify(listener, times(2)).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
 
         verify(dest1).receive(same(source1));
         verify(dest2).receive(same(source1));
@@ -313,7 +348,9 @@ public class XMLRouterTest {
             source1, source2);
         router.addTransformation(transformation);
 
-        assertTrue(router.publish("source", source1));
+        router.publish("source", source1);
+        verify(listener, times(2)).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
 
         verify(dest).receive(same(source1));
         verify(dest).receive(same(source2));
@@ -321,7 +358,7 @@ public class XMLRouterTest {
 
     @Test
     public void testMultipleTransformations() {
-        Destination dest = registerDestination(true, "any", "other");
+        Destination dest = registerDestination(true, "other");
         registerDocumentType("any", source1);
         registerDocumentType("other", source3);
 
@@ -332,8 +369,29 @@ public class XMLRouterTest {
             source2, source3);
         router.addTransformation(t2);
 
-        assertTrue(router.publish("source", source1));
+        router.publish("source", source1);
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(true));
 
         verify(dest).receive(same(source3));
     }
+
+    @Test
+    public void testDestinationGivesError() {
+        Destination destination = mock(Destination.class);
+        when(destination.getName()).thenReturn("name");
+        when(destination.chooseFromTargetTypes(anyCollectionOf(String.class)))
+            .thenReturn(Arrays.asList("any"));
+        doThrow(new RuntimeException("x")).when(destination).receive(
+            any(DOMSource.class));
+        router.registerDestination(destination);
+
+        registerDocumentType("any");
+
+        router.publish("source", source1);
+
+        verify(listener).delivered(any(EventInfo.class),
+            anyListOf(Transformation.class), anyLong(), anyString(), eq(false));
+
+    }
 }
index 22943db266b0d339b8c015902ddaafd9c14b8d2d..791d9d141c0fe10a7dda49b713efb2dcca87937b 100644 (file)
@@ -21,11 +21,8 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.print.attribute.standard.Destination;
-
 import org.wamblee.concurrency.ReadLock;
 import org.wamblee.concurrency.WriteLock;
-import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
 public class CompositeEventListener implements EventListener {
@@ -72,11 +69,10 @@ public class CompositeEventListener implements EventListener {
     @Override
     @ReadLock
     public void delivered(EventInfo aInfo, List<Transformation> aSequence,
-        Id<Destination> aDestination, String aDestinationName,
-        boolean aSuccessFlag) {
+        long aDestinationId, String aDestinationName, boolean aSuccessFlag) {
         for (EventListener logger : loggers) {
             try {
-                logger.delivered(aInfo, aSequence, aDestination,
+                logger.delivered(aInfo, aSequence, aDestinationId,
                     aDestinationName, aSuccessFlag);
             } catch (Exception e) {
                 LOGGER.log(Level.WARNING, "Logger threw exception", e);
index 1c4e48ec2cae387c60ba472c0254eb44d88eafd1..4f117380adb4777a3534f8735364d1d2f0213299 100644 (file)
@@ -15,6 +15,8 @@
  */
 package org.wamblee.xmlrouter.listener;
 
+import java.util.List;
+
 import javax.xml.transform.dom.DOMSource;
 
 import org.wamblee.xml.XMLDocument;
@@ -31,15 +33,15 @@ public class EventInfo {
     private long time;
     private String source;
     private Id<DOMSource> id;
-    private String type;
+    private List<String> types;
     private DOMSource event;
 
     public EventInfo(long aTime, String aSource, Id<DOMSource> aId,
-        String aType, DOMSource aEvent) {
+        List<String> aTypes, DOMSource aEvent) {
         time = aTime;
         source = aSource;
         id = aId;
-        type = aType;
+        types = aTypes;
         event = aEvent;
     }
 
@@ -55,12 +57,8 @@ public class EventInfo {
         return id;
     }
 
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String aType) {
-        type = aType;
+    public List<String> getTypes() {
+        return types;
     }
 
     public DOMSource getEvent() {
@@ -74,7 +72,7 @@ public class EventInfo {
         buf.append("time " + time);
         buf.append(", source " + source);
         buf.append(", id " + id);
-        buf.append(", type " + type);
+        buf.append(", types " + types);
         buf.append(", event " + new XMLDocument(event).print(true));
         buf.append(")");
         return buf.toString();
index ee03b7b007d0e8f10a33bfbe41f3d66c07d4ef2e..251417ac2946c42405a7af85037c1f4089615a58 100644 (file)
@@ -17,9 +17,6 @@ package org.wamblee.xmlrouter.listener;
 
 import java.util.List;
 
-import javax.print.attribute.standard.Destination;
-
-import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
 /**
@@ -37,7 +34,7 @@ public interface EventListener {
      *            Event information.
      * @param aSequence
      *            Sequence of transformations performed.
-     * @param aDestination
+     * @param aDestinationId
      *            Id of the destination the event was delivered to.
      * @param aDestinationName
      *            Destination name.
@@ -45,8 +42,7 @@ public interface EventListener {
      *            Whether or not event delivery succeeded.
      */
     void delivered(EventInfo aInfo, List<Transformation> aSequence,
-        Id<Destination> aDestination, String aDestinationName,
-        boolean aSuccessFlag);
+        long aDestinationId, String aDestinationName, boolean aSuccessFlag);
 
     /**
      * Called when an event could not be delivered to any destination.
index 189f7632ae1993ef63af0b63cdba97827c5a988c..24c6be65c9333d571ab60f43e28dc291e40f0cff 100644 (file)
@@ -19,9 +19,6 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.print.attribute.standard.Destination;
-
-import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
 /**
@@ -42,18 +39,23 @@ public class LoggingEventListener implements EventListener {
 
     @Override
     public void delivered(EventInfo aEvent, List<Transformation> aSequence,
-        Id<Destination> aDestination, String aDestinationName,
-        boolean aSuccessFlag) {
+        long aDestinationId, String aDestinationName, boolean aSuccessFlag) {
         if (LOGGER.isLoggable(level)) {
-            LOGGER.log(level, "event delivered: " + aEvent + ", sequence '" +
-                getSequenceString(aSequence) + "', destionationId " +
-                aDestination + ", destinationName '" + aDestinationName + "'");
+            LOGGER
+                .log(level, "event delivered: " + aEvent + ", sequence '" +
+                    getSequenceString(aSequence) + "', destinationId " +
+                    aDestinationId + ", destinationName '" + aDestinationName +
+                    "'");
         }
     }
 
     private String getSequenceString(List<Transformation> aSequence) {
         StringBuffer buf = new StringBuffer();
-        for (Transformation transformation : aSequence) {
+        for (int i = 0; i < aSequence.size(); i++) {
+            if (i > 0) {
+                buf.append(", ");
+            }
+            Transformation transformation = aSequence.get(i);
             buf.append(transformation.getName());
             buf.append("(");
             buf.append(transformation.getFromType());
index fd94c43e6b72fadd03908d25b3f3c60d9209bdc3..19608b873ec3c4401533836fdbf84e766e7b5704 100644 (file)
@@ -21,18 +21,14 @@ import static org.mockito.Mockito.*;
 
 import java.util.ArrayList;
 
-import javax.print.attribute.standard.Destination;
-
 import org.junit.Before;
 import org.junit.Test;
-import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Transformation;
 
 public class CompositeEventListenerTest {
 
     private static final String DESTINATION_NAME = "dest";
-    private static final Id<Destination> DESTINATION_ID = new Id<Destination>(
-        12);
+    private static final long DESTINATION_ID = 12L;
     private CompositeEventListener composite;
 
     private EventInfo source;
index 533ba2c1a6626953919b71d5b4add34dbcaf39c4..c4f61131f97a87ee6441b9a18e53687871c5bb16 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.xmlrouter.publish;
 
 import javax.xml.transform.dom.DOMSource;
@@ -31,7 +31,6 @@ public interface Gateway {
      *            Source.
      * @param aEvent
      *            Event.
-     * @return True iff th event was delivered to at least one destination.
      */
-    boolean publish(String aSource, DOMSource aEvent);
+    void publish(String aSource, DOMSource aEvent);
 }