Weblogic获取端口IP
Weblogic获取端口IP
获取端口IP只为了判断哪个节点
调用
private WebMBeanServer server=new WebMBeanServer();
synlog.info("人员大对象清分开始-SaUUserSynJob,{}-{}",server.getIpAddr(),server.getPort());
效果
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.InitialContext;
public class WebMBeanServer {
private static Integer port=null;
private static String ipAddr=null;
private static String domainName=null;
public Integer getPort(){
if(port==null){
init();
}
return port;
}
public String getIpAddr(){
if(ipAddr==null){
init();
}
return ipAddr;
}
public String getDomainName(){
if(domainName==null){
init();
}
return domainName;
}
private void init(){
try {
InitialContext ctx = new InitialContext();
MBeanServer tMBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
ObjectName tObjectName = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
ObjectName serverrt = (ObjectName) tMBeanServer.getAttribute(tObjectName, "ServerRuntime");
String portt = String.valueOf(tMBeanServer.getAttribute(serverrt, "ListenPort"));
port=Integer.valueOf(portt);
String listenAddr=(String)tMBeanServer.getAttribute(serverrt,"ListenAddress");
ipAddr=listenAddr.split("/")[1];
domainName=listenAddr.split("/")[0];
}catch(Exception e){
if(port==null){
port=0;
}
if(ipAddr==null){
ipAddr="0.0.0.0";
}
if(domainName==null){
domainName="picc";
}
}
}
}