Skip to content

Commit

Permalink
INT-3372 Add NamedComponent to Remaining MsgSrcs
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell authored and Artem Bilan committed Apr 16, 2014
1 parent c4a7d22 commit 17c6f8a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.expression.Expression;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.integration.util.AbstractExpressionEvaluator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
Expand All @@ -33,16 +35,28 @@
* @author Oleg Zhurakousky
* @since 2.0
*/
public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluator implements MessageSource<T> {
public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluator implements MessageSource<T>,
NamedComponent, BeanNameAware {

private volatile Map<String, Expression> headerExpressions = Collections.emptyMap();

private volatile String beanName;

public void setHeaderExpressions(Map<String, Expression> headerExpressions) {
this.headerExpressions = (headerExpressions != null)
? headerExpressions : Collections.<String, Expression>emptyMap();
}

@Override
public void setBeanName(String name) {
this.beanName = name;
}

@Override
public String getComponentName() {
return this.beanName;
}

@Override
@SuppressWarnings("unchecked")
public final Message<T> receive() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -21,6 +21,7 @@

/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
public class ExpressionEvaluatingMessageSource<T> extends AbstractMessageSource<T> {
Expand All @@ -36,6 +37,12 @@ public ExpressionEvaluatingMessageSource(Expression expression, Class<T> expecte
this.expectedType = expectedType;
}

@Override
public String getComponentType() {
return "inbound-channel-adapter";
}

@Override
public T doReceive() {
return this.evaluateExpression(this.expression, this.expectedType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -19,16 +19,17 @@
import java.lang.reflect.Method;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;

/**
* A {@link MessageSource} implementation that invokes a no-argument method so
* that its return value may be sent to a channel.
*
*
* @author Mark Fisher
* @author Gary Russell
*/
public class MethodInvokingMessageSource extends AbstractMessageSource<Object> implements InitializingBean {

Expand Down Expand Up @@ -58,6 +59,12 @@ public void setMethodName(String methodName) {
this.methodName = methodName;
}

@Override
public String getComponentType() {
return "inbound-channel-adapter";
}

@Override
public void afterPropertiesSet() {
synchronized (this.initializationMonitor) {
if (this.initialized) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -25,19 +25,20 @@
import org.springframework.context.MessageSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.integration.util.CollectionFilter;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

/**
* Implementation of {@link MessageSource} based on {@link ResourcePatternResolver} which will
* Implementation of {@link MessageSource} based on {@link ResourcePatternResolver} which will
* attempt to resolve {@link Resource}s based on the pattern specified.
*
*
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gary Russell
* @since 2.1
*/
public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resource[]> implements ApplicationContextAware, InitializingBean {
Expand Down Expand Up @@ -65,10 +66,18 @@ public void setFilter(CollectionFilter<Resource> filter) {
this.filter = filter;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

@Override
public String getComponentType() {
return "resource-inbound-channel-adapter";
}


@Override
public void afterPropertiesSet() {
if (this.patternResolver == null) {
if (this.applicationContext instanceof ResourcePatternResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void setAttributeName(String attributeName) {
this.attributeName = attributeName;
}

@Override
public String getComponentType() {
return "jmx:attribute-polling-channel-adapter";
}

/**
* Retrieves the JMX attribute value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* A {@link MessageSource} implementation that retrieves a snapshot of a filtered subset of the MBean tree.
*
* @author Stuart Williams
* @author Gary Russell
* @since 3.0
*
*/
Expand All @@ -54,6 +55,11 @@ public MBeanTreePollingMessageSource(MBeanObjectConverter converter) {
this.converter = converter;
}

@Override
public String getComponentType() {
return "jmx:tree-polling-channel-adapter";
}

/**
* Provides the mapped tree object
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -25,9 +25,11 @@

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.DefaultMessageBuilderFactory;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
Expand All @@ -44,7 +46,7 @@
* @author Oleg Zhurakousky
*/
public class MailReceivingMessageSource implements MessageSource<javax.mail.Message>,
BeanFactoryAware {
BeanFactoryAware, BeanNameAware, NamedComponent {

private final Log logger = LogFactory.getLog(this.getClass());

Expand All @@ -56,6 +58,8 @@ public class MailReceivingMessageSource implements MessageSource<javax.mail.Mess

private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();

private volatile String beanName;


public MailReceivingMessageSource(MailReceiver mailReceiver) {
Assert.notNull(mailReceiver, "mailReceiver must not be null");
Expand All @@ -76,6 +80,21 @@ protected MessageBuilderFactory getMessageBuilderFactory() {
return messageBuilderFactory;
}

@Override
public String getComponentName() {
return this.beanName;
}

@Override
public String getComponentType() {
return "mail:inbound-channel-adapter";
}

@Override
public void setBeanName(String name) {
this.beanName = name;
}

@Override
public Message<javax.mail.Message> receive() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 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.
Expand All @@ -24,6 +24,7 @@
* {@linkplain #scriptMessageProcessor} for polling endpoints.
*
* @author Artem Bilan
* @author Gary Russell
* @since 3.0
*/
class ScriptExecutingMessageSource extends AbstractMessageSource<Object> {
Expand All @@ -34,6 +35,11 @@ public ScriptExecutingMessageSource(AbstractScriptExecutingMessageProcessor<?> s
this.scriptMessageProcessor = scriptMessageProcessor;
}

@Override
public String getComponentType() {
return "inbound-channel-adapter";
}

@Override
protected Object doReceive() {
return scriptMessageProcessor.processMessage(null);
Expand Down

0 comments on commit 17c6f8a

Please sign in to comment.