From 20807d81708bd33b3b5a4616fadcf3ae91bf9508 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sun, 24 Jul 2011 21:50:03 +0200 Subject: [PATCH] event listener is now used by the xml router and the publish method of the gateway is now a void method (fire and forget). --- .../java/org/wamblee/xmlrouter/common/Id.java | 10 +- .../xmlrouter/impl/Transformations.java | 19 ++-- .../org/wamblee/xmlrouter/impl/XMLRouter.java | 69 +++++++----- .../xmlrouter/impl/TransformationsTest.java | 10 +- .../wamblee/xmlrouter/impl/XMLRouterTest.java | 100 ++++++++++++++---- .../listener/CompositeEventListener.java | 8 +- .../wamblee/xmlrouter/listener/EventInfo.java | 18 ++-- .../xmlrouter/listener/EventListener.java | 8 +- .../listener/LoggingEventListener.java | 20 ++-- .../listener/CompositeEventListenerTest.java | 6 +- .../wamblee/xmlrouter/publish/Gateway.java | 5 +- 11 files changed, 171 insertions(+), 102 deletions(-) diff --git a/common/src/main/java/org/wamblee/xmlrouter/common/Id.java b/common/src/main/java/org/wamblee/xmlrouter/common/Id.java index bc23999..704aac9 100644 --- a/common/src/main/java/org/wamblee/xmlrouter/common/Id.java +++ b/common/src/main/java/org/wamblee/xmlrouter/common/Id.java @@ -12,24 +12,24 @@ * 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 { - 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 diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java index 212d36b..20455e8 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java @@ -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 transformations; + private AtomicLong sequenceNumber; + private Map transformations; private List vertices; private TransformationPath[][] matrix; private Map> sequences; public Transformations() { - sequenceNumber = new AtomicInteger(1); - transformations = new LinkedHashMap(); + sequenceNumber = new AtomicLong(1); + transformations = new LinkedHashMap(); vertices = new ArrayList(); matrix = new TransformationPath[0][0]; } public Id addTransformation(Transformation aTransformation) { - int seqno = sequenceNumber.getAndIncrement(); + long seqno = sequenceNumber.getAndIncrement(); Id id = new Id(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]; } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java index e166d75..6b460d1 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java @@ -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 documentTypes; + private Clock clock; + private AtomicLong nextEventId; + private AtomicLong sequenceNumbers; + private Map documentTypes; private Transformations transformations; - private Map filters; - private Map destinations; + private Map filters; + private Map destinations; - public XMLRouter(EventListener aListener) { + public XMLRouter(Clock aClock, EventListener aListener) { listener = aListener; - sequenceNumbers = new AtomicInteger(1); - documentTypes = new LinkedHashMap(); + clock = aClock; + nextEventId = new AtomicLong(clock.currentTimeMillis()); + sequenceNumbers = new AtomicLong(1); + documentTypes = new LinkedHashMap(); transformations = new Transformations(); - filters = new LinkedHashMap(); - destinations = new LinkedHashMap(); + filters = new LinkedHashMap(); + destinations = new LinkedHashMap(); } @Override public Id addDocumentType(DocumentType aType) { - int seqno = sequenceNumbers.getAndIncrement(); + long seqno = sequenceNumbers.getAndIncrement(); documentTypes.put(seqno, aType); return new Id(seqno); } @@ -97,7 +103,7 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry { @Override public Id addFilter(Filter aFilter) { - int seqno = sequenceNumbers.getAndIncrement(); + long seqno = sequenceNumbers.getAndIncrement(); filters.put(seqno, aFilter); return new Id(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 id = new Id(nextEventId.getAndIncrement()); + List types = determineDocumentTypes(aEvent); + EventInfo info = new EventInfo(time, aSource, id, types, aEvent); boolean delivered = false; try { - List filteredInputTypes = determineFilteredInputTypes(aEvent); + List 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 possibleTargetTypes = new HashSet(); @@ -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 entry : destinations.entrySet()) { + long destinationId = entry.getKey(); + Destination destination = entry.getValue(); Collection requested = destination .chooseFromTargetTypes(possibleTargetTypes); if (!requested.isEmpty()) { @@ -169,14 +181,14 @@ public class XMLRouter implements Config, Gateway, DestinationRegistry { List 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 determineFilteredInputTypes(DOMSource aEvent) { - List types = determineDocumentTypes(aEvent); + private List determineFilteredInputTypes(List aTypes, + DOMSource aEvent) { + // apply filters to the input List filteredTypes = new ArrayList(); - 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 registerDestination(Destination aDestination) { notNull("destination", aDestination); - int seqno = sequenceNumbers.getAndIncrement(); + long seqno = sequenceNumbers.getAndIncrement(); Id id = new Id(seqno); destinations.put(seqno, new RobustDestination(id, aDestination)); return id; diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationsTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationsTest.java index 9da9c35..230cd03 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationsTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/TransformationsTest.java @@ -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 res = transformations.getPossibleTargetTypes("a"); diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java index 2d73fad..47eb21a 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterTest.java @@ -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 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) 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 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) 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 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)); + + } } diff --git a/listener/src/main/java/org/wamblee/xmlrouter/listener/CompositeEventListener.java b/listener/src/main/java/org/wamblee/xmlrouter/listener/CompositeEventListener.java index 22943db..791d9d1 100644 --- a/listener/src/main/java/org/wamblee/xmlrouter/listener/CompositeEventListener.java +++ b/listener/src/main/java/org/wamblee/xmlrouter/listener/CompositeEventListener.java @@ -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 aSequence, - Id 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); diff --git a/listener/src/main/java/org/wamblee/xmlrouter/listener/EventInfo.java b/listener/src/main/java/org/wamblee/xmlrouter/listener/EventInfo.java index 1c4e48e..4f11738 100644 --- a/listener/src/main/java/org/wamblee/xmlrouter/listener/EventInfo.java +++ b/listener/src/main/java/org/wamblee/xmlrouter/listener/EventInfo.java @@ -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 id; - private String type; + private List types; private DOMSource event; public EventInfo(long aTime, String aSource, Id aId, - String aType, DOMSource aEvent) { + List 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 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(); diff --git a/listener/src/main/java/org/wamblee/xmlrouter/listener/EventListener.java b/listener/src/main/java/org/wamblee/xmlrouter/listener/EventListener.java index ee03b7b..251417a 100644 --- a/listener/src/main/java/org/wamblee/xmlrouter/listener/EventListener.java +++ b/listener/src/main/java/org/wamblee/xmlrouter/listener/EventListener.java @@ -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 aSequence, - Id aDestination, String aDestinationName, - boolean aSuccessFlag); + long aDestinationId, String aDestinationName, boolean aSuccessFlag); /** * Called when an event could not be delivered to any destination. diff --git a/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java b/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java index 189f763..24c6be6 100644 --- a/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java +++ b/listener/src/main/java/org/wamblee/xmlrouter/listener/LoggingEventListener.java @@ -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 aSequence, - Id 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 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()); diff --git a/listener/src/test/java/org/wamblee/xmlrouter/listener/CompositeEventListenerTest.java b/listener/src/test/java/org/wamblee/xmlrouter/listener/CompositeEventListenerTest.java index fd94c43..19608b8 100644 --- a/listener/src/test/java/org/wamblee/xmlrouter/listener/CompositeEventListenerTest.java +++ b/listener/src/test/java/org/wamblee/xmlrouter/listener/CompositeEventListenerTest.java @@ -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_ID = new Id( - 12); + private static final long DESTINATION_ID = 12L; private CompositeEventListener composite; private EventInfo source; diff --git a/publish/src/main/java/org/wamblee/xmlrouter/publish/Gateway.java b/publish/src/main/java/org/wamblee/xmlrouter/publish/Gateway.java index 533ba2c..c4f6113 100644 --- a/publish/src/main/java/org/wamblee/xmlrouter/publish/Gateway.java +++ b/publish/src/main/java/org/wamblee/xmlrouter/publish/Gateway.java @@ -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); } -- 2.31.1