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

com.gw.common.utils.GwServerResource Maven / Gradle / Ivy

The newest version!
package com.gw.common.utils;

import java.util.List;

import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.gw.common.utils.GwServerWrapper.IGWSessionStatus;

@Configuration
@Component
public class GwServerResource {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Value("${serverKey}")
	public String serverKey;
	@Autowired
	public GwServerWrapper gwServerWrapper;

	public GwServerWrapper getGwServerWrapper() {
		return gwServerWrapper;
	}

	public void addGWSessionStatus(IGWSessionStatus gwSessionStatus) {
		gwServerWrapper.addGWSessionStatus(gwSessionStatus);
	}

	public void publishMessage(String topic, String data) {
	 
		if (gwServerWrapper != null) {
			List lt = gwServerWrapper.publishMessage(topic, data);
			String printMsg = data;
			if (data.length() >= 50000) {
				printMsg = data.substring(0, 50000) + "... too long";
			}
			logger.info("publish ->: {},{},{}", lt,topic, printMsg);
		}
		 
	}

	@Bean(initMethod = "start")
	public void start() throws Exception {

		if (gwServerWrapper != null) {
			gwServerWrapper.start();
		}
	}

	@PreDestroy
	public void stop() throws Exception {
		if (gwServerWrapper != null) {
			gwServerWrapper.dispose();
			gwServerWrapper = null;
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy