helloclusterimpl.java
来自「weblogic应用全实例」· Java 代码 · 共 66 行
JAVA
66 行
//声明这个类定义在包examples.cluster.rmi中
package examples.cluster.rmi;
//声明引入的其它类
import weblogic.rmi.*;
import javax.naming.*;
import weblogic.jndi.*;
import weblogic.management.Admin;
import weblogic.common.*;
import java.util.Hashtable;
/**
* 这个类实现接口HelloCluster.
*
*/
public class HelloClusterImpl implements HelloCluster{
public static final String BINDNAME = "HelloCluster";
/**
* 返回一个字符串
*
* @返回 String message
* @异常 weblogic.rmi.RemoteException
*/
public String sayHello() throws RemoteException {
String temp = "Hello World from : " + getLocation();
System.out.println(temp);
return temp;
}
//获取服务器名
private String getLocation(){
String toReturn = null;
try{
toReturn = weblogic.management.Admin.getServerName();
}catch(Exception e){
System.out.println("HelloClusterImpl failed getLocation");
e.printStackTrace();
}
if(toReturn==null){
return "";
}else{
return toReturn;
}
}
/**
* main()方法
*/
public static void main(String args[]) {
try {
//上下文
Context context = new InitialContext();
//绑定
context.bind(BINDNAME,new HelloClusterImpl());
System.out.println("\n\n===========================HelloClusterImpl bound " +BINDNAME+
"===========================\n\n");
} catch(NamingException e) {
System.out.println("Could not bind service to '"+BINDNAME+"'");
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?