INT-1257, INT-1263 Refactoring Message History (work in progress): removed MessageHistory and MessageHistoryEvent, moved MessageHistoryWriter and NamedComponent to the 'context' package.

This commit is contained in:
Mark Fisher
2010-08-25 14:20:30 +00:00
parent d98ff8eaa1
commit 220538ec08
14 changed files with 14 additions and 253 deletions

View File

@@ -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;

View File

@@ -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;
/**

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.history;
package org.springframework.integration.context;
/**
* @author Mark Fisher

View File

@@ -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<MessageHistoryEvent>, Serializable {
private final Queue<MessageHistoryEvent> events = new ConcurrentLinkedQueue<MessageHistoryEvent>();
/**
* 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<MessageHistoryEvent> 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<MessageHistoryEvent>(events).toString();
}
}

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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">
<bean class="org.springframework.integration.history.MessageHistoryWriter"/>
<bean class="org.springframework.integration.history.MessageHistoryWriter"/>
<bean class="org.springframework.integration.context.MessageHistoryWriter"/>
<bean class="org.springframework.integration.context.MessageHistoryWriter"/>
</beans>

View File

@@ -30,5 +30,5 @@
<int:channel id="endOfThePipeChannel"/>
<bean class="org.springframework.integration.history.MessageHistoryWriter"/>
<bean class="org.springframework.integration.context.MessageHistoryWriter"/>
</beans>

View File

@@ -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;

View File

@@ -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;
/**