private void InitializeAdapter() { lock (_initializationMonitor) { if (_initialized) { return; } AssertUtils.ArgumentNotNull(_source, "source is required"); AssertUtils.ArgumentNotNull(_outputChannel, "outputChannel is required"); SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter(); spca.Source = _source; spca.OutputChannel = _outputChannel; if (_pollerMetadata == null) { _pollerMetadata = IntegrationContextUtils.GetDefaultPollerMetadata(_objectFactory); AssertUtils.ArgumentNotNull(_pollerMetadata, "No poller has been defined for channel-adapter '" + _objectName + "', and no default poller is available within the context."); } spca.Trigger = _pollerMetadata.Trigger; spca.MaxMessagesPerPoll = _pollerMetadata.MaxMessagesPerPoll; spca.TaskExecutor = _pollerMetadata.TaskExecutor; spca.TransactionManager = _pollerMetadata.TransactionManager; spca.TransactionDefinition = _pollerMetadata.TransactionDefinition; spca.AutoStartup = _autoStartup; spca.ObjectName = _objectName; spca.ObjectFactory = _objectFactory; //spca.setBeanClassLoader(this.beanClassLoader); spca.AfterPropertiesSet(); _adapter = spca; _initialized = true; } }
private void InitializeEndpoint() { lock (_initializationMonitor) { if (_initialized) { return; } AssertUtils.ArgumentHasText(_inputChannelName, "inputChannelName is required"); AssertUtils.IsTrue(_objectFactory.ContainsObject(_inputChannelName), "no such input channel '" + _inputChannelName + "' for endpoint '" + _objectName + "'"); IMessageChannel channel = (IMessageChannel)_objectFactory.GetObject(_inputChannelName, typeof(IMessageChannel)); if (channel is ISubscribableChannel) { if (_pollerMetadata != null) { throw new ArgumentException("A poller should not be specified for endpoint '" + _objectName + "', since '" + _inputChannelName + "' is a SubscribableChannel (not pollable)."); } _endpoint = new EventDrivenConsumer((ISubscribableChannel)channel, _handler); } else if (channel is IPollableChannel) { PollingConsumer pollingConsumer = new PollingConsumer((IPollableChannel)channel, _handler); if (_pollerMetadata == null) { _pollerMetadata = IntegrationContextUtils.GetDefaultPollerMetadata(_objectFactory); AssertUtils.ArgumentNotNull(_pollerMetadata, "No poller has been defined for endpoint '" + _objectName + "', and no default poller is available within the context."); } pollingConsumer.Trigger = _pollerMetadata.Trigger; pollingConsumer.MaxMessagesPerPoll = _pollerMetadata.MaxMessagesPerPoll; pollingConsumer.ReceiveTimeout = _pollerMetadata.ReceiveTimeout; pollingConsumer.TaskExecutor = _pollerMetadata.TaskExecutor; pollingConsumer.TransactionManager = _pollerMetadata.TransactionManager; pollingConsumer.TransactionDefinition = _pollerMetadata.TransactionDefinition; pollingConsumer.AdviceChain = _pollerMetadata.AdviceChain; _endpoint = pollingConsumer; } else { throw new ArgumentException("unsupported channel type: [" + channel.GetType() + "]"); } _endpoint.AutoStartup = _autoStartup; _endpoint.ObjectName = _objectName; _endpoint.ObjectFactory = _objectFactory; _endpoint.AfterPropertiesSet(); _initialized = true; } }
public void PollerWithAdviceChain() { IApplicationContext context = TestUtils.GetContext(@"Config\Xml\pollerWithAdviceChain.xml"); Object poller = context.GetObject("poller"); Assert.IsNotNull(poller); PollerMetadata metadata = (PollerMetadata)poller; Assert.IsNotNull(metadata.AdviceChain); Assert.That(metadata.AdviceChain.Count, Is.EqualTo(3)); Assert.That(metadata.AdviceChain[0], Is.EqualTo(context.GetObject("adviceBean1"))); Assert.That(metadata.AdviceChain[1].GetType(), Is.EqualTo(typeof(TestAdviceObject))); Assert.That(((TestAdviceObject)metadata.AdviceChain[1]).Id, Is.EqualTo(2)); Assert.That(metadata.AdviceChain[2], Is.EqualTo(context.GetObject("adviceBean3"))); }