From 220538ec087d04e2c83505a06b6a0041a428d9c1 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 25 Aug 2010 14:20:30 +0000 Subject: [PATCH] INT-1257, INT-1263 Refactoring Message History (work in progress): removed MessageHistory and MessageHistoryEvent, moved MessageHistoryWriter and NamedComponent to the 'context' package. --- .../config/ConsumerEndpointFactoryBean.java | 2 +- .../MessageHistoryWritingMessageHandler.java | 4 +- .../config/xml/MessageHistoryParser.java | 2 +- .../context/IntegrationObjectSupport.java | 2 - .../MessageHistoryWriter.java | 2 +- .../{history => context}/NamedComponent.java | 2 +- .../integration/history/MessageHistory.java | 78 ------------------ .../history/MessageHistoryEvent.java | 80 ------------------ .../MessageHistoryIntegrationTests.java | 1 + .../history/MessageHistoryTests.java | 81 ------------------- .../messageHistoryWithHistoryWriter-fail.xml | 5 +- .../messageHistoryWithHistoryWriter.xml | 2 +- .../integration/test/util/TestUtils.java | 2 +- .../jms/config/JmsMessageHistoryTests.java | 4 +- 14 files changed, 14 insertions(+), 253 deletions(-) rename spring-integration-core/src/main/java/org/springframework/integration/{history => context}/MessageHistoryWriter.java (98%) rename spring-integration-core/src/main/java/org/springframework/integration/{history => context}/NamedComponent.java (93%) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryEvent.java delete mode 100644 spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryTests.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java index c28df962cd..e4ef7010ec 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ConsumerEndpointFactoryBean.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.SmartLifecycle; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationObjectSupport; +import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.PollableChannel; @@ -36,7 +37,6 @@ import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.endpoint.PollingConsumer; -import org.springframework.integration.history.MessageHistoryWriter; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryWritingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryWritingMessageHandler.java index e99d1807ef..47f045a7be 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryWritingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/MessageHistoryWritingMessageHandler.java @@ -18,9 +18,9 @@ package org.springframework.integration.config; import org.springframework.core.Ordered; import org.springframework.integration.Message; +import org.springframework.integration.context.MessageHistoryWriter; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageHandler; -import org.springframework.integration.history.MessageHistoryWriter; -import org.springframework.integration.history.NamedComponent; import org.springframework.util.Assert; /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java index 36832fce79..ae1f796c88 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java @@ -31,7 +31,7 @@ public class MessageHistoryParser extends AbstractSimpleBeanDefinitionParser { @Override protected String getBeanClassName(Element element) { - return "org.springframework.integration.history.MessageHistoryWriter"; + return "org.springframework.integration.context.MessageHistoryWriter"; } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index 5ecc926dfe..124ed1314b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -30,8 +30,6 @@ import org.springframework.core.convert.ConversionService; import org.springframework.integration.Message; import org.springframework.integration.context.metadata.MetadataPersister; import org.springframework.integration.context.metadata.PropertiesBasedMetadataPersister; -import org.springframework.integration.history.MessageHistoryWriter; -import org.springframework.integration.history.NamedComponent; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java b/spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java similarity index 98% rename from spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java rename to spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java index 8cdb58ce0c..a6b0d51719 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryWriter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/MessageHistoryWriter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.history; +package org.springframework.integration.context; import java.util.ArrayList; import java.util.List; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/NamedComponent.java b/spring-integration-core/src/main/java/org/springframework/integration/context/NamedComponent.java similarity index 93% rename from spring-integration-core/src/main/java/org/springframework/integration/history/NamedComponent.java rename to spring-integration-core/src/main/java/org/springframework/integration/context/NamedComponent.java index 123a49b653..64116f7da7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/NamedComponent.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/NamedComponent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.history; +package org.springframework.integration.context; /** * @author Mark Fisher diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java deleted file mode 100644 index 4e6d24a21a..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2002-2010 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.history; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -import org.springframework.util.StringUtils; - -/** - * Threadsafe Iterable list of {@link MessageHistoryEvent} instances. - * - * @author Mark Fisher - * @author Oleg Zhurakousky - * @author Iwein Fuld - * @since 2.0 - */ -@SuppressWarnings("serial") -public class MessageHistory implements Iterable, Serializable { - - private final Queue events = new ConcurrentLinkedQueue(); - - /** - * Add a new event with the provided component metadata. - */ - public MessageHistoryEvent addEvent(NamedComponent component) { - String name = component.getComponentName(); - String type = component.getComponentType(); - if (name != null && !StringUtils.startsWithIgnoreCase(name, "org.springframework")) { - MessageHistoryEvent event = new MessageHistoryEvent(name, type); - this.events.add(event); - return event; - } - return null; - } - - /** - * Returns a weakly consistent iterator that will never throw - * ConcurrentModificationException as in {@link java.util.concurrent.ConcurrentLinkedQueue#iterator()}. - */ - public Iterator iterator() { - return this.events.iterator(); - } - - public boolean equals(Object other) { - return (other instanceof MessageHistory - && this.events.containsAll(((MessageHistory) other).events)) - && ((MessageHistory) other).events.containsAll(this.events); - } - - public int hashCode() { - return 17 * this.events.hashCode(); - } - - /** - * Returns a String representation of the history event list. - */ - public String toString() { - return new ArrayList(events).toString(); - } -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryEvent.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryEvent.java deleted file mode 100644 index d97debee5d..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryEvent.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2002-2010 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.history; - -import java.io.Serializable; - -/** - * Metadata about a historically relevant messaging event along - * with a timestamp that is generated when this event is created. - * - * @author Mark Fisher - * @author Oleg Zhurakousky - * @since 2.0 - */ -public class MessageHistoryEvent implements Serializable { - - private static final long serialVersionUID = 1623653800353662107L; - - private final String name; - - private final String type; - - private final long timestamp; - - - /** - * Create a MessageHistoryEvent with the metadata of the source component. - */ - public MessageHistoryEvent(String name, String type) { - this.name = name; - this.type = type; - this.timestamp = System.currentTimeMillis(); - } - - - public String getType() { - return this.type; - } - - public String getName() { - return this.name; - } - - /** - * Returns the timestamp generated when this event was created. - */ - public long getTimestamp() { - return this.timestamp; - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - if (this.type != null) { - sb.append(type); - } - if (this.name != null) { - if (this.type != null) { - sb.append('#'); - } - sb.append(name); - //sb.append("[" + timestamp + "]"); - } - return sb.toString(); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java index 4fe16a9165..ce011096cd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryIntegrationTests.java @@ -37,6 +37,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.ConsumerEndpointFactoryBean; +import org.springframework.integration.context.MessageHistoryWriter; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryTests.java b/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryTests.java deleted file mode 100644 index e99444e9d5..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/MessageHistoryTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2002-2010 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.history; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; - - -/** - * @author Oleg Zhurakousky - * @since 2.0 - */ -public class MessageHistoryTests { - - private long times = 1000; - - private ExecutorService executor = Executors.newCachedThreadPool(); - - @Test - public void testConcurrentModificationsOnObjectMethods() throws Exception{ - final MessageHistory history = new MessageHistory(); - final MessageHistory otherHistory = new MessageHistory(); - final NamedComponent component = new NamedComponent() { - public String getComponentType() { - return "testType"; - } - public String getComponentName() { - return "testName"; - } - }; - executor.execute(new Runnable() { - public void run() { - for (int i = 0; i < times; i++) { - history.addEvent(component); - otherHistory.addEvent(component); - } - } - }); - executor.execute(new Runnable() { - public void run() { - for (int i = 0; i < times; i++) { - history.toString(); - } - } - }); - executor.execute(new Runnable() { - public void run() { - for (int i = 0; i < times; i++) { - history.hashCode(); - } - } - }); - executor.execute(new Runnable() { - public void run() { - for (int i = 0; i < times; i++) { - history.equals(new Object()); - } - } - }); - executor.shutdown(); - executor.awaitTermination(3, TimeUnit.SECONDS); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml index 328ef9838a..dccb0e5e9b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter-fail.xml @@ -5,6 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"> - - + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml index f49525a1dc..e23557aa75 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml @@ -30,5 +30,5 @@ - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java b/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java index f7a548f305..d6ed8ac2cc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java @@ -38,11 +38,11 @@ import org.springframework.integration.MessageRejectedException; import org.springframework.integration.channel.MessagePublishingErrorHandler; import org.springframework.integration.context.BeanFactoryChannelResolver; import org.springframework.integration.context.IntegrationContextUtils; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.AbstractPollingEndpoint; -import org.springframework.integration.history.NamedComponent; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.support.PeriodicTrigger; import org.springframework.util.Assert; diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java index 040c65f08a..3ff080c3fe 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java @@ -35,13 +35,13 @@ import org.springframework.integration.Message; import org.springframework.integration.MessageHeaders; import org.springframework.integration.MessagingException; import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.context.MessageHistoryWriter; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.core.StringMessage; import org.springframework.integration.core.SubscribableChannel; -import org.springframework.integration.history.MessageHistoryWriter; -import org.springframework.integration.history.NamedComponent; import org.springframework.integration.jms.DefaultJmsHeaderMapper; /**