All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lmax.disruptor.biz.context.DisruptorApplicationContext Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018 (https://github.com/hiwepy).
 *
 * 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 com.lmax.disruptor.biz.context;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.biz.context.event.DisruptorEventPublisher;
import com.lmax.disruptor.biz.event.DisruptorBindEvent;
import com.lmax.disruptor.biz.event.DisruptorEvent;
import com.lmax.disruptor.biz.event.translator.DisruptorEventTranslator;
import com.lmax.disruptor.dsl.Disruptor;

public class DisruptorApplicationContext implements ApplicationContextAware, DisruptorEventPublisher, InitializingBean {

	protected ApplicationContext applicationContext;
	
	protected Disruptor disruptor = null;
	
	protected EventTranslatorOneArg eventTranslator = null;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		
		if(eventTranslator == null){
			eventTranslator = new DisruptorEventTranslator();
		}
		
	}
	
	@Override
	public void publishEvent(DisruptorEvent event) {
		
		if(event instanceof DisruptorBindEvent){
			DisruptorBindEvent bindEvent = (DisruptorBindEvent)event;
			disruptor.publishEvent(eventTranslator, bindEvent.getBind());
		} else {
			disruptor.publishEvent(eventTranslator, null);
		}
		//disruptor.getRingBuffer().tryPublishEvent(eventTranslator);
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public Disruptor getDisruptor() {
		return disruptor;
	}

	public void setDisruptor(Disruptor disruptor) {
		this.disruptor = disruptor;
	}

	public EventTranslatorOneArg getEventTranslator() {
		return eventTranslator;
	}

	public void setEventTranslator(EventTranslatorOneArg eventTranslator) {
		this.eventTranslator = eventTranslator;
	}
	
}
	





© 2015 - 2024 Weber Informatics LLC | Privacy Policy