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

com.codingapi.tx.springcloud.service.impl.ModelNameServiceImpl Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package com.codingapi.tx.springcloud.service.impl;

import com.lorne.core.framework.utils.encode.MD5Util;
import com.codingapi.tx.listener.service.ModelNameService;
import com.codingapi.tx.springcloud.listener.ServerListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by lorne on 2017/7/12.
 */
@Service
@Configuration
public class ModelNameServiceImpl implements ModelNameService {

    @Value("${spring.application.name}")
    private String modelName;

    @Autowired
    private ServerListener serverListener;


    private String host = null;

    @Override
    public String getModelName() {
        return modelName;
    }

    private String getIp(){
        if (host == null) {
            try {
                host = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }
        return host;
    }

    @Override
    public String getUniqueKey() {
        String address = getIp()+serverListener.getPort();
        return  MD5Util.md5(address.getBytes());
    }


    @Override
    public String getIpAddress() {
        String address = getIp() + ":" + serverListener.getPort();
        return address;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy