From f7ea3f765d40384b8c23d7d84ccb2135335afae5 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 17 Sep 2008 18:13:16 +0000 Subject: [PATCH] Removed 'event' code from the 'org.springframework.integration.adapter' module (INT-375). --- .../adapter/event/ApplicationEventSource.java | 79 ------------ .../adapter/event/ApplicationEventTarget.java | 49 -------- .../adapter/event/MessagingEvent.java | 37 ------ .../adapter/event/MessagingEventMapper.java | 38 ------ .../event/ApplicationEventSourceTests.java | 114 ------------------ .../event/ApplicationEventTargetTests.java | 62 ---------- .../event/applicationEventSourceTests.xml | 15 --- 7 files changed, 394 deletions(-) delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTarget.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceTests.xml diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java deleted file mode 100644 index b2631e8f33..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.MessageChannelTemplate; -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -/** - * A message source for passing Spring - * {@link ApplicationEvent ApplicationEvents} within messages. - * - * @author Mark Fisher - */ -public class ApplicationEventSource implements ApplicationListener { - - private final MessageChannel channel; - - private List> eventTypes = new ArrayList>(); - - private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate(); - - - public ApplicationEventSource(MessageChannel channel) { - Assert.notNull(channel, "channel must not be null"); - this.channel = channel; - } - - - /** - * Set the list of event types (classes that extend ApplicationEvent) that - * this adapter should send to the message channel. By default, all event - * types will be sent. - */ - public void setEventTypes(List> eventTypes) { - Assert.notEmpty(eventTypes, "at least one event type is required"); - this.eventTypes = eventTypes; - } - - public void onApplicationEvent(ApplicationEvent event) { - if (CollectionUtils.isEmpty(this.eventTypes)) { - this.sendMessage(event); - return; - } - for (Class eventType : this.eventTypes) { - if (eventType.isAssignableFrom(event.getClass())) { - this.sendMessage(event); - return; - } - } - } - - private boolean sendMessage(ApplicationEvent event) { - return this.channelTemplate.send( - new GenericMessage(event), this.channel); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTarget.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTarget.java deleted file mode 100644 index 4a8778e490..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventTarget.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageMapper; -import org.springframework.integration.message.MessageTarget; - -/** - * A message target for publishing {@link MessagingEvent MessagingEvents}. The - * {@link MessagingEvent} is a subclass of Spring's {@link ApplicationEvent} - * used by this adapter to wrap any {@link Message} sent to this target. - * - * @author Mark Fisher - */ -public class ApplicationEventTarget implements MessageTarget, ApplicationEventPublisherAware { - - private final MessageMapper> mapper = new MessagingEventMapper(); - - private ApplicationEventPublisher applicationEventPublisher; - - - public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { - this.applicationEventPublisher = applicationEventPublisher; - } - - public boolean send(Message message) { - this.applicationEventPublisher.publishEvent(this.mapper.mapMessage((Message) message)); - return true; - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java deleted file mode 100644 index 6b07cc68e9..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import org.springframework.context.ApplicationEvent; -import org.springframework.integration.message.Message; - -/** - * A subclass of {@link ApplicationEvent} that wraps a {@link Message}. - * - * @author Mark Fisher - */ -public class MessagingEvent extends ApplicationEvent { - - public MessagingEvent(Message message) { - super(message); - } - - public Message getMessage() { - return (Message) this.getSource(); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java deleted file mode 100644 index 47424ca665..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/MessagingEventMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageCreator; -import org.springframework.integration.message.MessageMapper; - -/** - * Maps between {@link Message Messages} and {@link MessagingEvent MessagingEvents}. - * - * @author Mark Fisher - */ -public class MessagingEventMapper implements MessageCreator, T>, MessageMapper> { - - public Message createMessage(MessagingEvent event) { - return event.getMessage(); - } - - public MessagingEvent mapMessage(Message message) { - return new MessagingEvent(message); - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceTests.java deleted file mode 100644 index 00a9a22735..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventSourceTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.event.ContextClosedEvent; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.event.ContextStartedEvent; -import org.springframework.context.event.ContextStoppedEvent; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.channel.PollableChannel; -import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.message.Message; - -/** - * @author Mark Fisher - */ -public class ApplicationEventSourceTests { - - @Test - public void testAnyApplicationEventSentByDefault() { - QueueChannel channel = new QueueChannel(); - ApplicationEventSource adapter = new ApplicationEventSource(channel); - Message message1 = channel.receive(0); - assertNull(message1); - adapter.onApplicationEvent(new TestApplicationEvent1()); - adapter.onApplicationEvent(new TestApplicationEvent2()); - Message message2 = channel.receive(20); - assertNotNull(message2); - assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource()); - Message message3 = channel.receive(20); - assertNotNull(message3); - assertEquals("event2", ((ApplicationEvent) message3.getPayload()).getSource()); - } - - @Test - public void testOnlyConfiguredEventTypesAreSent() { - QueueChannel channel = new QueueChannel(); - ApplicationEventSource adapter = new ApplicationEventSource(channel); - List> eventTypes = new ArrayList>(); - eventTypes.add(TestApplicationEvent1.class); - adapter.setEventTypes(eventTypes); - Message message1 = channel.receive(0); - assertNull(message1); - adapter.onApplicationEvent(new TestApplicationEvent1()); - adapter.onApplicationEvent(new TestApplicationEvent2()); - Message message2 = channel.receive(20); - assertNotNull(message2); - assertEquals("event1", ((ApplicationEvent) message2.getPayload()).getSource()); - Message message3 = channel.receive(0); - assertNull(message3); - } - - @Test - public void testApplicationContextEvents() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationEventSourceTests.xml", this.getClass()); - PollableChannel channel = (PollableChannel) context.getBean("channel"); - Message refreshedEventMessage = channel.receive(0); - assertNotNull(refreshedEventMessage); - assertEquals(ContextRefreshedEvent.class, refreshedEventMessage.getPayload().getClass()); - context.start(); - Message startedEventMessage = channel.receive(0); - assertNotNull(startedEventMessage); - assertEquals(ContextStartedEvent.class, startedEventMessage.getPayload().getClass()); - context.stop(); - Message stoppedEventMessage = channel.receive(0); - assertNotNull(stoppedEventMessage); - assertEquals(ContextStoppedEvent.class, stoppedEventMessage.getPayload().getClass()); - context.close(); - Message closedEventMessage = channel.receive(0); - assertNotNull(closedEventMessage); - assertEquals(ContextClosedEvent.class, closedEventMessage.getPayload().getClass()); - } - - - private static class TestApplicationEvent1 extends ApplicationEvent { - - public TestApplicationEvent1() { - super("event1"); - } - } - - - private static class TestApplicationEvent2 extends ApplicationEvent { - - public TestApplicationEvent2() { - super("event2"); - } - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetTests.java deleted file mode 100644 index 7a42ca138e..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/ApplicationEventTargetTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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.springframework.integration.adapter.event; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.StringMessage; - -/** - * @author Mark Fisher - */ -public class ApplicationEventTargetTests { - - @Test - @SuppressWarnings("unchecked") - public void testSendingEvent() throws InterruptedException { - TestApplicationEventPublisher publisher = new TestApplicationEventPublisher(); - ApplicationEventTarget adapter = new ApplicationEventTarget(); - adapter.setApplicationEventPublisher(publisher); - assertNull(publisher.getLastEvent()); - Message message = new StringMessage("testing"); - adapter.send(message); - ApplicationEvent event = publisher.getLastEvent(); - assertEquals(MessagingEvent.class, event.getClass()); - assertEquals(message, ((MessagingEvent) event).getMessage()); - } - - - private static class TestApplicationEventPublisher implements ApplicationEventPublisher { - - private volatile ApplicationEvent lastEvent; - - public ApplicationEvent getLastEvent() { - return this.lastEvent; - } - - public void publishEvent(ApplicationEvent event) { - this.lastEvent = event; - } - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceTests.xml deleted file mode 100644 index 85fd0da692..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/event/applicationEventSourceTests.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - -